Skip to content

Commit 1dded2b

Browse files
committed
fix test
1 parent 74d3823 commit 1dded2b

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

pathways/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,13 @@ def _get_mapping(data) -> dict:
11011101
"""
11021102
resource = data.get_resource("mapping")
11031103
source = getattr(resource, "source", None)
1104-
if source and Path(source).exists():
1105-
with open(source, "r", encoding="utf-8") as handle:
1104+
try:
1105+
source_path = Path(source) if source is not None else None
1106+
except TypeError:
1107+
source_path = None
1108+
1109+
if source_path and source_path.exists():
1110+
with open(source_path, "r", encoding="utf-8") as handle:
11061111
return yaml.safe_load(handle)
11071112

11081113
return yaml.safe_load(resource.raw_read())

tests/test_pathways.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ def test_get_mapping():
3030
), "Mapping does not match expected dictionary"
3131

3232

33+
def test_get_mapping_reads_mapping_source_file(tmp_path):
34+
mapping_path = tmp_path / "mapping.yaml"
35+
mapping_path.write_text(
36+
"""
37+
variable1:
38+
dataset: [from-file]
39+
""".lstrip(),
40+
encoding="utf-8",
41+
)
42+
43+
resource = Mock()
44+
resource.source = str(mapping_path)
45+
resource.raw_read.return_value = """
46+
variable1:
47+
dataset: [from-raw-read]
48+
"""
49+
50+
mock_data = Mock()
51+
mock_data.get_resource.return_value = resource
52+
53+
assert _get_mapping(mock_data) == {"variable1": {"dataset": ["from-file"]}}
54+
55+
3356
def test_fill_in_result_array_handles_single_mc_iteration_file(tmp_path, monkeypatch):
3457
iter_array = sp.COO.from_numpy(np.arange(24, dtype=float).reshape(2, 1, 3, 4))
3558
iter_path = tmp_path / "iter_results.npz"

0 commit comments

Comments
 (0)