Пример #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())
Пример #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)
Пример #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())
Пример #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())
Пример #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('*')})
Пример #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())
Пример #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)
Пример #8
0
 def test_from_file_path_relative(self):
     with self.assertRaises(ValueError):
         ResourcePath.from_file_path(Path('test_package')),
Пример #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"))
Пример #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"))
Пример #11
0
 def test_from_file_path_installed_packages_root(self):
     self.assertEqual(
         ResourcePath.from_file_path(Path(
             sublime.installed_packages_path())), ResourcePath("Packages"))
Пример #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')),
Пример #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"))
Пример #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"))
Пример #15
0
 def test_file_path_packages(self):
     self.assertEqual(
         ResourcePath("Packages/Foo/bar.py").file_path(),
         Path(sublime.packages_path(), 'Foo/bar.py'))
Пример #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"))
Пример #17
0
 def test_file_path_packages_root(self):
     self.assertEqual(
         ResourcePath("Packages").file_path(),
         Path(sublime.packages_path()))
Пример #18
0
 def test_file_path_cache(self):
     self.assertEqual(
         ResourcePath("Cache/Foo/bar.py").file_path(),
         Path(sublime.cache_path(), 'Foo/bar.py'))