def test_from_files(self): filetext1 = textwrap.dedent("""\ suite foo family bar edit FOOBAR 5 task baz endfamily endsuite """) filetext2 = filetext1.replace("baz", "boo") expected = [ d.context_to_string(no_labels=True) for d in DiffList(filetext1, filetext2)._diffs ] with tempfile.NamedTemporaryFile(mode="w+t", delete=False) as file1: file1.write(filetext1) file1.seek(0) with tempfile.NamedTemporaryFile(mode="w+t", delete=False) as file2: file2.write(filetext2) file2.seek(0) actual = [ d.context_to_string(no_labels=True) for d in DiffList.from_files(file1.name, file2.name)._diffs ] assert expected == actual
def test_from_files_error(self): """ Test that the correct exception is raised when attempting to load from a file that cannot be found. """ # Create an empty temporary directory: tmpdir = tempfile.mkdtemp() # Construct a path to a file that does not exist: invalid_file_path = os.path.join(tmpdir, "file1.def") # Verify that the correct exception is raised when the file is not # found, making sure to clean up the temporary directory before the # test exits regardless of the outcome. try: with pytest.raises(IOError) as excinfo: DiffList.from_files(invalid_file_path, invalid_file_path) expected_msg = "failed to load from file" assert expected_msg in str(excinfo.value) finally: os.rmdir(tmpdir)