|
@ -1,101 +1,94 @@ |
|
|
import os |
|
|
|
|
|
import json |
|
|
import json |
|
|
import pathlib |
|
|
|
|
|
|
|
|
|
|
|
from contextlib import contextmanager |
|
|
from contextlib import contextmanager |
|
|
|
|
|
from pathlib import Path |
|
|
|
|
|
from shutil import rmtree |
|
|
from tempfile import TemporaryDirectory |
|
|
from tempfile import TemporaryDirectory |
|
|
|
|
|
|
|
|
from transpose import DEFAULT_CACHE_FILENAME, version |
|
|
|
|
|
|
|
|
from transpose import version |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STORE_DIR = "store" |
|
|
|
|
|
STORED_DIR = "my_app" # Directory already in storage |
|
|
|
|
|
SYMLINK_DIR = "symlink_test" |
|
|
|
|
|
TARGET_DIR = "source" |
|
|
|
|
|
|
|
|
ENTRY_NAME = "MyName" |
|
|
|
|
|
TESTS_PATH = Path("tests-temp") |
|
|
|
|
|
STORE_PATH = TESTS_PATH.joinpath("store") |
|
|
|
|
|
TARGET_PATH = TESTS_PATH.joinpath("source") |
|
|
|
|
|
SYMLINK_TEST_PATH = TESTS_PATH.joinpath("symlink_test") |
|
|
|
|
|
|
|
|
CACHE_FILE_CONTENTS = {"version": version, "original_path": TARGET_DIR} |
|
|
|
|
|
|
|
|
ENTRY_STORE_PATH = STORE_PATH.joinpath(ENTRY_NAME) |
|
|
|
|
|
TRANSPOSE_CONFIG_PATH = STORE_PATH.joinpath("transpose.json") |
|
|
|
|
|
|
|
|
|
|
|
TRANSPOSE_CONFIG = { |
|
|
|
|
|
"version": version, |
|
|
|
|
|
"entries": {ENTRY_NAME: {"name": ENTRY_NAME, "path": str(TARGET_PATH)}}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
@contextmanager |
|
|
def setup_apply(): |
|
|
def setup_apply(): |
|
|
""" |
|
|
""" |
|
|
Create the following directory structure: |
|
|
Create the following directory structure: |
|
|
temp/ |
|
|
|
|
|
|
|
|
tests-temp/ |
|
|
|
|
|
├── store/ |
|
|
|
|
|
│ └── transpose.json |
|
|
├── target/ |
|
|
├── target/ |
|
|
│ └── .transpose.json # contains {"version": version, "original_path": "source/"} |
|
|
|
|
|
└── symlink_test/ -> source/ |
|
|
└── symlink_test/ -> source/ |
|
|
""" |
|
|
""" |
|
|
old_dir = os.getcwd() |
|
|
|
|
|
with TemporaryDirectory("tests-temp") as td: |
|
|
|
|
|
try: |
|
|
|
|
|
os.chdir(td) |
|
|
|
|
|
|
|
|
|
|
|
os.mkdir(STORE_DIR) |
|
|
|
|
|
os.symlink(STORE_DIR, SYMLINK_DIR) |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
with TemporaryDirectory(str(TESTS_PATH)): |
|
|
|
|
|
STORE_PATH.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
TARGET_PATH.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
SYMLINK_TEST_PATH.symlink_to(TARGET_PATH.resolve()) |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
with open(str(TRANSPOSE_CONFIG_PATH), "w") as f: |
|
|
|
|
|
json.dump(TRANSPOSE_CONFIG, f) |
|
|
|
|
|
|
|
|
yield |
|
|
yield |
|
|
finally: |
|
|
|
|
|
os.chdir(old_dir) |
|
|
|
|
|
|
|
|
finally: |
|
|
|
|
|
# This shouldn't be necessary but is for some reason |
|
|
|
|
|
rmtree(TESTS_PATH) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
@contextmanager |
|
|
def setup_restore(): |
|
|
def setup_restore(): |
|
|
""" |
|
|
""" |
|
|
Create the following directory structure: |
|
|
Create the following directory structure: |
|
|
temp/ |
|
|
|
|
|
├── source/ |
|
|
|
|
|
|
|
|
tests-temp/ |
|
|
└── store/ |
|
|
└── store/ |
|
|
└── my_app/ |
|
|
|
|
|
└── .transpose.json # contains {"version": version, "original_path": "source/"} |
|
|
|
|
|
|
|
|
├── MyName/ |
|
|
|
|
|
└── transpose.json |
|
|
""" |
|
|
""" |
|
|
old_dir = os.getcwd() |
|
|
|
|
|
with TemporaryDirectory("tests-temp") as td: |
|
|
|
|
|
try: |
|
|
|
|
|
os.chdir(td) |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
with TemporaryDirectory(str(TESTS_PATH)): |
|
|
|
|
|
ENTRY_STORE_PATH.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
TARGET_PATH.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
|
|
|
os.mkdir(TARGET_DIR) |
|
|
|
|
|
os.mkdir(STORE_DIR) |
|
|
|
|
|
os.mkdir(f"{STORE_DIR}/{STORED_DIR}") |
|
|
|
|
|
|
|
|
|
|
|
target_cache_path = pathlib.Path(f"{STORE_DIR}/{STORED_DIR}").joinpath( |
|
|
|
|
|
DEFAULT_CACHE_FILENAME |
|
|
|
|
|
) |
|
|
|
|
|
with open(str(target_cache_path), "w") as f: |
|
|
|
|
|
json.dump(CACHE_FILE_CONTENTS, f) |
|
|
|
|
|
|
|
|
with open(str(TRANSPOSE_CONFIG_PATH), "w") as f: |
|
|
|
|
|
json.dump(TRANSPOSE_CONFIG, f) |
|
|
|
|
|
|
|
|
yield |
|
|
yield |
|
|
finally: |
|
|
|
|
|
os.chdir(old_dir) |
|
|
|
|
|
|
|
|
finally: |
|
|
|
|
|
# This shouldn't be necessary but is for some reason |
|
|
|
|
|
rmtree(TESTS_PATH) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
@contextmanager |
|
|
def setup_store(): |
|
|
def setup_store(): |
|
|
""" |
|
|
""" |
|
|
Create the following directory structure: |
|
|
Create the following directory structure: |
|
|
temp/ |
|
|
|
|
|
|
|
|
tests-temp/ |
|
|
├── source/ |
|
|
├── source/ |
|
|
│ └── .transpose.json # contains {"version": version, "original_path": "source/"} |
|
|
|
|
|
└── store/ |
|
|
└── store/ |
|
|
|
|
|
└── transpose.json |
|
|
""" |
|
|
""" |
|
|
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) |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
with TemporaryDirectory(str(TESTS_PATH)): |
|
|
|
|
|
TARGET_PATH.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
STORE_PATH.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
|
|
|
target_cache_path = pathlib.Path(TARGET_DIR).joinpath( |
|
|
|
|
|
DEFAULT_CACHE_FILENAME |
|
|
|
|
|
) |
|
|
|
|
|
with open(str(target_cache_path), "w") as f: |
|
|
|
|
|
json.dump(CACHE_FILE_CONTENTS, f) |
|
|
|
|
|
|
|
|
with open(str(TRANSPOSE_CONFIG_PATH), "w") as f: |
|
|
|
|
|
json.dump(TRANSPOSE_CONFIG, f) |
|
|
|
|
|
|
|
|
yield |
|
|
yield |
|
|
finally: |
|
|
|
|
|
os.chdir(old_dir) |
|
|
|
|
|
|
|
|
finally: |
|
|
|
|
|
# This shouldn't be necessary but is for some reason |
|
|
|
|
|
rmtree(TESTS_PATH) |