gabriel / muse public
test_fetch_envelope.py python
59 lines 1.9 KB
Raw
sha256:b636f72dcba9e190afb980bece906fa5b717fbde014b76ef023df8cb96e01eb9 docs: expand cache plan with all seven testing tiers and do… Sonnet 4.6 131 days ago
1 """Envelope tests for fetch command."""
2 from __future__ import annotations
3 from collections.abc import Mapping
4 import json
5 import pytest
6 from tests.cli_test_helper import CliRunner
7
8 runner = CliRunner()
9
10 _FIELDS = ("muse_version", "schema", "timestamp", "warnings")
11
12
13 def _check(d: Mapping[str, object]) -> None:
14 for f in _FIELDS:
15 assert f in d, f"missing {f}"
16 assert "schema_version" not in d
17
18
19 class TestFetchEnvelope:
20 def test_fetch_no_remote_has_envelope(self):
21 # fetch with an unconfigured remote exits non-zero but still emits JSON envelope
22 r = runner.invoke(None, ["fetch", "nonexistent_remote_xyz", "--json"])
23 assert r.exit_code != 0
24 # runner captures stdout + stderr; first line is the JSON envelope
25 _check(json.loads(r.output.splitlines()[0]))
26
27
28 # ---------------------------------------------------------------------------
29 # TestRegisterFlags — argparse-level verification
30 # ---------------------------------------------------------------------------
31
32
33 class TestRegisterFlags:
34 """Verify that register() wires --json / -j correctly."""
35
36 def _make_parser(self):
37 import argparse
38 from muse.cli.commands.fetch import register
39 ap = argparse.ArgumentParser()
40 subs = ap.add_subparsers()
41 register(subs)
42 return ap
43
44 def test_json_flag_long(self):
45 ns = self._make_parser().parse_args(["fetch", "--json"])
46 assert ns.json_out is True
47
48 def test_j_alias(self):
49 ns = self._make_parser().parse_args(["fetch", "-j"])
50 assert ns.json_out is True
51
52 def test_default_is_text(self):
53 ns = self._make_parser().parse_args(["fetch"])
54 assert ns.json_out is False
55
56 def test_dest_is_json_out(self):
57 ns = self._make_parser().parse_args(["fetch", "-j"])
58 assert hasattr(ns, "json_out")
59 assert not hasattr(ns, "fmt")
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 137 days ago