Exemplo n.º 1
0
    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")
Exemplo n.º 2
0
 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"))
Exemplo n.º 3
0
    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")
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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()) == str(path)
         or str(any_file.path()).startswith(str(path) + ".")
     ]
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
 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")
Exemplo n.º 10
0
 def setUp(self):
     self.fileSystem = InMemoryFileSystem()
     self.current_directory = Path.fromText("/temp")
Exemplo n.º 11
0
 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])
Exemplo n.º 12
0
 def test_remove_trailing_spaces(self):
     path = Path.fromText("/text/ blabla /test.txt")
     self.assertEqual(path, Path.fromText("/text/blabla/test.txt"))
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
    def test_without_extension(self):
        path = Path.fromText("/home/test/foo.txt")

        self.assertEquals(path.without_extension(), Path.fromText("/home/test/foo"))
Exemplo n.º 15
0
 def setUp(self):
     self.fileSystem = InMemoryFileSystem()
     self.current_directory = Path.fromText("/temp")
Exemplo n.º 16
0
    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"))
Exemplo n.º 17
0
    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!")
Exemplo n.º 18
0
    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"))
Exemplo n.º 19
0
    def test_as_absolute_with_root(self):
        path = ROOT

        absolute_path = path.absolute_from(Path.fromText("/home/franck"))

        self.assertEqual(absolute_path, ROOT)
Exemplo n.º 20
0
 def test_is_absolute_with_relative(self):
     path = Path.fromText("franck/test.tex")
     self.assertFalse(path.is_absolute())
Exemplo n.º 21
0
 def test_is_absolute_on_windows_paths(self):
     path = Path.fromText("C:\\Users\\franckc\\file.txt")
     self.assertTrue(path.is_absolute())
Exemplo n.º 22
0
 def test_is_absolute_on_unix_paths(self):
     path = Path.fromText("/home/franck/test.tex")
     self.assertTrue(path.is_absolute())
Exemplo n.º 23
0
 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")
Exemplo n.º 24
0
    def testParts(self):
        path = Path.fromText("C:\\Users\\franckc\\pub\\JOCC\\main.tex")

        self.verify_parts(
            path, ["C:", "Users", "franckc", "pub", "JOCC", "main.tex"])
Exemplo n.º 25
0
 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() ])
Exemplo n.º 26
0
 def testPathWithNewlines(self):
     path = Path.fromText("/Root/Foo\nBar\nBaz/home")
     self.verify_parts(path, ["", "Root", "FooBarBaz", "home"])
Exemplo n.º 27
0
    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"))
Exemplo n.º 28
0
 def test_remove_trailing_spaces(self):
     path = Path.fromText("/text/ blabla /test.txt")
     self.assertEqual(path, Path.fromText("/text/blabla/test.txt"))
Exemplo n.º 29
0
 def testThatMissingFileDoNotExist(self):
     path = Path.fromText("file\\that\\do\\not\\exist.txt")
     file = self.fileSystem.open(path)
     self.assertFalse(file.exists())
Exemplo n.º 30
0
 def test_is_absolute_on_unix_paths(self):
     path = Path.fromText("/home/franck/test.tex")
     self.assertTrue(path.is_absolute())
Exemplo n.º 31
0
 def _extract_project(self):
     root = self._file_system.open(Path.fromText(self._directory))
     return LatexProject.extract_from_directory(root)
Exemplo n.º 32
0
 def test_is_absolute_on_windows_paths(self):
     path = Path.fromText("C:\\Users\\franckc\\file.txt")
     self.assertTrue(path.is_absolute())
Exemplo n.º 33
0
 def testPathBuilding(self):
     path = Path.fromText("\\Users\\franckc\\file.txt")
     
     self.assertEqual(path, ROOT / "Users" / "franckc" / "file.txt")
Exemplo n.º 34
0
 def test_is_absolute_with_relative(self):
     path = Path.fromText("franck/test.tex")
     self.assertFalse(path.is_absolute())
Exemplo n.º 35
0
 def test_empty_container(self):
     path = Path.fromText("foo.tex")
     self.assertEquals(CURRENT_DIRECTORY, path.container())
Exemplo n.º 36
0
    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"))
Exemplo n.º 37
0
 def testThatMissingFileDoNotExist(self):
     path = Path.fromText("file\\that\\do\\not\\exist.txt")
     file = self.fileSystem.open(path)
     self.assertFalse(file.exists())
Exemplo n.º 38
0
    def test_as_absolute_with_root(self):
        path = ROOT

        absolute_path = path.absolute_from(Path.fromText("/home/franck"))

        self.assertEqual(absolute_path, ROOT)
Exemplo n.º 39
0
 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")
Exemplo n.º 40
0
    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"))
Exemplo n.º 41
0
 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)
Exemplo n.º 42
0
 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")
Exemplo n.º 43
0
 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)
Exemplo n.º 44
0
 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)
Exemplo n.º 45
0
 def __init__(self):
     super().__init__()
     self.current_directory = Path.fromText(os.getcwd())
Exemplo n.º 46
0
    def testParts(self):
        path = Path.fromText("C:\\Users\\franckc\\pub\\JOCC\\main.tex")

        self.verify_parts(path, ["C:", "Users", "franckc", "pub", "JOCC", "main.tex"])
Exemplo n.º 47
0
 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)
Exemplo n.º 48
0
 def output_directory(self):
     return Path.fromText(self._output)
Exemplo n.º 49
0
 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])
Exemplo n.º 50
0
    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!")
Exemplo n.º 51
0
 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")
Exemplo n.º 52
0
 def testPathWithNewlines(self):
     path = Path.fromText("/Root/Foo\nBar\nBaz/home")
     self.verify_parts(path, ["", "Root", "FooBarBaz", "home"])
Exemplo n.º 53
0
 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")
Exemplo n.º 54
0
 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)
Exemplo n.º 55
0
 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)
Exemplo n.º 56
0
 def _do_test_setup(self, project):
     project.setup(self._file_system, Path.fromText(self._directory))
     self._verify(project)
Exemplo n.º 57
0
 def root_tex_file(self):
     return Path.fromText(self._root_tex_file)
Exemplo n.º 58
0
 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())
Exemplo n.º 59
0
 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)
Exemplo n.º 60
0
 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)