Fix imports_test nosetest description and running 2x under unittest

This commit is contained in:
prculley 2017-05-09 12:04:11 -05:00 committed by Nick Hall
parent dd828cee5b
commit 355110e703

View File

@ -61,7 +61,7 @@ def mock_localtime(*args):
""" """
return strptime("25 Dec 1999", "%d %b %Y") return strptime("25 Dec 1999", "%d %b %Y")
class CompleteCheck(unittest.TestCase): class TestImports(unittest.TestCase):
"""The test class cases will be dynamically created at import time from """The test class cases will be dynamically created at import time from
files to be tested. The following defs are used by the test cases files to be tested. The following defs are used by the test cases
""" """
@ -278,39 +278,27 @@ if __name__ == "__main__":
del sys.argv[i] del sys.argv[i]
del sys.argv[i] del sys.argv[i]
# The following code dynamically creates the methods for each test file. # The following code dynamically creates the methods for each test file.
# The methods are inserted at load time into the 'CompleteCheck' class # The methods are inserted at load time into the 'TestImports' class
# via the modules' globals, taking advantage that they are a dict. # via the modules' globals, taking advantage that they are a dict.
if _tstfile: # single file mode if _tstfile: # single file mode
(fname, ext) = os.path.splitext(os.path.basename(_tstfile)) (fname, ext) = os.path.splitext(os.path.basename(_tstfile))
test_func = make_tst_function(_tstfile, fname) test_func = make_tst_function(_tstfile, fname)
clname = 'Import_{0}'.format(_tstfile) tname = "test_" + _tstfile.replace("-", "_").replace(".", "_")
globals()[clname] = type(clname, test_func.__name__ = tname
(CompleteCheck,), test_func.__doc__ = tname
{"testit": test_func}) setattr(TestImports, tname, test_func)
else: else:
_tstfiles = []
for _tstfile in os.listdir(TEST_DIR): for _tstfile in os.listdir(TEST_DIR):
(fname, ext) = os.path.splitext(os.path.basename(_tstfile)) (fname, ext) = os.path.splitext(os.path.basename(_tstfile))
if _tstfile != "SAMPLE.DEF" and (ext in (".gramps", ".difs", ".bak") \ if _tstfile != "SAMPLE.DEF" and (ext in (".gramps", ".difs", ".bak") \
or not fname.startswith("imp_")): or not fname.startswith("imp_")):
continue continue
test_func = make_tst_function(_tstfile, fname) test_func = make_tst_function(_tstfile, fname)
clname = 'Import_{0}'.format(_tstfile) tname = "test_" + _tstfile.replace("-", "_").replace(".", "_")
globals()[clname] = type(clname, test_func.__name__ = tname
(CompleteCheck,), test_func.__doc__ = tname
{"testit": test_func}) setattr(TestImports, tname, test_func)
_tstfiles.append(clname) test_func = None # keep nosetest from finding last one again
def test_import_classes():
"""
Dynamic Test-function lister for
nosetests. Creates an instance for each
import test, and yields the function to
test.
"""
for clname in _tstfiles:
instance = globals()[clname]()
yield instance.testit
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()