From 355110e70303e8a55bebbfac593cd6306a3ebd46 Mon Sep 17 00:00:00 2001 From: prculley Date: Tue, 9 May 2017 12:04:11 -0500 Subject: [PATCH] Fix imports_test nosetest description and running 2x under unittest --- gramps/plugins/test/imports_test.py | 34 ++++++++++------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/gramps/plugins/test/imports_test.py b/gramps/plugins/test/imports_test.py index 8b468d8d2..3014ac17f 100644 --- a/gramps/plugins/test/imports_test.py +++ b/gramps/plugins/test/imports_test.py @@ -61,7 +61,7 @@ def mock_localtime(*args): """ 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 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] # 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. if _tstfile: # single file mode (fname, ext) = os.path.splitext(os.path.basename(_tstfile)) test_func = make_tst_function(_tstfile, fname) - clname = 'Import_{0}'.format(_tstfile) - globals()[clname] = type(clname, - (CompleteCheck,), - {"testit": test_func}) + tname = "test_" + _tstfile.replace("-", "_").replace(".", "_") + test_func.__name__ = tname + test_func.__doc__ = tname + setattr(TestImports, tname, test_func) else: - _tstfiles = [] for _tstfile in os.listdir(TEST_DIR): (fname, ext) = os.path.splitext(os.path.basename(_tstfile)) if _tstfile != "SAMPLE.DEF" and (ext in (".gramps", ".difs", ".bak") \ or not fname.startswith("imp_")): continue test_func = make_tst_function(_tstfile, fname) - clname = 'Import_{0}'.format(_tstfile) - globals()[clname] = type(clname, - (CompleteCheck,), - {"testit": test_func}) - _tstfiles.append(clname) - - 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 + tname = "test_" + _tstfile.replace("-", "_").replace(".", "_") + test_func.__name__ = tname + test_func.__doc__ = tname + setattr(TestImports, tname, test_func) + test_func = None # keep nosetest from finding last one again if __name__ == "__main__": unittest.main()