From 165aa4188009bf0ec5ea8dca4820576ba22b8452 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Wed, 29 Jun 2022 20:00:10 -0400 Subject: [PATCH] Adding tests for Transpose class --- tests/test_project.py | 44 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/test_project.py b/tests/test_project.py index f56c672..514a2c9 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -7,7 +7,7 @@ from contextlib import contextmanager from tempfile import TemporaryDirectory from config import Config -from transpose import version +from transpose import Transpose, version from transpose.utils import check_path, create_cache, get_cache, move, remove, symlink @@ -114,3 +114,45 @@ def test_file_symlink(): assert target_filepath.exists() assert symlink_filepath.is_symlink() assert symlink_filepath.readlink() == target_filepath + + +@setup() +def test_transpose_init(): + t = Transpose( + target_path=TARGET_DIR, + store_path=STORE_DIR, + ) + assert t.cache_filename == ".transpose.json" + assert t.cache_path == Path(PurePath(TARGET_DIR, ".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")) + + +@setup() +def test_transpose_store_restore(): + t = Transpose( + target_path=TARGET_DIR, + store_path=STORE_DIR, + ) + t.store("TestStore") + + target_path = Path(TARGET_DIR) + store_path = Path(PurePath(STORE_DIR, "TestStore")) + + 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() + + t = Transpose( + target_path=str(store_path), + store_path=STORE_DIR, + ) + t.restore() + + assert not store_path.exists() + assert target_path.is_dir() and not target_path.is_symlink() + assert not t.cache_path.exists()