def test_load_module(self): import sys anchor_dir = os.getcwd() loader = ModuleLoader(anchor_dir=anchor_dir) mod = loader.load_module(name='tests.test_tddtags') # Load this self.assertTrue(mod) self.assertTrue('test_tddtags' in mod.__file__)
def test_load_module_diff_anchor(self): import sys # --> setup the anchor to ./tests to pickup the module p.mod anchor_dir = os.getcwd() anchor_dir = os.path.join(anchor_dir, 'tests') loader = ModuleLoader(anchor_dir=anchor_dir) mod = loader.load_module(name='p.mod') self.assertTrue(mod)
def test_with_pyc(self): anchor_dir = os.getcwd() loader = ModuleLoader(anchor_dir=anchor_dir) mod = loader.load_module(name='tddtags.core') self.assertTrue(mod) self.assertTrue('.pyc' in mod.__file__) container = UTModuleContainer(module_path=mod.__file__) self.assertNotEqual(container.module_path, mod.__file__)
def test_update_verify_path(self): with mock.patch('tddtags.core.ModuleUpdater._update_step1', spec=True) as ModCon: # --> Prep updater = ModuleUpdater(ut_module=self.ut_module) updater._update_step1.side_effect = self.return_true loader = ModuleLoader(anchor_dir=self.anchor_dir) mod = loader.load_module(name=self.tmp_module_name) # --> Test reply = updater.update(loaded_module=mod) parm_info = [('loaded_module', 0), ('module_path', 1)] kwargs = self.get_patched_call_parms(parm_info, updater._update_step1, 0) self.assertTrue(self.tmp_file in kwargs['module_path']) self.assertEqual(kwargs['loaded_module'], mod)
def test_get_class_lists(self): updater = ModuleUpdater(ut_module=self.ut_module) loader = ModuleLoader(anchor_dir=self.anchor_dir) mod = loader.load_module(self.tmp_module_name) self.assertTrue(mod) # --> And test it first with no difference... existing_classes, new_classes = updater._get_class_lists(loaded_module=mod) self.assertFalse(new_classes) # --> Then with a new one self.ut_module.add_class(class_name='NewClassTests') existing_classes, new_classes = updater._get_class_lists(loaded_module=mod) self.assertTrue(new_classes)
def test_update_new_methods_none(self): with mock.patch('tddtags.core.ModuleUpdater._add_new_tests_to_class', spec=True) as ModUp: # --> Prep # (Same as test_update_new_methods, but no new test method added) container = None # We'll also verity that it correctly creates the container and returns it loader = ModuleLoader(anchor_dir=self.anchor_dir) mod = loader.load_module(self.tmp_module_name) updater = ModuleUpdater(ut_module=self.ut_module) existing_classes, new_names = updater._get_class_lists(loaded_module=mod) # --> The test container = updater._update_new_methods(container, self.tmp_file, existing_classes) self.assertFalse(container) self.assertEqual(updater._add_new_tests_to_class.call_count, 0)
def test_update_no_save(self): with mock.patch('tddtags.core.UTModuleContainer.save_module', spec=True) as ModCon: # --> Prep updater = ModuleUpdater(ut_module=self.ut_module) loader = ModuleLoader(anchor_dir=self.anchor_dir) mod = loader.load_module(name=self.tmp_module_name) tddtags.core.tddtags_config['save'] = False # --> Need something new to do (Remember, this just uses the ut_module setup in setUp()) ut_class = self.ut_module.class_list['ChildSampleTests'] ut_class.add_method('eat_peanuts') # --> Test reply = updater.update(loaded_module=mod) self.assertEqual(updater.container.save_module.call_count, 0)
def test_update_new_methods(self): with mock.patch('tddtags.core.ModuleUpdater._add_new_tests_to_class', spec=True) as ModUp: # --> Prep ut_class = self.ut_module.class_list['ChildSampleTests'] ut_class.add_method('eat_beans') container = None # We'll also verity that it correctly creates the container and returns it loader = ModuleLoader(anchor_dir=self.anchor_dir) mod = loader.load_module(self.tmp_module_name) updater = ModuleUpdater(ut_module=self.ut_module) existing_classes, new_names = updater._get_class_lists(loaded_module=mod) # --> The test container = updater._update_new_methods(container, self.tmp_file, existing_classes) self.assertTrue(container) self.assertIsInstance(container, UTModuleContainer) self.assertEqual(updater._add_new_tests_to_class.call_count, 1) parm_info = [('container', 0), ('class_name', 1), ('new_test_names', 2)] kwargs = self.get_patched_call_parms(parm_info, updater._add_new_tests_to_class, 0) self.assertEqual(kwargs['class_name'], 'ChildSampleTests') self.assertEqual(kwargs['new_test_names'], ['test_eat_beans'])
def test_load_module_name_unknown(self): import sys anchor_dir = os.getcwd() loader = ModuleLoader(anchor_dir=anchor_dir) mod = loader.load_module(name='tests.unknown') # Load this self.assertFalse(mod)