forked from ChelseaKR/tods-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config_extends.py
More file actions
53 lines (38 loc) · 1.89 KB
/
Copy pathtest_config_extends.py
File metadata and controls
53 lines (38 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Config profiles and extends inheritance."""
from pathlib import Path
import pytest
from tods_validate.config import ConfigError, load_config
def test_profile_sets_defaults(tmp_path: Path) -> None:
cfg = tmp_path / "tods-validate.toml"
cfg.write_text('profile = "strict"\n', encoding="utf-8")
config = load_config(cfg)
assert config.fail_on == "warning"
assert "coverage" in config.enable
def test_local_overrides_profile(tmp_path: Path) -> None:
cfg = tmp_path / "tods-validate.toml"
cfg.write_text('profile = "strict"\nfail-on = "error"\n', encoding="utf-8")
config = load_config(cfg)
assert config.fail_on == "error" # local file wins over the profile
def test_extends_merges_base(tmp_path: Path) -> None:
base = tmp_path / "base.toml"
base.write_text('ignore = ["TODS-W206"]\nfail-on = "warning"\n', encoding="utf-8")
child = tmp_path / "tods-validate.toml"
child.write_text('extends = "base.toml"\nignore = ["TODS-I108"]\n', encoding="utf-8")
config = load_config(child)
assert set(config.ignore) == {"TODS-W206", "TODS-I108"}
assert config.fail_on == "warning" # inherited from base
def test_extends_missing_target_errors(tmp_path: Path) -> None:
child = tmp_path / "tods-validate.toml"
child.write_text('extends = "nope.toml"\n', encoding="utf-8")
with pytest.raises(ConfigError, match="does not exist"):
load_config(child)
def test_unknown_profile_errors(tmp_path: Path) -> None:
cfg = tmp_path / "tods-validate.toml"
cfg.write_text('profile = "turbo"\n', encoding="utf-8")
with pytest.raises(ConfigError, match="unknown profile"):
load_config(cfg)
def test_max_findings_must_be_non_negative(tmp_path: Path) -> None:
cfg = tmp_path / "tods-validate.toml"
cfg.write_text("max-findings = -1\n", encoding="utf-8")
with pytest.raises(ConfigError, match="non-negative"):
load_config(cfg)