|
@ -35,6 +35,21 @@ def test_apply(): |
|
|
target_path=STORE_DIR, |
|
|
target_path=STORE_DIR, |
|
|
store_path=STORE_DIR, |
|
|
store_path=STORE_DIR, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
with open(t.cache_path, "r") as f: |
|
|
|
|
|
cache = json.load(f) |
|
|
|
|
|
|
|
|
|
|
|
# Test cache doesn't exist |
|
|
|
|
|
t.cache_path.unlink() |
|
|
|
|
|
with pytest.raises(TransposeError): |
|
|
|
|
|
t.apply() |
|
|
|
|
|
|
|
|
|
|
|
with open(t.cache_path, "w") as f: |
|
|
|
|
|
json.dump(cache, f) |
|
|
|
|
|
|
|
|
|
|
|
pathlib.Path(cache["original_path"]).symlink_to("bad/path") |
|
|
|
|
|
|
|
|
|
|
|
# Success |
|
|
t.apply() |
|
|
t.apply() |
|
|
|
|
|
|
|
|
assert store_path.is_dir() and not store_path.is_symlink() |
|
|
assert store_path.is_dir() and not store_path.is_symlink() |
|
@ -47,11 +62,13 @@ def test_store_restore(): |
|
|
target_path=TARGET_DIR, |
|
|
target_path=TARGET_DIR, |
|
|
store_path=STORE_DIR, |
|
|
store_path=STORE_DIR, |
|
|
) |
|
|
) |
|
|
t.store("TestStore") |
|
|
|
|
|
|
|
|
|
|
|
target_path = pathlib.Path(TARGET_DIR) |
|
|
target_path = pathlib.Path(TARGET_DIR) |
|
|
store_path = pathlib.Path(STORE_DIR).joinpath("TestStore") |
|
|
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 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() |
|
|
assert t.cache_path.is_file() |
|
|
assert t.cache_path.is_file() |
|
@ -60,6 +77,23 @@ def test_store_restore(): |
|
|
target_path=str(store_path), |
|
|
target_path=str(store_path), |
|
|
store_path=STORE_DIR, |
|
|
store_path=STORE_DIR, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# RESTORE |
|
|
|
|
|
## Missing Cache File |
|
|
|
|
|
cache = t.cache_path.read_text() |
|
|
|
|
|
t.cache_path.unlink() |
|
|
|
|
|
with pytest.raises(TransposeError): |
|
|
|
|
|
t.restore() |
|
|
|
|
|
t.cache_path.write_text(cache) |
|
|
|
|
|
cache = json.loads(cache) |
|
|
|
|
|
|
|
|
|
|
|
## Missing Target Path |
|
|
|
|
|
t.target_path.rename("newpath") |
|
|
|
|
|
with pytest.raises(TransposeError): |
|
|
|
|
|
t.restore() |
|
|
|
|
|
pathlib.Path("newpath").rename(t.target_path) |
|
|
|
|
|
|
|
|
|
|
|
## Successful Restore |
|
|
t.restore() |
|
|
t.restore() |
|
|
|
|
|
|
|
|
assert not store_path.exists() |
|
|
assert not store_path.exists() |
|
|