From 120802a2120ecca6344ae787f53b64a056728342 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Thu, 30 Jun 2022 10:13:45 -0400 Subject: [PATCH] Removing PurePath as unnecessary --- tests/test_project.py | 20 ++++++++++---------- transpose/transpose.py | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index dcda3e5..db8c0af 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -1,7 +1,7 @@ import json import os -from pathlib import Path, PurePath +from pathlib import Path from contextlib import contextmanager from tempfile import TemporaryDirectory @@ -31,7 +31,7 @@ def setup(): os.mkdir(STORE_DIR) os.symlink(TARGET_DIR, SYMLINK_DIR) - cache_path = Path(PurePath(TARGET_DIR, config.cache_filename)) + cache_path = Path(TARGET_DIR, config.cache_filename) with open(str(cache_path), "w") as f: json.dump(CACHE_FILE_CONTENTS, f) yield @@ -45,7 +45,7 @@ def test_check_path(): nonexisting_dir = Path("nonexistent") symlink_dir = Path(SYMLINK_DIR) - cache_path = Path(PurePath(TARGET_DIR, config.cache_filename)) + cache_path = Path(TARGET_DIR).joinpath(config.cache_filename) assert check_path(existing_dir) is True assert check_path(nonexisting_dir) is False @@ -57,7 +57,7 @@ def test_check_path(): def test_cache_create(): cache_file = "test_cache_file.json" - cache_path = Path(PurePath(TARGET_DIR, cache_file)) + cache_path = Path(TARGET_DIR).joinpath(cache_file) original_path = Path("/tmp/some/random/path") create_cache(cache_path=cache_path, original_path=original_path) @@ -71,7 +71,7 @@ def test_cache_create(): @setup() def test_cache_get(): - cache_path = Path(PurePath(TARGET_DIR, config.cache_filename)) + cache_path = Path(TARGET_DIR).joinpath(config.cache_filename) cache = get_cache(cache_path) assert cache["version"] == CACHE_FILE_CONTENTS["version"] @@ -90,8 +90,8 @@ def test_file_move(): @setup() def test_file_remove(): - cache_path = Path(PurePath(TARGET_DIR, config.cache_filename)) - symlink_filepath = Path(PurePath(TARGET_DIR, SYMLINK_DIR)) + cache_path = Path(TARGET_DIR).joinpath(config.cache_filename) + symlink_filepath = Path(TARGET_DIR).joinpath(SYMLINK_DIR) target_filepath = Path(TARGET_DIR) remove(path=cache_path) @@ -123,13 +123,13 @@ def test_transpose_init(): store_path=STORE_DIR, ) assert t.cache_filename == ".transpose.json" - assert t.cache_path == Path(PurePath(TARGET_DIR, ".transpose.json")) + assert t.cache_path == Path(TARGET_DIR).joinpath(".transpose.json") t = Transpose( target_path=TARGET_DIR, store_path=STORE_DIR, cache_filename=".transpose.txt" ) assert t.cache_filename == ".transpose.txt" - assert t.cache_path == Path(PurePath(TARGET_DIR, ".transpose.txt")) + assert t.cache_path == Path(TARGET_DIR).joinpath(".transpose.txt") @setup() @@ -141,7 +141,7 @@ def test_transpose_store_restore(): t.store("TestStore") target_path = Path(TARGET_DIR) - store_path = Path(PurePath(STORE_DIR, "TestStore")) + store_path = Path(STORE_DIR).joinpath("TestStore") assert store_path.is_dir() and not store_path.is_symlink() assert target_path.is_dir() and target_path.is_symlink() diff --git a/transpose/transpose.py b/transpose/transpose.py index bf9ebd3..4840a96 100644 --- a/transpose/transpose.py +++ b/transpose/transpose.py @@ -1,4 +1,4 @@ -from pathlib import Path, PurePath +from pathlib import Path from .exceptions import TransposeError from .utils import check_path, create_cache, get_cache, move, remove, symlink @@ -14,7 +14,7 @@ class Transpose: if not cache_filename: cache_filename = ".transpose.json" self.cache_filename = cache_filename - self.cache_path = Path(PurePath(self.target_path, cache_filename)) + self.cache_path = Path(self.target_path).joinpath(cache_filename) def restore(self) -> None: """ @@ -47,7 +47,7 @@ class Transpose: move(source=self.target_path, destination=original_path) - new_cache_path = Path(PurePath(original_path, self.cache_filename)) + new_cache_path = Path(original_path).joinpath(self.cache_filename) remove(new_cache_path) def store(self, name: str) -> None: @@ -61,7 +61,7 @@ class Transpose: 4. Move the `target_path` to `store_path/name` 5. Create symlink `target_path` -> `store_path/name` """ - new_location = Path(PurePath(self.store_path, name)) + new_location = Path(self.store_path).joinpath(name) if not check_path(path=self.target_path): raise TransposeError(