Skip to content

Commit 60b30be

Browse files
committed
Fix validate_from_path.
1 parent b316947 commit 60b30be

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

datashuttle/configs/canonical_folders.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ def get_datashuttle_path() -> Path:
8282
return Path.home() / ".datashuttle"
8383

8484

85+
def get_internal_datashuttle_from_path():
86+
"""Get a placeholder path for `validate_project_from_path()`."""
87+
return get_datashuttle_path() / "_datashuttle_from_path"
88+
89+
8590
def get_project_datashuttle_path(project_name: str) -> Tuple[Path, Path]:
8691
"""Return the datashuttle config path for the project.
8792

datashuttle/datashuttle_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
Optional,
1414
)
1515

16-
from datashuttle.configs import (
17-
canonical_configs,
18-
)
16+
from datashuttle.configs import canonical_configs, canonical_folders
1917
from datashuttle.configs.config_class import Configs
2018
from datashuttle.utils import (
2119
validation,
@@ -85,14 +83,16 @@ def validate_project_from_path(
8583

8684
# Create some mock configs for the validation call,
8785
# then for each top-level folder, run the validation
86+
# Note `get_internal_datashuttle_from_path` generates a placeholder
87+
# folder path but this is not actually created.
8888
placeholder_configs = {
8989
key: None for key in canonical_configs.get_canonical_configs().keys()
9090
}
9191
placeholder_configs["local_path"] = Path(project_path) # type: ignore
9292

9393
cfg = Configs(
9494
project_name=project_path.name,
95-
file_path=None, # type: ignore
95+
file_path=canonical_folders.get_internal_datashuttle_from_path(), # type: ignore
9696
input_dict=placeholder_configs,
9797
)
9898

tests/tests_integration/test_validation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from datashuttle import validate_project_from_path
8+
from datashuttle.configs import canonical_folders
89
from datashuttle.utils import formatting, validation
910
from datashuttle.utils.custom_exceptions import NeuroBlueprintError
1011

@@ -787,7 +788,7 @@ def test_name_templates_validate_project(self, project):
787788
# Test Quick Validation Function
788789
# ----------------------------------------------------------------------------------
789790

790-
def test_quick_validation(self, mocker, project):
791+
def test_validate_project_from_path(self, mocker, project):
791792
project.create_folders("rawdata", "sub-1")
792793
os.makedirs(project.cfg["local_path"] / "rawdata" / "sub-02")
793794
project.create_folders("derivatives", "sub-1")
@@ -803,6 +804,12 @@ def test_quick_validation(self, mocker, project):
803804
assert "VALUE_LENGTH" in str(w[1].message)
804805
assert len(w) == 2
805806

807+
# This is used internally to generate a Configs class,
808+
# but should not actually be written to.
809+
assert (
810+
not canonical_folders.get_internal_datashuttle_from_path().exists()
811+
)
812+
806813
# For good measure, monkeypatch and change all defaults,
807814
# ensuring they are propagated to the validate_project
808815
# function (which is tested above)
@@ -824,7 +831,7 @@ def test_quick_validation(self, mocker, project):
824831
assert kwargs["top_level_folder_list"] == ["derivatives"]
825832
assert kwargs["name_templates"] == {"on": False}
826833

827-
def test_quick_validation_top_level_folder(self, project):
834+
def test_validate_from_path_top_level_folder(self, project):
828835
"""Test that errors are raised as expected on
829836
bad project path input.
830837
"""

0 commit comments

Comments
 (0)