def test_module_equality(self): modules = list(collect_module_code( join(FILES_DIR, 'python'), [FILES_DIR])) self.assertEqual(2, len(modules)) module1 = modules[0] module2 = modules[1] self.assert_(module1 is not module2) self.assert_(not module1 == module2) self.assert_(module1 is module1) self.assert_(module1 == module1) modules2 = list(collect_module_code( join(FILES_DIR, 'python'), [FILES_DIR])) self.assert_(module1 is not modules2[0]) self.assert_(module1 == modules2[0]) # hash self.assertEqual(hash(module1), hash(module1)) self.assertEqual(hash(module1), hash(modules2[0])) self.assertEqual(hash(module2), hash(modules2[1]))
def gather_tests(): """Returns unittest.TestSuite instance""" tests = unittest.TestSuite() # unittest for dirpath, dirnames, filenames in os.walk(dirname(__file__)): if 'files' in dirnames: dirnames.remove('files') for name in filenames: if not (name.startswith("test_") and name.endswith(".py")): continue filepath = join(dirpath, name) modulename = resolve_modulename(filepath) module = import_module(modulename) suite = unittest.defaultTestLoader.loadTestsFromModule(module) tests.addTest(suite) # doctest modipyd_dir = join(dirname(__file__), '..', 'modipyd') for modcode in collect_module_code(modipyd_dir): module = import_module(modcode.name) try: suite = doctest.DocTestSuite(module) except ValueError: pass else: tests.addTest(suite) return tests
def test_collect_module_code(self): modules = list(collect_module_code( join(FILES_DIR, 'python'), [FILES_DIR])) self.assertNotNone(modules) self.assertEqual(2, len(modules)) names = [m.name for m in modules] self.assert_('python.a' in names) self.assert_('python' in names)
def setUp(self): codes = list(collect_module_code( join(FILES_DIR, 'package_dependency'), [FILES_DIR])) self.descriptors = build_module_descriptors(codes) self.assertEqual(3, len(self.descriptors)) init = self.descriptors['package_dependency'] a = self.descriptors['package_dependency.a'] b = self.descriptors['package_dependency.b'] self.assertNotNone(init) self.assertNotNone(a) self.assertNotNone(b) self.assertEqual('package_dependency', init.name) self.assertEqual('package_dependency.a', a.name) self.assertEqual('package_dependency.b', b.name)
def test_import_alias(self): path = join(FILES_DIR, 'import_alias') codes = list(collect_module_code(path, path)) descriptors = build_module_descriptors(codes) foo = descriptors['foo'] bar = descriptors['bar'] # import foo module syspath = sys.path[:] try: sys.path.insert(0, path) import foo as f self.assert_( has_subclass(bar, f.Foo), "The module 'bar' should contain a subclass of 'foo.Foo'") finally: sys.path = syspath
def import_modules(self, path): sys.path.insert(0, path) codes = list(collect_module_code(path, path)) self.descriptors.update(build_module_descriptors(codes))
def setUp(self): codes = list(collect_module_code( join(FILES_DIR, 'cycles'), [FILES_DIR])) self.descriptors = build_module_descriptors(codes)
def setUp(self): d = join(FILES_DIR, 'imports') codes = list(collect_module_code(d, [d])) self.descriptors = build_module_descriptors(codes) self.assertEqual(8, len(self.descriptors))