forked from simplistix/testfixtures
-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor date/time mocks to explicit signatures #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cjw296
wants to merge
91
commits into
datetime-reimplement
Choose a base branch
from
codex/redesign-mock_datetime-with-explicit-signatures
base: datetime-reimplement
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor date/time mocks to explicit signatures #5
cjw296
wants to merge
91
commits into
datetime-reimplement
from
codex/redesign-mock_datetime-with-explicit-signatures
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…astructure - Add basic Queue, MockedCurrent, and MockDateTime classes with modern typing - Implement minimal mock_datetime() factory function - First test_now passes with proper mypy compliance - Export mock_datetime from testfixtures.__init__.py 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…one support - Add timezone helper classes (SampleTZInfo, SampleTZInfo2, WeirdTZInfo) with proper typing - Implement timezone offset handling in MockDateTime.now() method - Second test passes: datetime.now(tz) correctly applies timezone offset - Both tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock_datetime(tzinfo=SampleTZInfo()) configuration - Test passes with existing timezone handling in MockDateTime.now() - All three tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add _adjust_instance_using_tzinfo method to handle mock's configured timezone - Implement proper error handling for timezone with None utcoffset - Test correctly raises TypeError when calling now(tz=...) on mock with WeirdTZInfo - All four tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Simplify mock_factory to use cls.add(*args, **kw) like the original - Implement basic add() method in MockedCurrent class - Remove complex manual datetime construction logic - All existing tests still pass with cleaner, more maintainable code 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mixed timezone scenarios: mock configured with one timezone, now() called with different timezone - Test passes with existing timezone handling logic - All five tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for timezone scenario where mock and now() call use same timezone - Test passes with existing timezone handling logic (adjustments cancel out) - All six tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…zone extraction - Add support for passing datetime instances with timezone to mock_datetime() - Implement timezone extraction and datetime timezone stripping in add() method - Mock extracts tzinfo and stores timezone-naive datetime in queue - All seven tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test combining timezone instance creation with supplied timezone to now() call - Test passes with existing timezone handling logic - All eight tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…plied) - Add test for timezone instance creation with same timezone supplied to now() - Test passes with existing timezone handling logic - All nine tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock_datetime with explicit datetime parameters (2002, 1, 1, 1, 2, 3) - Test passes with existing parameter handling in mock_factory - All ten tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock_datetime(None) with manual add() calls to build sequence - Import MockDateTime for type annotations - Test passes with existing add() method and queue handling - All eleven tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add set() method to MockedCurrent class that clears queue and adds new datetime - Test validates set() clears previous add() calls and starts new progression - All twelve tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…timezone validation - Add timezone compatibility check in add() method - Validate that added datetime's tzinfo matches mock's configured tzinfo - Raise ValueError with descriptive message for tzinfo mismatches - All thirteen tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for passing datetime instance directly to mock_datetime() - Test passes with existing datetime instance handling - All fourteen tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…plied) - Add test for automatic delta progression when queue is exhausted - Test validates Queue.next() automatically generates new values with delta increments - All fifteen tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
… strict mode - Add __new__ method to MockedCurrent for constructor behavior control - When strict=True, mock class constructor returns mock instances - When strict=False, returns base datetime class instances - All sixteen tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…() method - Add date() method to MockDateTime that returns proper date type - Initialize _mock_date_type with proper default handling - Test validates datetime.date() returns correct date class instance - All seventeen tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for manual replacer usage with mock datetime instances - Import sample1 module for test dependencies - Test passes with existing mock functionality - All eighteen tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock class repr() representation - Test validates replaced datetime class shows MockDateTime name - All nineteen tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for custom delta=1 parameter (1 second increments) - Test validates delta progression: 0, 1, 2 seconds - All twenty tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for delta_type='minutes' parameter - Test validates minute-based progression: 0, 10, 30 minutes - All twenty-one tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for set() method with mock_datetime(None) - Fix mypy error by using separate variable for cast instead of reassigning datetime - Test validates set() clears queue and establishes new progression - All twenty-two tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for set() method with datetime instances and timezone validation - Test validates set() accepts datetime instances and enforces timezone constraints - All twenty-three tests pass with full mypy compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
… modern typing Fixed add() method to properly handle keyword arguments (year=, month=, day=) when creating datetime instances. Uses type-safe checks to ensure kwargs are int before using them for datetime construction. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Test verifies that set() method works properly with keyword arguments only. Uses modern type annotations with proper return type annotation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…typing Implemented validation to raise TypeError when tzinfo is passed as keyword argument to add() or set() methods, maintaining API compatibility with original implementation. Uses modern type annotations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…rgs for MockTime 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…test_kw_tzinfo for MockTime 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…mport 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This reverts commit d71a0e9.
- Queue[T] where T is bound to datetime < /dev/null | date - MockDateTime uses Queue[datetime] - MockDate uses Queue[date] - MockTime uses Queue[datetime] - Removed cast() calls from now(), utcnow(), today(), and MockTime.__new__() - Uses modern Python 3.11+ syntax with TypeVar bound to union type 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- MockedCurrent[T] where T is bound to datetime < /dev/null | date - MockDateTime extends MockedCurrent[datetime] - MockDate extends MockedCurrent[date] - MockTime extends MockedCurrent[datetime] - Updated mock_factory to be generic - Removed 5 type: ignore comments by improving type annotations - Improved _correct_mock_type methods with better casting Note: One test_isinstance_strict test currently failing - needs strict mode fix 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Prefer type-ignores instead
The return type annotation in MockedCurrent.__add__ method no longer needs a type ignore comment as the generic type constraints properly handle the return value. Reduced type ignore count from 18 to 17 without introducing any casts or changing the external API. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1157e2c to
f443e5a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
mock_datetime,mock_dateandmock_timefunctions with explicitparameter signatures
defaults
Testing
mypy testfixturespytest -qhttps://chatgpt.com/codex/tasks/task_e_68661928d2a08321b3abe40b0223902c