class TestRepositoryTest(TestCase): def setUp(self): self.file_system = InMemoryFileSystem() self.repository = FileBasedTestRepository( self.file_system, Path.fromText("tests"), YamlCodec()) def test_do_not_found_test_that_do_not_exist(self): test_cases = self._fetch_all_tests() self.assertEqual(0, len(test_cases)) def test_found_one_test_if_only_one_yml_exists(self): self._create_file("tests/test.yml", YamlTest.with_latex_code()) test_cases = self.repository.fetch_all() self._verify(test_cases) def test_found_one_test_if_only_one_yaml_exists(self): self._create_file("tests/test.yaml", YamlTest.with_latex_code()) test_cases = self.repository.fetch_all() self._verify(test_cases) def test_ignore_files_that_are_not_yaml(self): self._create_file("tests/test.txt", YamlTest.with_latex_code()) test_cases = self._fetch_all_tests() self.assertEqual(0, len(test_cases)) def test_spot_files_hidden_in_sub_directories(self): self._create_file( "tests/sub_dir/test_2.yml", YamlTest.with_latex_code()) test_cases = self._fetch_all_tests() self._verify(test_cases) def _verify(self, test_cases): self.assertEqual(1, len(test_cases)) expected = FlapTestCase( "test 1", a_project().with_main_file(self.LATEX_CODE).build(), a_project().with_merged_file(self.LATEX_CODE).build()) self.assertEqual(expected, test_cases[0]) LATEX_CODE = ("\\documentclass{article}\n" "\\begin{document}\n" " This is a simple \\LaTeX document!\n" "\\end{document}") def _fetch_all_tests(self): return self.repository.fetch_all() def _create_file(self, path, content): self.file_system.create_file(Path.fromText(path), content)
class LatexProjectExtractionTests(TestCase): def setUp(self): self._file_system = InMemoryFileSystem() self._directory = "home/" self._files = [] def _create_files(self, *files): self._files = files for (path, content) in files: complete_path = Path.fromText(self._directory + path) self._file_system.create_file(complete_path, content) def _extract_project(self): root = self._file_system.open(Path.fromText(self._directory)) return LatexProject.extract_from_directory(root) def _verify(self, project): self._expected().assert_is_equivalent_to(project) def _do_test_with_files(self, *files): self._create_files(*files) project = self._extract_project() self._verify(project) def _expected(self): tex_files = [] for (path, content) in self._files: tex_files.append(TexFile(path, content)) return LatexProject(*tex_files) def test_extracting_a_simple_file(self): self._do_test_with_files(("main.tex", "content")) def test_extracting_a_two_files_project(self): self._do_test_with_files( ("main.tex", "content"), ("result.tex", "Here are some results")) def test_extracting_files_in_a_subdirectory(self): self._do_test_with_files( ("main.tex", "content"), ("test/result.tex", "Here are some results")) def test_extracting_a_complete_project(self): self._do_test_with_files( ("main.tex", "blablabla"), ("sections/introduction.tex", "Here are some results"), ("sections/development.tex", "Some more details"), ("sections/conclusions.tex", "Some more hindsight"), ("images/results.pdf", "PDF CONTENT"), ("images/sources/results.svg", "SVG CODE"), ("article.bib", "The bibliography"))
class TestRepositoryTest(TestCase): def setUp(self): self.file_system = InMemoryFileSystem() self.repository = FileBasedTestRepository( self.file_system, Path.fromText("tests"), YamlCodec()) def test_do_not_found_test_that_do_not_exist(self): test_cases = self._fetch_all_tests() self.assertEqual(0, len(test_cases)) def test_found_one_test_if_only_one_yml_exists(self): self._create_file("tests/test.yml", YamlTest.with_latex_code()) test_cases = self.repository.fetch_all() self._verify(test_cases) def test_found_one_test_if_only_one_yaml_exists(self): self._create_file("tests/test.yaml", YamlTest.with_latex_code()) test_cases = self.repository.fetch_all() self._verify(test_cases) def test_ignore_files_that_are_not_yaml(self): self._create_file("tests/test.txt", YamlTest.with_latex_code()) test_cases = self._fetch_all_tests() self.assertEqual(0, len(test_cases)) def test_spot_files_hidden_in_sub_directories(self): self._create_file("tests/sub_dir/test_2.yml", YamlTest.with_latex_code()) test_cases = self._fetch_all_tests() self._verify(test_cases) def _verify(self, test_cases): self.assertEqual(1, len(test_cases)) expected = FlapTestCase( "test 1", a_project().with_main_file(self.LATEX_CODE).build(), a_project().with_merged_file(self.LATEX_CODE).build()) self.assertEqual(expected, test_cases[0]) LATEX_CODE = ("\\documentclass{article}\n" "\\begin{document}\n" " This is a simple \\LaTeX document!\n" "\\end{document}") def _fetch_all_tests(self): return self.repository.fetch_all() def _create_file(self, path, content): self.file_system.create_file(Path.fromText(path), content)
class LatexProjectExtractionTests(TestCase): def setUp(self): self._file_system = InMemoryFileSystem() self._directory = "home/" self._files = [] def _create_files(self, *files): self._files = files for (path, content) in files: complete_path = Path.fromText(self._directory + path) self._file_system.create_file(complete_path, content) def _extract_project(self): root = self._file_system.open(Path.fromText(self._directory)) return LatexProject.extract_from_directory(root) def _verify(self, project): self._expected().assert_is_equivalent_to(project) def _do_test_with_files(self, *files): self._create_files(*files) project = self._extract_project() self._verify(project) def _expected(self): tex_files = [] for (path, content) in self._files: tex_files.append(TexFile(path, content)) return LatexProject(*tex_files) def test_extracting_a_simple_file(self): self._do_test_with_files(("main.tex", "content")) def test_extracting_a_two_files_project(self): self._do_test_with_files(("main.tex", "content"), ("result.tex", "Here are some results")) def test_extracting_files_in_a_subdirectory(self): self._do_test_with_files(("main.tex", "content"), ("test/result.tex", "Here are some results")) def test_extracting_a_complete_project(self): self._do_test_with_files( ("main.tex", "blablabla"), ("sections/introduction.tex", "Here are some results"), ("sections/development.tex", "Some more details"), ("sections/conclusions.tex", "Some more hindsight"), ("images/results.pdf", "PDF CONTENT"), ("images/sources/results.svg", "SVG CODE"), ("article.bib", "The bibliography"))
class LatexProjectGenerationTests(TestCase): def setUp(self): self._file_system = InMemoryFileSystem() self._directory = "home" def test_setup_a_single_file_project(self): self._do_test_setup(LatexProject(TexFile("main.tex", "blabla"))) def test_setup_a_two_files_project(self): self._do_test_setup( LatexProject(TexFile("main.tex", "blabla"), TexFile("result.tex", "Some results"))) def test_setup_a_project_with_subdirectories(self): self._do_test_setup( LatexProject(TexFile("main.tex", "blabla"), TexFile("sections/introduction.tex", "introduction"), TexFile("sections/conclusions.tex", "conclusions"), TexFile("images/results.pdf", "PDF"))) def _do_test_setup(self, project): project.setup(self._file_system, Path.fromText(self._directory)) self._verify(project) def _verify(self, project): for (path, file) in project.files.items(): file_on_disk = self._file_system.open( Path.fromText(self._directory) / path) self.assertEqual(file.content, file_on_disk.content())
class LatexProjectGenerationTests(TestCase): def setUp(self): self._file_system = InMemoryFileSystem() self._directory = "home" def test_setup_a_single_file_project(self): self._do_test_setup( LatexProject(TexFile("main.tex", "blabla")) ) def test_setup_a_two_files_project(self): self._do_test_setup(LatexProject( TexFile("main.tex", "blabla"), TexFile("result.tex", "Some results")) ) def test_setup_a_project_with_subdirectories(self): self._do_test_setup(LatexProject( TexFile("main.tex", "blabla"), TexFile("sections/introduction.tex", "introduction"), TexFile("sections/conclusions.tex", "conclusions"), TexFile("images/results.pdf", "PDF")) ) def _do_test_setup(self, project): project.setup(self._file_system, Path.fromText(self._directory)) self._verify(project) def _verify(self, project): for (path, file) in project.files.items(): file_on_disk = self._file_system.open(Path.fromText(self._directory) / path) self.assertEqual(file.content, file_on_disk.content())
def setUp(self): self.fileSystem = InMemoryFileSystem() self.current_directory = Path.fromText("/temp")
class InMemoryFileSystemTest(unittest.TestCase): def setUp(self): self.fileSystem = InMemoryFileSystem() self.current_directory = Path.fromText("/temp") def test_file_creation(self): path = Path.fromText("dir/test/source.tex") self.fileSystem.create_file(path, "blah") file = self.fileSystem.open(Path.fromText("dir/test/source.tex")) self.assertTrue(file.exists()) self.assertTrue(file.contains("blah")) def test_create_file_rejects_content_that_is_not_text(self): path = Path.fromText("dir/test.txt") with self.assertRaises(ValueError): self.fileSystem.create_file(path, [1, 2, 3, 4]) def testThatMissingFileDoNotExist(self): path = Path.fromText("file\\that\\do\\not\\exist.txt") file = self.fileSystem.open(path) self.assertFalse(file.exists()) def testContainingDirectoryIsAvailable(self): path = Path.fromText("my\\dir\\test.txt") self.fileSystem.create_file(path, "data") file = self.fileSystem.open(path) self.assertEqual(file.container().path(), ROOT / "my" / "dir") def testFullNameIsAvailable(self): path = Path.fromText("/my/dir/test.txt") self.fileSystem.create_file(path, "data") file = self.fileSystem.open(path) self.assertEqual(file.fullname(), "test.txt") def testBasenameIsAvailable(self): path = Path.fromText("my/dir/test.txt") self.fileSystem.create_file(path, "whatever") file = self.fileSystem.open(path) self.assertEqual(file.basename(), "test") def testDirectoryContainsFiles(self): self.fileSystem.create_file(Path.fromText("dir/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/test2.txt"), "y") file = self.fileSystem.open(Path.fromText("dir")) self.assertEqual(len(file.files()), 2) def testDirectoryContainsOnlyItsDirectContent(self): self.fileSystem.create_file(Path.fromText("dir/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/test2.txt"), "y") self.fileSystem.create_file(Path.fromText("dir/more/test.txt"), "x") directory = self.fileSystem.open(Path.fromText("dir")) self.assertEqual(len(directory.files()), 3, [ str(file.path()) for file in directory.files()]) def testFilteringFilesInDirectory(self): self.fileSystem.create_file(Path.fromText("dir/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/test2.txt"), "y") self.fileSystem.create_file(Path.fromText("dir/blah"), "z") file = self.fileSystem.open(Path.fromText("dir")) self.assertEqual(len(file.files_that_matches("test")), 1) def testCopyingFile(self): source = Path.fromText("dir/test.txt") self.fileSystem.create_file(source, "whatever") file = self.fileSystem.open(source) destination = Path.fromText("dir2/clone") self.fileSystem.copy(file, destination) copy = self.fileSystem.open(destination / "test.txt") self.assertTrue(copy.exists()) self.assertEqual(copy.content(), "whatever") def test_copy_while_renaming(self): source = Path.fromText("dir/test.txt") self.fileSystem.create_file(source, "whatever") file = self.fileSystem.open(source) destination = Path.fromText("dir2/clone/test_copy.txt") self.fileSystem.copy(file, destination) copy = self.fileSystem.open(destination) self.assertTrue(copy.exists()) self.assertEqual(copy.content(), "whatever") def test_files_that_match(self): self.fileSystem.create_file(Path.fromText("dir/foo/bar/test.txt"), "x") directory = self.fileSystem.open(Path.fromText("dir/foo")) results = directory.files_that_matches("bar/test") self.assertEqual(len(results), 1) def test_files_that_match_with_multiple_matches(self): self.fileSystem.create_file(Path.fromText("dir/foo/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/foo/subtest.txt"), "x") directory = self.fileSystem.open(Path.fromText("dir/foo")) results = directory.files_that_matches("test") self.assertEqual(len(results), 1) def test_finding_files_in_the_current_directory(self): path = Path.fromText("/root/foo/bar/test.txt") self.fileSystem.create_file(path, "blahblah blah") self.fileSystem.move_to_directory(Path.fromText("/root/foo")) file = self.fileSystem.open(Path.fromText("bar/test.txt")) self.assertEqual(file.content(), "blahblah blah")
class InMemoryFileSystemTest(unittest.TestCase): def setUp(self): self.fileSystem = InMemoryFileSystem() self.current_directory = Path.fromText("/temp") def test_file_creation(self): path = Path.fromText("dir/test/source.tex") self.fileSystem.create_file(path, "blah") file = self.fileSystem.open(Path.fromText("dir/test/source.tex")) self.assertTrue(file.exists()) self.assertTrue(file.contains("blah")) def test_create_file_rejects_content_that_is_not_text(self): path = Path.fromText("dir/test.txt") with self.assertRaises(ValueError): self.fileSystem.create_file(path, [1, 2, 3, 4]) def testThatMissingFileDoNotExist(self): path = Path.fromText("file\\that\\do\\not\\exist.txt") file = self.fileSystem.open(path) self.assertFalse(file.exists()) def testContainingDirectoryIsAvailable(self): path = Path.fromText("my\\dir\\test.txt") self.fileSystem.create_file(path, "data") file = self.fileSystem.open(path) self.assertEqual(file.container().path(), ROOT / "my" / "dir") def testFullNameIsAvailable(self): path = Path.fromText("/my/dir/test.txt") self.fileSystem.create_file(path, "data") file = self.fileSystem.open(path) self.assertEqual(file.fullname(), "test.txt") def testBasenameIsAvailable(self): path = Path.fromText("my/dir/test.txt") self.fileSystem.create_file(path, "whatever") file = self.fileSystem.open(path) self.assertEqual(file.basename(), "test") def testDirectoryContainsFiles(self): self.fileSystem.create_file(Path.fromText("dir/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/test2.txt"), "y") file = self.fileSystem.open(Path.fromText("dir")) self.assertEqual(len(file.files()), 2) def testDirectoryContainsOnlyItsDirectContent(self): self.fileSystem.create_file(Path.fromText("dir/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/test2.txt"), "y") self.fileSystem.create_file(Path.fromText("dir/more/test.txt"), "x") directory = self.fileSystem.open(Path.fromText("dir")) self.assertEqual(len(directory.files()), 3, [ str(file.path()) for file in directory.files() ]) def testFilteringFilesInDirectory(self): self.fileSystem.create_file(Path.fromText("dir/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/test2.txt"), "y") self.fileSystem.create_file(Path.fromText("dir/blah"), "z") file = self.fileSystem.open(Path.fromText("dir")) self.assertEqual(len(file.files_that_matches("test")), 2) def testCopyingFile(self): source = Path.fromText("dir/test.txt") self.fileSystem.create_file(source, "whatever") file = self.fileSystem.open(source) destination = Path.fromText("dir2/clone") self.fileSystem.copy(file, destination) copy = self.fileSystem.open(destination / "test.txt") self.assertTrue(copy.exists()) self.assertEqual(copy.content(), "whatever") def test_copy_while_renaming(self): source = Path.fromText("dir/test.txt") self.fileSystem.create_file(source, "whatever") file = self.fileSystem.open(source) destination = Path.fromText("dir2/clone/test_copy.txt") self.fileSystem.copy(file, destination) copy = self.fileSystem.open(destination) self.assertTrue(copy.exists()) self.assertEqual(copy.content(), "whatever") def test_files_that_match(self): self.fileSystem.create_file(Path.fromText("dir/foo/bar/test.txt"), "x") directory = self.fileSystem.open(Path.fromText("dir/foo")) results = directory.files_that_matches("bar/test") self.assertEqual(len(results), 1) def test_files_that_match_with_multiple_matches(self): self.fileSystem.create_file(Path.fromText("dir/foo/test.txt"), "x") self.fileSystem.create_file(Path.fromText("dir/foo/subtest.txt"), "x") directory = self.fileSystem.open(Path.fromText("dir/foo")) results = directory.files_that_matches("test") self.assertEqual(len(results), 1) def test_finding_files_in_the_current_directory(self): path = Path.fromText("/root/foo/bar/test.txt") self.fileSystem.create_file(path, "blahblah blah") self.fileSystem.move_to_directory(Path.fromText("/root/foo")) file = self.fileSystem.open(Path.fromText("bar/test.txt")) self.assertEqual(file.content(), "blahblah blah")
def setUp(self): self._file_system = InMemoryFileSystem() self._directory = "home/" self._files = []
def setUp(self): self.file_system = InMemoryFileSystem() self.repository = FileBasedTestRepository( self.file_system, Path.fromText("tests"), YamlCodec())