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 test_as_absolute_with_implicit_current(self): path = Path.fromText("test/foo.txt") absolute_path = path.absolute_from(Path.fromText("/home/franck")) self.assertEqual(absolute_path, Path.fromText("/home/franck/test/foo.txt"))
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_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 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 files_that_matches(self, pattern): path = Path.fromText(str(self._path) + "/" + str(pattern)) directory = self.fileSystem.open(path.container()) return [ any_file for any_file in directory.files() if str(any_file.path()).startswith(str(path)) ]
def _find(path, directories, extensions, error): for any_directory in directories: candidates = any_directory.files_that_matches(Path.fromText(path)) for any_possible_extension in extensions: for any_resource in candidates: if any_resource.has_extension(any_possible_extension): return any_resource raise error
def load_tests(loader, tests, pattern): file_system = OSFileSystem() repository = FileBasedTestRepository(file_system, Path.fromText("tests/acceptance/scenarios"), YamlCodec()) runner = EndToEndRunner(file_system) generate = Generator(repository, runner) suite = TestSuite() tests = loader.loadTestsFromTestCase(generate.test_class()) suite.addTests(tests) return suite
def __init__(self): super().__init__() self.current_directory = Path.fromText(os.getcwd())
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 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 test_as_absolute_with_absolute_path(self): path = Path.fromText("/home/test/foo.txt") absolute_path = path.absolute_from(Path.fromText("/home/franck")) self.assertEqual(absolute_path, Path.fromText("/home/test/foo.txt"))
def test_relative_to_file(self): path = Path.fromText("/home/test/foo.txt") relative = path.relative_to(Path.fromText("/home/test")) self.assertEquals(relative, Path.fromText("foo.txt"))
def testThatMissingFileDoNotExist(self): path = Path.fromText("file\\that\\do\\not\\exist.txt") file = self.fileSystem.open(path) self.assertFalse(file.exists())
def test_as_absolute_with_root(self): path = ROOT absolute_path = path.absolute_from(Path.fromText("/home/franck")) self.assertEqual(absolute_path, ROOT)
def test_is_absolute_on_windows_paths(self): path = Path.fromText("C:\\Users\\franckc\\file.txt") self.assertTrue(path.is_absolute())
def test_is_absolute_with_relative(self): path = Path.fromText("franck/test.tex") self.assertFalse(path.is_absolute())
def test_is_absolute_on_unix_paths(self): path = Path.fromText("/home/franck/test.tex") self.assertTrue(path.is_absolute())
def test_relative_to_directory(self): path = Path.fromText("/home/test/foo.txt") relative = path.relative_to(Path.fromText("/home")) self.assertEquals(relative, Path.fromText("test/foo.txt"))
def test_parsing_directory(self): path = Path.fromText("project/img/") parts = [each.fullname() for each in path.parts()] self.assertEqual(parts, ["project", "img"], "Wrong parts!")
def testPathBuilding(self): path = Path.fromText("\\Users\\franckc\\file.txt") self.assertEqual(path, ROOT / "Users" / "franckc" / "file.txt")
def test_relative_to_directory(self): path = Path.fromText("/home/test/foo.txt") relative = path.relative_to(Path.fromText("/home")) self.assertEqual(relative, Path.fromText("test/foo.txt"))
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 _verify_generated_files(self, test_case): location = self._file_system.open(Path.fromText("output")) actual = LatexProject.extract_from_directory(location) actual.assert_is_equivalent_to(test_case._expected)
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 output_directory(self): return Path.fromText(self._output)
def _do_test_setup(self, project): project.setup(self._file_system, Path.fromText(self._directory)) self._verify(project)
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 _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 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 _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 testParts(self): path = Path.fromText("C:\\Users\\franckc\\pub\\JOCC\\main.tex") self.verify_parts(path, ["C:", "Users", "franckc", "pub", "JOCC", "main.tex"])
def _extract_project(self): root = self._file_system.open(Path.fromText(self._directory)) return LatexProject.extract_from_directory(root)
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 setUp(self): self.fileSystem = InMemoryFileSystem() self.current_directory = Path.fromText("/temp")
def test_remove_trailing_spaces(self): path = Path.fromText("/text/ blabla /test.txt") self.assertEqual(path, Path.fromText("/text/blabla/test.txt"))
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 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 testPathWithNewlines(self): path = Path.fromText("/Root/Foo\nBar\nBaz/home") self.verify_parts(path, ["", "Root", "FooBarBaz", "home"])
def test_empty_container(self): path = Path.fromText("foo.tex") self.assertEquals(CURRENT_DIRECTORY, path.container())
def test_without_extension(self): path = Path.fromText("/home/test/foo.txt") self.assertEquals(path.without_extension(), Path.fromText("/home/test/foo"))
def root_tex_file(self): return Path.fromText(self._root_tex_file)
def _verify_generated_files(self, test_case): location = self._file_system.open(Path.fromText("output")) actual = LatexProject.extract_from_directory(location) test_case._expected.assert_is_equivalent_to(actual)