From 000d9f778d9b04c1d723b3f507ff30d6c0676b4a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 14:10:06 +0000 Subject: [PATCH] Date the preview fixtures in the report tests report.read_bodies dates a preview body by its file time. A checkout sets that time to the moment of the checkout, so PreviewTest.test_preview_report_keeps_unknown_spend_null and PreviewKindsTest.test_kinds_and_account_gaps passed only on a checkout made on 2026-10-22, and CI has failed on main since 2026-10-23. The two test classes now read a temporary copy of their fixture folder, with every file dated NOW, as a run writes its bodies on its own day. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LrwmG7tGPk6tcvdrGCkfzU Signed-off-by: Claude --- tests/test_report.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/test_report.py b/tests/test_report.py index 12057f6..ba21fd4 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -1,6 +1,7 @@ import io import json import os +import shutil import tempfile import unittest from unittest import mock @@ -174,8 +175,27 @@ def test_main_exits_2_when_short_and_writes_json(self): self.assertEqual(len(json.load(f)), 3) +def dated_bodies(test_class, name): + """Copy fixtures/NAME to a temporary folder with every file dated NOW. + + read_bodies dates a preview body by its file time, and a checkout sets + that to the time of the checkout. A run writes its bodies on its own day. + """ + folder = tempfile.mkdtemp() + test_class.addClassCleanup(shutil.rmtree, folder) + copy = os.path.join(folder, name) + shutil.copytree(os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", name), copy) + stamp = NOW.timestamp() + for root, _, files in os.walk(copy): + for f in files: + os.utime(os.path.join(root, f), (stamp, stamp)) + return copy + + class PreviewTest(unittest.TestCase): - BODIES = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "bodies") + @classmethod + def setUpClass(cls): + cls.BODIES = dated_bodies(cls, "bodies") def test_read_bodies(self): nodes, comments, notes, problems = report.read_bodies(self.BODIES) @@ -225,7 +245,9 @@ def test_known_and_unknown_spend(self): class PreviewKindsTest(unittest.TestCase): - BODIES = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "bodies2") + @classmethod + def setUpClass(cls): + cls.BODIES = dated_bodies(cls, "bodies2") def read(self, scope=frozenset({"acme"})): return report.read_bodies(self.BODIES, scope)