Skip to content

Commit ec2f786

Browse files
committed
Add fixture to tear down configs and make sure project init folders are not written.
1 parent f29a8d8 commit ec2f786

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

tests/test_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def delete_all_folders_in_project_path(project, local_or_central):
108108
""""""
109109
folder = f"{local_or_central}_path"
110110

111-
if folder == "central_path" and project.cfg[folder] is None:
111+
if project.cfg is None or (
112+
folder == "central_path" and project.cfg[folder] is None
113+
):
112114
return
113115

114116
ds_logger.close_log_filehandler()

tests/tests_regression/test_backwards_compatibility.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1+
import os
12
import shutil
23
from pathlib import Path
34

45
import pytest
6+
import test_utils
57

68
from datashuttle import DataShuttle
79

10+
TEST_PROJECT_NAME = "test_project"
11+
812

913
class TestBackwardsCompatibility:
1014

1115
@pytest.fixture(scope="function")
1216
def project(self):
13-
""" """
14-
project = DataShuttle("test_project")
17+
"""
18+
Delete the project configs if they exist,
19+
and tear down after the test has run.
20+
"""
21+
test_utils.delete_project_if_it_exists(TEST_PROJECT_NAME)
22+
23+
project = DataShuttle(TEST_PROJECT_NAME)
1524

1625
yield project
1726

18-
def test_v0_6_0(self):
27+
test_utils.delete_project_if_it_exists(TEST_PROJECT_NAME)
28+
29+
def test_v0_6_0(self, project, tmp_path):
1930
"""
2031
v0.6.0 is the first version with narrow datatypes, and the checkboxes was refactored to
2132
be a {"on": bool, "displayed": bool} dict rather than a bool indicating whether the checkbox is on.
2233
However, this version is missing narrow datatypes added later (e.g. "motion").
2334
In the test file, all 'displayed' are turned off except f2pe.
2435
"""
2536
reloaded_ver_configs, reloaded_ver_persistent_settings = (
26-
self.load_and_check_old_version_yamls("v0.6.0")
37+
self.load_and_check_old_version_yamls(project, tmp_path, "v0.6.0")
2738
)
2839

2940
assert reloaded_ver_configs["local_path"] == Path("old_ver")
@@ -43,13 +54,13 @@ def test_v0_6_0(self):
4354
for key in transfer_checkboxes.keys():
4455
assert transfer_checkboxes[key]["displayed"] is (key == "f2pe")
4556

46-
def test_v0_5_3(self):
57+
def test_v0_5_3(self, project, tmp_path):
4758
"""
4859
This version did not have narrow datatypes, and the persistent checkbox setting was only a
4960
bool. Therefore, the "displayed" uses the canonical defaults (because they don't exist in the file yet).
5061
"""
5162
reloaded_ver_configs, reloaded_ver_persistent_settings = (
52-
self.load_and_check_old_version_yamls("v0.5.3")
63+
self.load_and_check_old_version_yamls(project, tmp_path, "v0.5.3")
5364
)
5465

5566
assert reloaded_ver_configs["local_path"] == Path("old_ver")
@@ -70,14 +81,18 @@ def test_v0_5_3(self):
7081
assert transfer_checkboxes["motion"]["displayed"] is False
7182
assert transfer_checkboxes["f2pe"]["displayed"] is False
7283

73-
def load_and_check_old_version_yamls(self, datashuttle_version):
84+
def load_and_check_old_version_yamls(
85+
self, project, tmp_path, datashuttle_version
86+
):
7487
"""
7588
Load an old config file in the current datashuttle version,
7689
and check that the new-version ('canonical') configs
7790
and persistent settings match the structure of the
7891
files loaded from the old datashuttle version.
7992
"""
80-
project = DataShuttle("test_project")
93+
# Switch dir so folders created in `DataShuttle` init do
94+
# not pollute the users test drive.
95+
os.chdir(tmp_path)
8196

8297
# Set up paths and clear any existing config files for this project
8398
old_version_path = (
@@ -92,7 +107,7 @@ def load_and_check_old_version_yamls(self, datashuttle_version):
92107

93108
# In the current version of datashuttle, get the settings. These are
94109
# thus correct for the most recent datashuttle version.
95-
project = DataShuttle("test_project")
110+
project = DataShuttle(TEST_PROJECT_NAME)
96111
project.make_config_file("cur_ver", "cur_ver", "local_filesystem")
97112

98113
current_ver_configs = project.get_configs()
@@ -105,7 +120,7 @@ def load_and_check_old_version_yamls(self, datashuttle_version):
105120
shutil.copy(old_version_path / "config.yaml", config_path)
106121
shutil.copy(old_version_path / "persistent_settings.yaml", config_path)
107122

108-
project = DataShuttle("test_project")
123+
project = DataShuttle(TEST_PROJECT_NAME)
109124

110125
reloaded_ver_configs = project.get_configs()
111126
reloaded_ver_persistent_settings = project._load_persistent_settings()

0 commit comments

Comments
 (0)