Add "test" target for setup.py. Run tests with `python3 setup.py test`.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/cd9eec3c Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/cd9eec3c Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/cd9eec3c Branch: refs/heads/master Commit: cd9eec3c29c15c93532547fe92ffe1f48b1864fc Parents: 4ff8756 Author: Marvin Humphrey <[email protected]> Authored: Tue Dec 16 16:37:54 2014 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Wed Jan 6 18:32:52 2016 -0800 ---------------------------------------------------------------------- compiler/python/setup.py | 30 ++++++++++++++++++++++++++++++ compiler/python/test/test_cfc.py | 12 ++++++++++++ 2 files changed, 42 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd9eec3c/compiler/python/setup.py ---------------------------------------------------------------------- diff --git a/compiler/python/setup.py b/compiler/python/setup.py index 072c337..ccfba55 100644 --- a/compiler/python/setup.py +++ b/compiler/python/setup.py @@ -26,6 +26,8 @@ import re import shutil import subprocess import sysconfig +import sys +import unittest # Get a compiler object and and strings representing the compiler type and # CFLAGS. @@ -132,6 +134,33 @@ class my_build(_build): self.run_command('libcfc') _build.run(self) +class test(_Command): + description = "Run unit tests." + user_options = [] + def initialize_options(self): + pass + def finalize_options(self): + pass + def ext_build_dir(self): + """Returns the build directory for compiled extensions""" + pattern = "lib.{platform}-{version[0]}.{version[1]}" + dirname = pattern.format(platform=sysconfig.get_platform(), + version=sys.version_info) + return os.path.join('build', dirname) + + def run(self): + self.run_command('build') + orig_sys_path = sys.path[:] + sys.path.append(self.ext_build_dir()) + + loader = unittest.TestLoader() + tests = loader.discover("test") + test_runner = unittest.runner.TextTestRunner() + test_runner.run(tests) + + # restore sys.path + sys.path = orig_sys_path + cfc_extension = Extension('clownfish._cfc', define_macros = [('CFCPYTHON', None)], include_dirs = [ @@ -155,6 +184,7 @@ setup(name = 'clownfish-cfc', 'clean': my_clean, 'charmony': charmony, 'libcfc': libcfc, + 'test': test, }, ext_modules = [cfc_extension]) http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd9eec3c/compiler/python/test/test_cfc.py ---------------------------------------------------------------------- diff --git a/compiler/python/test/test_cfc.py b/compiler/python/test/test_cfc.py new file mode 100644 index 0000000..c4091d8 --- /dev/null +++ b/compiler/python/test/test_cfc.py @@ -0,0 +1,12 @@ +import unittest +import clownfish.cfc + +class MyTest(unittest.TestCase): + + def testTrue(self): + self.assertTrue(True, "True should be true") + + +if __name__ == '__main__': + unittest.main() +
