Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cimport for quicktions #5

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
479ad2d
Add pxd to allow cimport from other cython modules
nocarryr Apr 6, 2018
4ab0b49
Add test case for cimporting from another cython module
nocarryr Apr 6, 2018
2a10e91
Rename top-level src directory so it can be imported as a package
nocarryr Apr 6, 2018
0a6e8e2
Modify extension build methods to match layout
nocarryr Nov 12, 2018
cee0127
Merge branch 'master' into pxd-header
nocarryr Nov 12, 2018
b59f3ba
Merge branch 'master' into pxd-restructure
nocarryr Nov 12, 2018
278516c
Add language level directive to pxd and unittest cython module
nocarryr Nov 12, 2018
18f7389
Update paths in Makefile
nocarryr Nov 12, 2018
46daa88
Add language directive to pxd
nocarryr Nov 12, 2018
3be2c4e
Add module-level pxd
nocarryr Nov 12, 2018
13b03b5
Add language level to pyximport, handle extension teardown properly
nocarryr Nov 12, 2018
32fe9ea
Import docstrings from quicktions.pyx at package level
nocarryr Nov 12, 2018
53e1250
Handle py2 imports properly
nocarryr Nov 12, 2018
08ac125
Compatibility fix for py2.6
nocarryr Nov 12, 2018
f628e89
Merge branch 'master' into pxd-header
nocarryr Jan 22, 2019
6de8ea4
Use pre-built wheel to install and run tests against
nocarryr Jan 22, 2019
5cb185a
Move wrapper code and typedefs into pxd
nocarryr Jan 23, 2019
19ea21c
Merge branch 'pxd-header' into pxd-restructure
nocarryr Jan 24, 2019
b7d99f4
Move to src layout with subdirectory. Move test module to project root
nocarryr Jan 25, 2019
f8894e9
Remove unused imports and assertions
nocarryr Jan 25, 2019
fad41af
Correct paths for "make test"
nocarryr Jan 25, 2019
dde7654
Add comment explaining wheel installation step in travis config
nocarryr Jan 25, 2019
efcca15
Make __version__ and __all__ variables available at the package level
nocarryr Jan 25, 2019
0536e1e
Place Cython-related tests into separate module
nocarryr Feb 15, 2019
5a477cc
Use Cythonize module instead of pyximport to compile test modules
nocarryr Feb 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions test_fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,50 +797,11 @@ def test_pi_digits(self):
self.assertEqual(ff.numerator, qf.numerator)
self.assertEqual(ff.denominator, qf.denominator)

class CImportTest(unittest.TestCase):

def setUp(self):
self.build_test_module()

def tearDown(self):
self.remove_test_module()

def build_test_module(self):
self.module_code = '\n'.join([
'# cython: language_level=3str',
'from quicktions cimport Fraction',
'def get_fraction():',
' return Fraction(1, 2)',
])
self.base_path = os.path.abspath(os.path.dirname(__file__))
self.module_name = 'quicktions_importtest'
self.module_filename = os.path.join(self.base_path, '.'.join([self.module_name, 'pyx']))
with open(self.module_filename, 'w') as f:
f.write(self.module_code)

def remove_test_module(self):
for fn in os.listdir(self.base_path):
if not fn.startswith(self.module_name):
continue
os.remove(os.path.join(self.base_path, fn))

def test_cimport(self):
self.build_test_module()
import pyximport
self.py_importer, self.pyx_importer = pyximport.install(inplace=True, language_level=3)

from quicktions_importtest import get_fraction

self.assertEqual(get_fraction(), F(1,2))

pyximport.uninstall(self.py_importer, self.pyx_importer)


def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(GcdTest))
suite.addTest(unittest.makeSuite(FractionTest))
suite.addTest(unittest.makeSuite(CImportTest))
import doctest
suite.addTest(doctest.DocTestSuite('quicktions'))
return suite
Expand Down
60 changes: 60 additions & 0 deletions test_quicktions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import unittest

import quicktions
F = quicktions.Fraction
gcd = quicktions._gcd

class CImportTest(unittest.TestCase):

def setUp(self):
self.build_test_module()

def tearDown(self):
self.remove_test_module()

def build_test_module(self):
self.module_code = '\n'.join([
'# cython: language_level=3str',
'from quicktions cimport Fraction',
'def get_fraction():',
' return Fraction(1, 2)',
])
self.base_path = os.path.abspath(os.path.dirname(__file__))
self.module_name = 'quicktions_importtest'
self.module_filename = os.path.join(self.base_path, '.'.join([self.module_name, 'pyx']))
with open(self.module_filename, 'w') as f:
f.write(self.module_code)

def remove_test_module(self):
for fn in os.listdir(self.base_path):
if not fn.startswith(self.module_name):
continue
os.remove(os.path.join(self.base_path, fn))

def test_cimport(self):
self.build_test_module()
import pyximport
self.py_importer, self.pyx_importer = pyximport.install(inplace=True, language_level=3)

from quicktions_importtest import get_fraction

self.assertEqual(get_fraction(), F(1,2))

pyximport.uninstall(self.py_importer, self.pyx_importer)



def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(CImportTest))
return suite

def main():
suite = test_main()
runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
result = runner.run(suite)
sys.exit(not result.wasSuccessful())

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ platform =
linux: linux
darwin: darwin
passenv = *
commands = coverage run --parallel-mode -m pytest test_fractions.py --capture=no --strict {posargs}
commands = coverage run --parallel-mode -m pytest --capture=no --strict {posargs}
coverage combine
coverage report -m --include=test_fractions.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should include the new test file.

{windows,linux}: codecov