Browse Source

Removing PurePath as unnecessary

pull/2/head
Ryan Reed 3 years ago
parent
commit
120802a212
2 changed files with 14 additions and 14 deletions
  1. +10
    -10
      tests/test_project.py
  2. +4
    -4
      transpose/transpose.py

+ 10
- 10
tests/test_project.py View File

@ -1,7 +1,7 @@
import json import json
import os import os
from pathlib import Path, PurePath
from pathlib import Path
from contextlib import contextmanager from contextlib import contextmanager
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
@ -31,7 +31,7 @@ def setup():
os.mkdir(STORE_DIR) os.mkdir(STORE_DIR)
os.symlink(TARGET_DIR, SYMLINK_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: with open(str(cache_path), "w") as f:
json.dump(CACHE_FILE_CONTENTS, f) json.dump(CACHE_FILE_CONTENTS, f)
yield yield
@ -45,7 +45,7 @@ def test_check_path():
nonexisting_dir = Path("nonexistent") nonexisting_dir = Path("nonexistent")
symlink_dir = Path(SYMLINK_DIR) 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(existing_dir) is True
assert check_path(nonexisting_dir) is False assert check_path(nonexisting_dir) is False
@ -57,7 +57,7 @@ def test_check_path():
def test_cache_create(): def test_cache_create():
cache_file = "test_cache_file.json" 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") original_path = Path("/tmp/some/random/path")
create_cache(cache_path=cache_path, original_path=original_path) create_cache(cache_path=cache_path, original_path=original_path)
@ -71,7 +71,7 @@ def test_cache_create():
@setup() @setup()
def test_cache_get(): 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) cache = get_cache(cache_path)
assert cache["version"] == CACHE_FILE_CONTENTS["version"] assert cache["version"] == CACHE_FILE_CONTENTS["version"]
@ -90,8 +90,8 @@ def test_file_move():
@setup() @setup()
def test_file_remove(): 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) target_filepath = Path(TARGET_DIR)
remove(path=cache_path) remove(path=cache_path)
@ -123,13 +123,13 @@ def test_transpose_init():
store_path=STORE_DIR, store_path=STORE_DIR,
) )
assert t.cache_filename == ".transpose.json" 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( t = Transpose(
target_path=TARGET_DIR, store_path=STORE_DIR, cache_filename=".transpose.txt" target_path=TARGET_DIR, store_path=STORE_DIR, cache_filename=".transpose.txt"
) )
assert t.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() @setup()
@ -141,7 +141,7 @@ def test_transpose_store_restore():
t.store("TestStore") t.store("TestStore")
target_path = Path(TARGET_DIR) 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 store_path.is_dir() and not store_path.is_symlink()
assert target_path.is_dir() and target_path.is_symlink() assert target_path.is_dir() and target_path.is_symlink()


+ 4
- 4
transpose/transpose.py View File

@ -1,4 +1,4 @@
from pathlib import Path, PurePath
from pathlib import Path
from .exceptions import TransposeError from .exceptions import TransposeError
from .utils import check_path, create_cache, get_cache, move, remove, symlink from .utils import check_path, create_cache, get_cache, move, remove, symlink
@ -14,7 +14,7 @@ class Transpose:
if not cache_filename: if not cache_filename:
cache_filename = ".transpose.json" cache_filename = ".transpose.json"
self.cache_filename = cache_filename 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: def restore(self) -> None:
""" """
@ -47,7 +47,7 @@ class Transpose:
move(source=self.target_path, destination=original_path) 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) remove(new_cache_path)
def store(self, name: str) -> None: def store(self, name: str) -> None:
@ -61,7 +61,7 @@ class Transpose:
4. Move the `target_path` to `store_path/name` 4. Move the `target_path` to `store_path/name`
5. Create symlink `target_path` -> `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): if not check_path(path=self.target_path):
raise TransposeError( raise TransposeError(


Loading…
Cancel
Save