Skip to content

Commit 915c7a4

Browse files
committed
Add path handling test
1 parent ee7da35 commit 915c7a4

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/pandas_openscm/db/path_handling.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def rel_db_validator(self, attribute: attr.Attribute[Any], value: Path) -> None:
4848
`value` is not within `self.abs`
4949
"""
5050
if not str(self.abs).endswith(str(value)):
51-
msg = f"{value} for {attribute.name} is not within {self.abs=}"
51+
msg = (
52+
f"{attribute.name} value, {value!r}, "
53+
f"is not a sub-path of {self.abs=!r}"
54+
)
5255
raise AssertionError(msg)
5356

5457
@classmethod
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Tests of `pandas_openscm.db.path_handling`
3+
"""
4+
5+
import re
6+
from contextlib import nullcontext as does_not_raise
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
from pandas_openscm.db.path_handling import DBPath
12+
13+
14+
@pytest.mark.parametrize(
15+
"abs, rel_db, exp",
16+
(
17+
(Path("/a/b/c/d.csv"), Path("d.csv"), does_not_raise()),
18+
(Path("/a/b/c/d.csv"), Path("c/d.csv"), does_not_raise()),
19+
(
20+
Path("/a/b/c/d.csv"),
21+
Path("e/d.csv"),
22+
pytest.raises(
23+
AssertionError,
24+
match="".join(
25+
(
26+
re.escape("rel_db value, "),
27+
".*Path",
28+
re.escape(r"('e/d.csv'), is not a sub-path of self.abs="),
29+
".*Path",
30+
re.escape("('/a/b/c/d.csv')"),
31+
)
32+
),
33+
),
34+
),
35+
),
36+
)
37+
def test_rel_db_validator(abs, rel_db, exp):
38+
with exp:
39+
DBPath(abs=abs, rel_db=rel_db)

0 commit comments

Comments
 (0)