gabriel / muse public
test_envelope.py python
89 lines 2.6 KB
Raw
sha256:b636f72dcba9e190afb980bece906fa5b717fbde014b76ef023df8cb96e01eb9 docs: expand cache plan with all seven testing tiers and do… Sonnet 4.6 131 days ago
1 """Tests for the standard JSON envelope utility (muse.core.envelope)."""
2
3 from __future__ import annotations
4
5 import time
6 from typing import get_type_hints
7
8 import pytest
9
10 from muse.core.timing import start_timer
11
12
13 class TestMakeEnvelope:
14 """make_envelope() must return all six standard fields."""
15
16 def _call(self, **kwargs):
17 from muse.core.envelope import make_envelope
18 elapsed = start_timer()
19 return make_envelope(elapsed, **kwargs)
20
21 def test_has_muse_version(self):
22 assert "muse_version" in self._call()
23
24 def test_has_schema(self):
25 assert "schema" in self._call()
26
27 def test_has_exit_code(self):
28 assert "exit_code" in self._call()
29
30 def test_has_duration_ms(self):
31 assert "duration_ms" in self._call()
32
33 def test_has_timestamp(self):
34 assert "timestamp" in self._call()
35
36 def test_has_warnings(self):
37 assert "warnings" in self._call()
38
39 def test_muse_version_is_str(self):
40 v = self._call()["muse_version"]
41 assert isinstance(v, str) and v
42
43 def test_schema_defaults_to_1(self):
44 assert self._call()["schema"] == 1
45
46 def test_schema_custom(self):
47 assert self._call(schema=2)["schema"] == 2
48
49 def test_exit_code_defaults_to_0(self):
50 assert self._call()["exit_code"] == 0
51
52 def test_exit_code_custom(self):
53 assert self._call(exit_code=1)["exit_code"] == 1
54
55 def test_duration_ms_is_float(self):
56 assert isinstance(self._call()["duration_ms"], float)
57
58 def test_duration_ms_nonnegative(self):
59 assert self._call()["duration_ms"] >= 0.0
60
61 def test_warnings_defaults_to_empty_list(self):
62 assert self._call()["warnings"] == []
63
64 def test_warnings_custom(self):
65 w = self._call(warnings=["watch out"])["warnings"]
66 assert w == ["watch out"]
67
68 def test_timestamp_is_iso8601_z(self):
69 ts = self._call()["timestamp"]
70 assert isinstance(ts, str)
71 assert ts.endswith("Z")
72 assert "T" in ts
73
74 def test_timestamp_is_utc(self):
75 import datetime
76 ts = self._call()["timestamp"]
77 # Must parse without error
78 datetime.datetime.fromisoformat(ts.replace("Z", "+00:00"))
79
80 def test_duration_ms_increases_with_time(self):
81 from muse.core.envelope import make_envelope
82 elapsed = start_timer()
83 time.sleep(0.01)
84 ms = make_envelope(elapsed)["duration_ms"]
85 assert ms >= 10.0
86
87 def test_no_schema_version_key(self):
88 """The old name must not appear in the envelope."""
89 assert "schema_version" not in self._call()
File History 2 commits
sha256:b636f72dcba9e190afb980bece906fa5b717fbde014b76ef023df8cb96e01eb9 docs: expand cache plan with all seven testing tiers and do… Sonnet 4.6 131 days ago
sha256:7f9e2ef5286aedad9c1e6011b4c46ca27f39dbdad6e3409357e36b26e46b3b7c docs: docstring sprint for-each-ref→hotspots — idiomatic ru… Sonnet 4.6 patch 138 days ago