Browse Source

Cleaning up imports

pull/3/head
Ryan Reed 2 years ago
parent
commit
4688cde573
2 changed files with 17 additions and 18 deletions
  1. +15
    -16
      tests/test_utils.py
  2. +2
    -2
      tests/utils.py

+ 15
- 16
tests/test_utils.py View File

@ -1,6 +1,5 @@
import json import json
from pathlib import Path
import pathlib
from transpose import version, DEFAULT_CACHE_FILENAME from transpose import version, DEFAULT_CACHE_FILENAME
from transpose.utils import check_path, create_cache, get_cache, move, remove, symlink from transpose.utils import check_path, create_cache, get_cache, move, remove, symlink
@ -11,11 +10,11 @@ from .utils import CACHE_FILE_CONTENTS, STORE_DIR, SYMLINK_DIR, TARGET_DIR, setu
@setup_env() @setup_env()
def test_check_path(): def test_check_path():
existing_dir = Path(TARGET_DIR)
nonexisting_dir = Path("nonexistent")
symlink_dir = Path(SYMLINK_DIR)
existing_dir = pathlib.Path(TARGET_DIR)
nonexisting_dir = pathlib.Path("nonexistent")
symlink_dir = pathlib.Path(SYMLINK_DIR)
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
cache_path = pathlib.Path(TARGET_DIR).joinpath(DEFAULT_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
@ -27,8 +26,8 @@ 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(TARGET_DIR).joinpath(cache_file)
original_path = Path("/tmp/some/random/path")
cache_path = pathlib.Path(TARGET_DIR).joinpath(cache_file)
original_path = pathlib.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)
@ -41,7 +40,7 @@ def test_cache_create():
@setup_env() @setup_env()
def test_cache_get(): def test_cache_get():
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
cache_path = pathlib.Path(TARGET_DIR).joinpath(DEFAULT_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"]
@ -50,8 +49,8 @@ def test_cache_get():
@setup_env() @setup_env()
def test_file_move(): def test_file_move():
source_path = Path(TARGET_DIR)
destination_path = Path(STORE_DIR)
source_path = pathlib.Path(TARGET_DIR)
destination_path = pathlib.Path(STORE_DIR)
move(source=source_path.absolute(), destination=destination_path.absolute()) move(source=source_path.absolute(), destination=destination_path.absolute())
assert not source_path.exists() assert not source_path.exists()
@ -60,9 +59,9 @@ def test_file_move():
@setup_env() @setup_env()
def test_file_remove(): def test_file_remove():
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
symlink_filepath = Path(TARGET_DIR).joinpath(SYMLINK_DIR)
target_filepath = Path(TARGET_DIR)
cache_path = pathlib.Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
symlink_filepath = pathlib.Path(TARGET_DIR).joinpath(SYMLINK_DIR)
target_filepath = pathlib.Path(TARGET_DIR)
remove(path=cache_path) remove(path=cache_path)
remove(path=symlink_filepath) remove(path=symlink_filepath)
@ -76,8 +75,8 @@ def test_file_remove():
@setup_env() @setup_env()
def test_file_symlink(): def test_file_symlink():
symlink_name = "test_link" symlink_name = "test_link"
symlink_filepath = Path(symlink_name)
target_filepath = Path(TARGET_DIR)
symlink_filepath = pathlib.Path(symlink_name)
target_filepath = pathlib.Path(TARGET_DIR)
symlink(target_path=target_filepath, symlink_path=symlink_filepath) symlink(target_path=target_filepath, symlink_path=symlink_filepath)


+ 2
- 2
tests/utils.py View File

@ -1,8 +1,8 @@
import os import os
import json import json
import pathlib
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from transpose import DEFAULT_CACHE_FILENAME, version from transpose import DEFAULT_CACHE_FILENAME, version
@ -27,7 +27,7 @@ def setup_env():
os.mkdir(STORE_DIR) os.mkdir(STORE_DIR)
os.symlink(TARGET_DIR, SYMLINK_DIR) os.symlink(TARGET_DIR, SYMLINK_DIR)
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
cache_path = pathlib.Path(TARGET_DIR).joinpath(DEFAULT_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


Loading…
Cancel
Save