def _test_appending(self, modified_input, expected_output): project = ProjectInDirectory(self.tmpdir) module_path = putfile( project.path, "module.py", read_data("appending_test_cases_module_initial.py")) test_module_path = putfile( project.path, "test_module.py", read_data("appending_test_cases_output_initial.py")) # Analyze the project with an existing test module. inspect_project(project) # Filesystem stat has resolution of 1 second, and we don't want to # sleep in a test, so we just fake the original files creation time. project["module"].created = 0 project["test_module"].created = 0 # Modify the application module and analyze it again. putfile(project.path, "module.py", read_data(modified_input)) inspect_project(project) # Regenerate the tests. add_tests_to_project(project, [module_path], 'unittest') project.save() assert_length(project.get_modules(), 2) result = read_file_contents(test_module_path) expected_result = read_data(expected_output) assert_equal_strings(expected_result, result)
def _test_appending(self, modified_input, expected_output): project = ProjectInDirectory(self.tmpdir) module_path = putfile(project.path, "module.py", read_data("appending_test_cases_module_initial.py")) test_module_path = putfile(project.path, "test_module.py", read_data("appending_test_cases_output_initial.py")) # Analyze the project with an existing test module. inspect_project(project) # Filesystem stat has resolution of 1 second, and we don't want to # sleep in a test, so we just fake the original files creation time. project["module"].created = 0 project["test_module"].created = 0 # Modify the application module and analyze it again. putfile(project.path, "module.py", read_data(modified_input)) inspect_project(project) # Regenerate the tests. add_tests_to_project(project, [module_path], 'unittest') project.save() assert_length(project.get_modules(), 2) result = read_file_contents(test_module_path) expected_result = read_data(expected_output) assert_equal_strings(expected_result, result)
def test_removes_definitions_of_modules_that_dont_exist_anymore(self): project = ProjectInDirectory(self.tmpdir).with_modules(["module.py", "other_module.py", "test_module.py"]) test_class = create(TestClass, associated_modules=[project["module"]]) add_test_case(project["test_module.py"], test_class) project.save() os.remove(os.path.join(project.path, "other_module.py")) remove_deleted_modules(project) assert_not_raises(ModuleNotFound, lambda: project["module"]) assert_raises(ModuleNotFound, lambda: project["other_module"]) assert_not_raises(ModuleNotFound, lambda: project["test_module"])
def test_removes_definitions_of_modules_that_dont_exist_anymore(self): project = ProjectInDirectory(self.tmpdir).with_modules( ["module.py", "other_module.py", "test_module.py"]) test_class = create(TestClass, associated_modules=[project["module"]]) add_test_case(project["test_module.py"], test_class) project.save() os.remove(os.path.join(project.path, "other_module.py")) remove_deleted_modules(project) assert_not_raises(ModuleNotFound, lambda: project["module"]) assert_raises(ModuleNotFound, lambda: project["other_module"]) assert_not_raises(ModuleNotFound, lambda: project["test_module"])
def test_can_be_saved_and_restored_from_file(self): project = ProjectInDirectory(self.tmpdir).with_modules(["good_module.py", "bad_module.py"]) project['good_module'].add_objects([Class("AClass", [Method("amethod")]), Function("afunction")]) project['bad_module'].errors = ["Syntax error"] project.save() project = Project.from_directory(project.path) assert_equal(2, len(project.get_modules())) assert_equal(2, len(project['good_module'].objects)) assert_equal(["AClass"], get_names(project['good_module'].classes)) assert_equal(["amethod"], get_names(project['good_module'].classes[0].methods)) assert_equal(["afunction"], get_names(project['good_module'].functions)) assert_equal(["Syntax error"], project['bad_module'].errors)
def test_doesnt_save_uncomplete_pickle_files(self): project = ProjectInDirectory(self.tmpdir) project.save() original_pickle = read_file_contents(project._get_pickle_path()) # Inject unpickable object into project. project._injected_attr = UNPICKABLE_OBJECT try: project.save() except PicklingError: pass # Make sure that the original file wasn't overwritten. assert_equal_strings(original_pickle, read_file_contents(project._get_pickle_path()))
def test_can_be_saved_and_restored_from_file(self): project = ProjectInDirectory(self.tmpdir).with_modules( ["good_module.py", "bad_module.py"]) project['good_module'].add_objects( [Class("AClass", [Method("amethod")]), Function("afunction")]) project['bad_module'].errors = ["Syntax error"] project.save() project = Project.from_directory(project.path) assert_equal(2, len(project.get_modules())) assert_equal(2, len(project['good_module'].objects)) assert_equal(["AClass"], get_names(project['good_module'].classes)) assert_equal(["amethod"], get_names(project['good_module'].classes[0].methods)) assert_equal(["afunction"], get_names(project['good_module'].functions)) assert_equal(["Syntax error"], project['bad_module'].errors)