Skip to content

Commit d50700c

Browse files
committed
Add an error() method to Configuration
1 parent 2b0f4b2 commit d50700c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pgactivity/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,6 @@ def lookup(
356356
return cls.parse(builtin_profile.content, builtin_profile.name)
357357

358358
raise FileNotFoundError(f"profile {profile!r} not found")
359+
360+
def error(self, message: str) -> ConfigurationError:
361+
return ConfigurationError(self.name, message)

tests/test_config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import attr
77
import pytest
88

9-
from pgactivity.config import Configuration, Flag, UISection
9+
from pgactivity.config import Configuration, ConfigurationError, Flag, UISection
1010

1111

1212
def test_flag():
@@ -85,6 +85,13 @@ def asdict(cfg: Configuration) -> dict[str, Any]:
8585
return {k: attr.asdict(v) for k, v in cfg.items()}
8686

8787

88+
def test_error() -> None:
89+
cfg = Configuration(name="test", values={})
90+
with pytest.raises(ConfigurationError, match="test error") as cm:
91+
raise cfg.error("test error")
92+
assert cm.value.filename == "test"
93+
94+
8895
def test_lookup(tmp_path: Path) -> None:
8996
cfg = Configuration.lookup(None, user_config_home=tmp_path)
9097
assert cfg is None

0 commit comments

Comments
 (0)