Skip to content

Commit 75d61ad

Browse files
sunasrd-byteclaude
andcommitted
test: pin clock in test_cli_output.py credit tests
The credit tests compared absolute fixture dates against the real clock, so they broke once those dates passed — nine failed at a 2040 clock. Patch cli_output.status.datetime with a datetime subclass whose now() returns a fixed instant, so the assertions no longer depend on when the suite runs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 15961c3 commit 75d61ad

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tests/test_cli_output.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit tests for cli_output module."""
22

3+
from datetime import datetime, timezone
34
from unittest.mock import Mock, patch
45

56
from cli_output.status import (
@@ -10,6 +11,14 @@
1011
print_status,
1112
)
1213

14+
FROZEN_NOW = datetime(2025, 6, 15, 12, 0, tzinfo=timezone.utc)
15+
16+
17+
class FrozenDatetime(datetime):
18+
@classmethod
19+
def now(cls, tz=None):
20+
return FROZEN_NOW if tz is None else FROZEN_NOW.astimezone(tz)
21+
1322

1423
class TestProgressBar:
1524
"""Tests for _create_progress_bar function."""
@@ -52,6 +61,7 @@ def test_custom_width(self):
5261
assert bar == "█" * 5 + "░" * 5
5362

5463

64+
@patch("cli_output.status.datetime", FrozenDatetime)
5565
class TestDisplayCreditLine:
5666
"""Tests for _display_credit_line function."""
5767

@@ -132,6 +142,7 @@ def test_timezone_naive_datetime(self, mock_console):
132142
mock_console.print.assert_called_once()
133143

134144

145+
@patch("cli_output.status.datetime", FrozenDatetime)
135146
class TestDisplayBucketCreditLine:
136147
"""Tests for _display_bucket_credit_line function."""
137148

@@ -192,6 +203,7 @@ def test_timezone_naive_datetime(self, mock_console):
192203
mock_console.print.assert_called_once()
193204

194205

206+
@patch("cli_output.status.datetime", FrozenDatetime)
195207
class TestDisplayStatusMessage:
196208
"""Tests for _display_status_message function."""
197209

@@ -271,6 +283,7 @@ def test_null_plan_credits_and_empty_purchased(self, mock_console):
271283
assert "No rendering credits remaining" in call_args
272284

273285

286+
@patch("cli_output.status.datetime", FrozenDatetime)
274287
class TestPrintStatus:
275288
"""Tests for print_status function."""
276289

0 commit comments

Comments
 (0)