def test_doesnt_overwrite_existing_files_which_werent_analyzed(self): TEST_CONTENTS = "# test" project = TestableProject(self.tmpdir) # File exists, but project does NOT contain corresponding test module. existing_file = os.path.join(project.new_tests_directory, "test_module.py") putfile(project.path, existing_file, TEST_CONTENTS) def add_and_save(): add_tests_to_project(project, [os.path.join(project.path, "module.py")], 'unittest') project.save() assert_raises(ModuleNeedsAnalysis, add_and_save) assert_equal(TEST_CONTENTS, read_file_contents(project._path_for_test("test_module.py")))
def setUp(self): super(TestGeneratorWithTestDirectoryAsFile, self).setUp() self.project = TestableProject(self.tmpdir) putfile(self.project.path, self.project.new_tests_directory, "its content") self.module_path = os.path.join(self.project.path, "module.py") def add_and_save(): add_tests_to_project(self.project, [self.module_path], 'unittest') self.project.save() self.add_and_save = add_and_save
class TestGeneratorWithTestDirectoryAsFile(TempDirectory): def setUp(self): super(TestGeneratorWithTestDirectoryAsFile, self).setUp() self.project = TestableProject(self.tmpdir) putfile(self.project.path, self.project.new_tests_directory, "its content") self.module_path = os.path.join(self.project.path, "module.py") def add_and_save(): add_tests_to_project(self.project, [self.module_path], 'unittest') self.project.save() self.add_and_save = add_and_save def test_raises_an_exception_if_destdir_is_a_file(self): assert_raises(ModuleSaveError, self.add_and_save) def test_doesnt_save_pickle_file_if_module_save_error_is_raised(self): mtime = get_last_modification_time(self.project._get_pickle_path()) assert_raises(ModuleSaveError, self.add_and_save) assert_equal(mtime, get_last_modification_time(self.project._get_pickle_path()))