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