Conversation
Add a TestParseTokenInt class in test_models.py that directly tests the
public parse_token_int() function with all documented contract cases:
- bool inputs (True/False) return None
- str inputs ('42', 'abc', '') return None
- non-whole floats (3.14, 0.5, -1.5, 1.999) return None
- zero/negative ints (0, -1, -100000) return None
- zero/negative floats (0.0, -1.0, -100.0) return None
- unsupported types (None, dict, list, object) return None
- positive int returned as-is
- positive whole float coerced to int
- large positive int returned unchanged
- return type verified as int (not float)
Closes #886
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds dedicated unit tests to directly validate the public parse_token_int() contract, reducing regression risk from refactors that might subtly change type-guard behavior (notably bool vs int).
Changes:
- Import
parse_token_intintotests/copilot_usage/test_models.py. - Add
TestParseTokenIntcovering invalid inputs (returnNone) and valid inputs (return positiveint, including whole-float coercion). - Assert return type behavior to ensure whole-number floats produce
int(notfloat).
Contributor
There was a problem hiding this comment.
Low-impact test-only addition with good coverage. Adds direct unit tests for parse_token_int() covering all input categories (bool, str, non-whole float, zero/negative, unsupported types, and valid positive values). Well-structured, follows existing patterns and coding guidelines. Auto-approving for merge.
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
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.
Closes #886
Summary
Adds a
TestParseTokenIntclass intests/copilot_usage/test_models.pythat directly tests the publicparse_token_int()function against its documented contract, covering all input categories:Invalid inputs →
NoneTrue/False(bool is a subclass of int — guard order matters)"42","abc",""(no string coercion)3.14,0.5,-1.5,1.9990,-1,-100_0000.0,-1.0,-100.0None,{},[],object()Valid inputs → positive
int42 → 42)1234.0 → 1234)1_000_000)int, notfloatRegression risk addressed
Previously, all
parse_token_intcoverage was indirect (through_extract_output_tokens). A refactor that swapped theisinstance(raw, bool)guard order would silently break the contract — these direct tests catch that.