|
|
@ -6,7 +6,6 @@ from contextlib import contextmanager |
|
|
|
from tempfile import TemporaryDirectory |
|
|
|
|
|
|
|
from transpose import DEFAULT_CACHE_FILENAME, version |
|
|
|
from transpose.exceptions import TransposeError |
|
|
|
|
|
|
|
|
|
|
|
STORE_DIR = "store" |
|
|
@ -18,15 +17,12 @@ CACHE_FILE_CONTENTS = {"version": version, "original_path": TARGET_DIR} |
|
|
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
|
def setup_env(): |
|
|
|
def setup_apply(): |
|
|
|
""" |
|
|
|
Create the following directory structure: |
|
|
|
temp/ |
|
|
|
├── source/ |
|
|
|
├── target/ |
|
|
|
│ └── .transpose.json # contains {"version": version, "original_path": "source/"} |
|
|
|
├── store/ |
|
|
|
│ └── my_app/ |
|
|
|
│ └── .transpose.json # contains {"version": version, "original_path": "source/"} |
|
|
|
└── symlink_test/ -> source/ |
|
|
|
""" |
|
|
|
old_dir = os.getcwd() |
|
|
@ -34,21 +30,71 @@ def setup_env(): |
|
|
|
try: |
|
|
|
os.chdir(td) |
|
|
|
|
|
|
|
os.mkdir(STORE_DIR) |
|
|
|
os.symlink(STORE_DIR, SYMLINK_DIR) |
|
|
|
|
|
|
|
target_cache_path = pathlib.Path(STORE_DIR).joinpath(DEFAULT_CACHE_FILENAME) |
|
|
|
with open(str(target_cache_path), "w") as f: |
|
|
|
json.dump(CACHE_FILE_CONTENTS, f) |
|
|
|
|
|
|
|
yield |
|
|
|
finally: |
|
|
|
os.chdir(old_dir) |
|
|
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
|
def setup_restore(): |
|
|
|
""" |
|
|
|
Create the following directory structure: |
|
|
|
temp/ |
|
|
|
├── source/ |
|
|
|
└── store/ |
|
|
|
└── my_app/ |
|
|
|
└── .transpose.json # contains {"version": version, "original_path": "source/"} |
|
|
|
""" |
|
|
|
old_dir = os.getcwd() |
|
|
|
with TemporaryDirectory("tests-temp") as td: |
|
|
|
try: |
|
|
|
os.chdir(td) |
|
|
|
|
|
|
|
os.mkdir(TARGET_DIR) |
|
|
|
os.mkdir(STORE_DIR) |
|
|
|
os.mkdir(f"{STORE_DIR}/{STORED_DIR}") |
|
|
|
os.symlink(TARGET_DIR, SYMLINK_DIR) |
|
|
|
|
|
|
|
target_cache_path1 = pathlib.Path(TARGET_DIR).joinpath( |
|
|
|
target_cache_path = pathlib.Path(f"{STORE_DIR}/{STORED_DIR}").joinpath( |
|
|
|
DEFAULT_CACHE_FILENAME |
|
|
|
) |
|
|
|
with open(str(target_cache_path1), "w") as f: |
|
|
|
with open(str(target_cache_path), "w") as f: |
|
|
|
json.dump(CACHE_FILE_CONTENTS, f) |
|
|
|
|
|
|
|
target_cache_path2 = pathlib.Path(f"{STORE_DIR}/{STORED_DIR}").joinpath( |
|
|
|
yield |
|
|
|
finally: |
|
|
|
os.chdir(old_dir) |
|
|
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
|
def setup_store(): |
|
|
|
""" |
|
|
|
Create the following directory structure: |
|
|
|
temp/ |
|
|
|
├── source/ |
|
|
|
│ └── .transpose.json # contains {"version": version, "original_path": "source/"} |
|
|
|
└── store/ |
|
|
|
""" |
|
|
|
old_dir = os.getcwd() |
|
|
|
with TemporaryDirectory("tests-temp") as td: |
|
|
|
try: |
|
|
|
os.chdir(td) |
|
|
|
|
|
|
|
os.mkdir(TARGET_DIR) |
|
|
|
os.mkdir(STORE_DIR) |
|
|
|
os.symlink(TARGET_DIR, SYMLINK_DIR) |
|
|
|
|
|
|
|
target_cache_path = pathlib.Path(TARGET_DIR).joinpath( |
|
|
|
DEFAULT_CACHE_FILENAME |
|
|
|
) |
|
|
|
target_cache_path2.write_text(target_cache_path1.read_text()) |
|
|
|
with open(str(target_cache_path), "w") as f: |
|
|
|
json.dump(CACHE_FILE_CONTENTS, f) |
|
|
|
|
|
|
|
yield |
|
|
|
finally: |
|
|
|