Ejemplo n.º 1
0
    def test_copytree_exists(self):
        with tempfile.TemporaryDirectory() as directory:
            source = ResourcePath("Packages/test_package")
            destination = Path(directory) / 'tree'
            destination.mkdir()

            helloworld_file = destination / 'helloworld.txt'

            with open(str(helloworld_file), 'w') as file:
                file.write("Nothing to see here.\n")

            source.copytree(destination, exist_ok=True)

            self.assertEqual(
                {
                    path.relative_to(destination).parts
                    for path in destination.rglob('*') if path.is_file()
                }, {path.relative_to(source)
                    for path in source.rglob('*')})

            with open(str(helloworld_file)) as file:
                helloworld_contents = file.read()

            self.assertEqual(helloworld_contents,
                             (source / 'helloworld.txt').read_text())
Ejemplo n.º 2
0
    def test_copytree_exists_error(self):
        with tempfile.TemporaryDirectory() as directory:
            source = ResourcePath("Packages/test_package")
            destination = Path(directory) / 'tree'
            destination.mkdir()

            with self.assertRaises(FileExistsError):
                source.copytree(destination)
Ejemplo n.º 3
0
    def test_copy_directory_error(self):
        with tempfile.TemporaryDirectory() as directory:
            source = ResourcePath("Packages/test_package/helloworld.txt")
            destination = Path(directory) / 'helloworld.txt'

            destination.mkdir()

            with self.assertRaises(IsADirectoryError):
                source.copy(destination)

            self.assertTrue(destination.is_dir())
Ejemplo n.º 4
0
    def test_copy_text(self):
        with tempfile.TemporaryDirectory() as directory:
            source = ResourcePath("Packages/test_package/helloworld.txt")
            destination = Path(directory) / 'helloworld.txt'

            source.copy(destination)

            self.assertTrue(destination.is_file())

            with open(str(destination), 'r') as file:
                text = file.read()

            self.assertEqual(text, source.read_text())
Ejemplo n.º 5
0
    def test_copytree(self):
        with tempfile.TemporaryDirectory() as directory:
            source = ResourcePath("Packages/test_package")
            destination = Path(directory) / 'tree'

            source.copytree(destination)

            self.assertEqual(
                {
                    path.relative_to(destination).parts
                    for path in destination.rglob('*') if path.is_file()
                }, {path.relative_to(source)
                    for path in source.rglob('*')})
Ejemplo n.º 6
0
    def test_copy_binary(self):
        with tempfile.TemporaryDirectory() as directory:
            source = ResourcePath("Packages/test_package/UTF-8-test.txt")
            destination = Path(directory) / 'UTF-8-test.txt'

            source.copy(destination)

            self.assertTrue(destination.is_file())

            with open(str(destination), 'rb') as file:
                data = file.read()

            self.assertEqual(data, source.read_bytes())
Ejemplo n.º 7
0
    def test_copy_existing_error(self):
        with tempfile.TemporaryDirectory() as directory:
            source = ResourcePath("Packages/test_package/helloworld.txt")
            destination = Path(directory) / 'helloworld.txt'

            text = "Nothing to see here.\n"
            with open(str(destination), 'w') as file:
                file.write(text)

            with self.assertRaises(FileExistsError):
                source.copy(destination, False)
Ejemplo n.º 8
0
 def test_from_file_path_relative(self):
     with self.assertRaises(ValueError):
         ResourcePath.from_file_path(Path('test_package')),
Ejemplo n.º 9
0
 def test_from_file_path_default_packages_root(self):
     self.assertEqual(
         ResourcePath.from_file_path(
             Path(sublime.executable_path()).parent / 'Packages'),
         ResourcePath("Packages"))
Ejemplo n.º 10
0
 def test_from_file_path_default_packages(self):
     self.assertEqual(
         ResourcePath.from_file_path(
             Path(sublime.executable_path()).parent.joinpath(
                 'Packages', 'test_package.sublime-package', 'foo.py')),
         ResourcePath("Packages/test_package/foo.py"))
Ejemplo n.º 11
0
 def test_from_file_path_installed_packages_root(self):
     self.assertEqual(
         ResourcePath.from_file_path(Path(
             sublime.installed_packages_path())), ResourcePath("Packages"))
Ejemplo n.º 12
0
 def test_from_file_path_installed_packages_not_installed(self):
     with self.assertRaises(ValueError):
         ResourcePath.from_file_path(
             Path(sublime.installed_packages_path(), 'test_package',
                  'foo.py')),
Ejemplo n.º 13
0
 def test_from_file_path_installed_packages(self):
     self.assertEqual(
         ResourcePath.from_file_path(
             Path(sublime.installed_packages_path(),
                  'test_package.sublime-package', 'foo.py')),
         ResourcePath("Packages/test_package/foo.py"))
Ejemplo n.º 14
0
 def test_from_file_path_packages(self):
     self.assertEqual(
         ResourcePath.from_file_path(
             Path(sublime.packages_path(), 'test_package')),
         ResourcePath("Packages/test_package"))
Ejemplo n.º 15
0
 def test_file_path_packages(self):
     self.assertEqual(
         ResourcePath("Packages/Foo/bar.py").file_path(),
         Path(sublime.packages_path(), 'Foo/bar.py'))
Ejemplo n.º 16
0
 def test_from_file_path_cache(self):
     self.assertEqual(
         ResourcePath.from_file_path(
             Path(sublime.cache_path(), 'test_package')),
         ResourcePath("Cache/test_package"))
Ejemplo n.º 17
0
 def test_file_path_packages_root(self):
     self.assertEqual(
         ResourcePath("Packages").file_path(),
         Path(sublime.packages_path()))
Ejemplo n.º 18
0
 def test_file_path_cache(self):
     self.assertEqual(
         ResourcePath("Cache/Foo/bar.py").file_path(),
         Path(sublime.cache_path(), 'Foo/bar.py'))