mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-04 13:07:32 +00:00
fix(tools): report deeply nested progress snapshots as usage errors
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
3a2b919816
commit
df4aee248b
2 files changed
+17
-1
No files matched your search
+1
-1
@@ -585,7 +585,7 @@ def main(argv=None):
|
||||
for path in args.compare:
|
||||
try:
|
||||
snapshots.append(json.loads(path.read_text(encoding="utf-8-sig")))
|
||||
except (OSError, ValueError) as error:
|
||||
except (OSError, ValueError, RecursionError) as error:
|
||||
parser.error(f"{path}: {error}")
|
||||
for path, snapshot in zip(args.compare, snapshots):
|
||||
try:
|
||||
|
||||
@@ -59,6 +59,22 @@ class ProgressSnapshotTests(unittest.TestCase):
|
||||
self.assertIn(message, stderr.getvalue())
|
||||
self.assertNotIn("Traceback", stderr.getvalue())
|
||||
|
||||
def test_deeply_nested_snapshots_are_usage_errors(self):
|
||||
for position in (0, 1):
|
||||
with self.subTest(position=position), tempfile.TemporaryDirectory() as directory:
|
||||
paths = [Path(directory) / "base snapshot.json", Path(directory) / "head snapshot.json"]
|
||||
for path in paths:
|
||||
path.write_text(json.dumps(self.snapshot()), encoding="utf-8")
|
||||
paths[position].write_text("[" * 100000 + "]" * 100000, encoding="utf-8")
|
||||
stdout, stderr = io.StringIO(), io.StringIO()
|
||||
with patch("sys.stdout", stdout), patch("sys.stderr", stderr):
|
||||
with self.assertRaises(SystemExit) as raised:
|
||||
progress.main(["--compare", *map(str, paths)])
|
||||
self.assertEqual(raised.exception.code, 2)
|
||||
self.assertEqual(stdout.getvalue(), "")
|
||||
self.assertIn(str(paths[position]), stderr.getvalue())
|
||||
self.assertIn("recursion", stderr.getvalue())
|
||||
|
||||
def test_non_object_snapshots_are_usage_errors(self):
|
||||
for snapshot in (None, [], "progress", 7, True):
|
||||
with self.subTest(snapshot=snapshot):
|
||||
|
||||
Reference in new issue
Block a user