-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_types.py
More file actions
64 lines (48 loc) · 1.82 KB
/
test_types.py
File metadata and controls
64 lines (48 loc) · 1.82 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
54
55
56
57
58
59
60
61
62
63
64
from pathlib import Path
from scripts.drift_check.checks import VersionSignalCheck
from scripts.drift_check.types import (
Check,
DriftConfig,
FileSnapshot,
Finding,
Pragma,
RepoSnapshot,
SignalResult,
Version,
)
def test_version_asdict():
v = Version(1, 6, 3, "1.6.3")
assert v.as_tuple() == (1, 6, 3)
assert str(v) == "1.6.3"
def test_frozen_dataclasses_immutable():
f = Finding(repo="r", file=None, check="c", severity="error", message="m")
import pytest
with pytest.raises(Exception):
f.repo = "other" # type: ignore[misc]
def test_check_protocol_satisfied_by_real_check():
assert isinstance(VersionSignalCheck(), Check)
def test_drift_config_resolve_layering():
cfg = DriftConfig(
repos={"r1": {"skip_checks": ["a"]}},
types={"cursor-plugin": {"skip_checks": ["b"]}},
globals={"skip_checks": ["c"], "signal_policy": "same-major-minor"},
)
resolved = cfg.resolve("r1", "cursor-plugin")
assert resolved.skip_checks == frozenset({"a", "b", "c"})
assert resolved.signal_policy == "same-major-minor"
def test_signal_result_and_pragma_fields():
s = SignalResult(version=None, format="html-comment", line=1, raw_value="x", malformed=True)
assert s.malformed
p = Pragma(check_name="version-signal", reason=None, format="html-comment", line=2)
assert p.check_name == "version-signal"
def test_file_snapshot_defaults_pragmas():
fs = FileSnapshot(path=Path("x.md"), content=b"", signal=None)
assert fs.pragmas == ()
def test_repo_snapshot_holds_files():
v = Version(1, 6, 3, "1.6.3")
cfg = DriftConfig().resolve("x", "cursor-plugin")
snap = RepoSnapshot(
slug="x", repo_type="cursor-plugin", files={}, meta_version=v,
meta_commit="HEAD", config=cfg,
)
assert snap.slug == "x"