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_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_doesnt_overwrite_existing_files_which_were_modified_since_last_analysis(self): TEST_CONTENTS = "# test" project = TestableProject(self.tmpdir, ["test_module.py"]) # File exists, and project contains corresponding, but outdated, test module. existing_file = putfile(project.path, "test_module.py", TEST_CONTENTS) project["test_module"].created = time.time() - 3600 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(existing_file))
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 test(doc): path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, doc)) parser = docutils.parsers.rst.Parser() contents = read_file_contents(path) document = docutils.utils.new_document(path) document.settings.tab_width = 4 document.settings.pep_references = 1 document.settings.rfc_references = 1 # Will raise exception on a mere warning from the parser. document.reporter.halt_level = 0 parser.parse(contents, document)
def test(doc): path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, doc)) parser = docutils.parsers.rst.Parser() contents = read_file_contents(path) document = docutils.utils.new_document(path) document.settings.tab_width = 4 document.settings.pep_references = 1 document.settings.rfc_references = 1 # Will raise exception on a mere warning from the parser. document.reporter.halt_level = 0 parser.parse(contents, document)
def read_data(name): return read_file_contents(data(name))
def inspect_module(project, path): return inspect_code(project, path, read_file_contents(path))
def get_content(self): return read_file_contents(self.get_path())