|
3 | 3 | import json |
4 | 4 | import tempfile |
5 | 5 | import unittest |
| 6 | +from contextlib import redirect_stdout |
| 7 | +from io import StringIO |
6 | 8 | from pathlib import Path |
7 | 9 |
|
| 10 | +from packslice.cli import main as cli_main |
8 | 11 | from packslice.report import markdown_splits, summarize_splits |
9 | 12 | from packslice.splitter import split_pack |
10 | 13 |
|
@@ -138,6 +141,35 @@ def test_chronological_split_keeps_ordered_groups(self): |
138 | 141 | ["assert-b", "billing-b"], |
139 | 142 | ) |
140 | 143 |
|
| 144 | + def test_split_cli_can_emit_json(self): |
| 145 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 146 | + root = Path(tmpdir) / "sample_pack" |
| 147 | + root.mkdir() |
| 148 | + self._write_pack(root) |
| 149 | + out = Path(tmpdir) / "splits" |
| 150 | + output = StringIO() |
| 151 | + with redirect_stdout(output): |
| 152 | + code = cli_main(["split", str(root), str(out), "--group-by", "signature", "--json"]) |
| 153 | + payload = json.loads(output.getvalue()) |
| 154 | + self.assertEqual(code, 0) |
| 155 | + self.assertEqual(payload["total_cases"], 6) |
| 156 | + self.assertEqual(payload["splits"][0]["name"], "train") |
| 157 | + |
| 158 | + def test_summarize_cli_can_emit_json(self): |
| 159 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 160 | + root = Path(tmpdir) / "sample_pack" |
| 161 | + root.mkdir() |
| 162 | + self._write_pack(root) |
| 163 | + out = Path(tmpdir) / "splits" |
| 164 | + split_pack(root, out, ratios=(2, 1, 1)) |
| 165 | + output = StringIO() |
| 166 | + with redirect_stdout(output): |
| 167 | + code = cli_main(["summarize", str(out), "--json"]) |
| 168 | + payload = json.loads(output.getvalue()) |
| 169 | + self.assertEqual(code, 0) |
| 170 | + self.assertEqual(payload["group_by"], "signature") |
| 171 | + self.assertEqual(payload["total_cases"], 6) |
| 172 | + |
141 | 173 |
|
142 | 174 | if __name__ == "__main__": |
143 | 175 | unittest.main() |
0 commit comments