|
|
@ -1,11 +1,12 @@ |
|
|
|
import json |
|
|
|
import pathlib |
|
|
|
import pytest |
|
|
|
import shutil |
|
|
|
|
|
|
|
from transpose import Transpose, version, DEFAULT_CACHE_FILENAME |
|
|
|
from transpose.exceptions import TransposeError |
|
|
|
|
|
|
|
from .utils import STORE_DIR, TARGET_DIR, setup_env |
|
|
|
from .utils import STORE_DIR, STORED_DIR, TARGET_DIR, setup_env |
|
|
|
|
|
|
|
|
|
|
|
@setup_env() |
|
|
@ -28,7 +29,7 @@ def test_init(): |
|
|
|
def test_apply(): |
|
|
|
store_path = pathlib.Path(STORE_DIR) |
|
|
|
target_path = pathlib.Path(TARGET_DIR) |
|
|
|
store_path.rmdir() |
|
|
|
shutil.rmtree(store_path) |
|
|
|
target_path.rename(store_path) |
|
|
|
|
|
|
|
t = Transpose( |
|
|
@ -57,29 +58,33 @@ def test_apply(): |
|
|
|
|
|
|
|
|
|
|
|
@setup_env() |
|
|
|
def test_store_restore(): |
|
|
|
def test_store(): |
|
|
|
t = Transpose( |
|
|
|
target_path=TARGET_DIR, |
|
|
|
store_path=STORE_DIR, |
|
|
|
) |
|
|
|
t.store("TestStore") |
|
|
|
|
|
|
|
target_path = pathlib.Path(TARGET_DIR) |
|
|
|
store_path = pathlib.Path(STORE_DIR).joinpath("TestStore") |
|
|
|
t.store("TestStore") |
|
|
|
|
|
|
|
# STORE |
|
|
|
## Successful Store |
|
|
|
assert store_path.is_dir() and not store_path.is_symlink() |
|
|
|
assert target_path.is_dir() and target_path.is_symlink() |
|
|
|
assert t.cache_path.is_file() |
|
|
|
|
|
|
|
|
|
|
|
@setup_env() |
|
|
|
def test_restore(): |
|
|
|
target_path = pathlib.Path(TARGET_DIR) |
|
|
|
stored_path = pathlib.Path(STORE_DIR).joinpath(STORED_DIR) |
|
|
|
|
|
|
|
t = Transpose( |
|
|
|
target_path=str(store_path), |
|
|
|
target_path=str(stored_path), |
|
|
|
store_path=STORE_DIR, |
|
|
|
) |
|
|
|
|
|
|
|
# RESTORE |
|
|
|
## Missing Cache File |
|
|
|
# Missing Cache File |
|
|
|
cache = t.cache_path.read_text() |
|
|
|
t.cache_path.unlink() |
|
|
|
with pytest.raises(TransposeError): |
|
|
@ -87,15 +92,20 @@ def test_store_restore(): |
|
|
|
t.cache_path.write_text(cache) |
|
|
|
cache = json.loads(cache) |
|
|
|
|
|
|
|
## Missing Target Path |
|
|
|
# Missing Target Path (original path) |
|
|
|
t.target_path.rename("newpath") |
|
|
|
with pytest.raises(TransposeError): |
|
|
|
t.restore() |
|
|
|
pathlib.Path("newpath").rename(t.target_path) |
|
|
|
|
|
|
|
## Successful Restore |
|
|
|
# Original Path is a symlink - Should be removed and successfully restore |
|
|
|
original_path = pathlib.Path(cache["original_path"]) |
|
|
|
original_path.rename("newpath") |
|
|
|
original_path.symlink_to("newpath") |
|
|
|
|
|
|
|
# Successful |
|
|
|
t.restore() |
|
|
|
|
|
|
|
assert not store_path.exists() |
|
|
|
assert target_path.is_dir() and not target_path.is_symlink() |
|
|
|
assert not stored_path.exists() |
|
|
|
assert not t.cache_path.exists() |