Skip to content

test(models): add dedicated TestParseTokenInt unit tests (#886)#888

Merged
microsasa merged 1 commit intomainfrom
add-parse-token-int-tests-886-52ef5a62307a15e4
Apr 9, 2026
Merged

test(models): add dedicated TestParseTokenInt unit tests (#886)#888
microsasa merged 1 commit intomainfrom
add-parse-token-int-tests-886-52ef5a62307a15e4

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #886

Summary

Adds a TestParseTokenInt class in tests/copilot_usage/test_models.py that directly tests the public parse_token_int() function against its documented contract, covering all input categories:

Invalid inputs → None

  • bool: True / False (bool is a subclass of int — guard order matters)
  • str: "42", "abc", "" (no string coercion)
  • non-whole float: 3.14, 0.5, -1.5, 1.999
  • zero/negative int: 0, -1, -100_000
  • zero/negative float: 0.0, -1.0, -100.0
  • other types: None, {}, [], object()

Valid inputs → positive int

  • Positive int returned as-is (42 → 42)
  • Positive whole float coerced to int (1234.0 → 1234)
  • Large positive int (1_000_000)
  • Return type verified as int, not float

Regression risk addressed

Previously, all parse_token_int coverage was indirect (through _extract_output_tokens). A refactor that swapped the isinstance(raw, bool) guard order would silently break the contract — these direct tests catch that.

Generated by Issue Implementer · ● 4.1M ·

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>
Copilot AI review requested due to automatic review settings April 9, 2026 15:39
@microsasa microsasa added the aw Created by agentic workflow label Apr 9, 2026
@microsasa microsasa enabled auto-merge April 9, 2026 15:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_int into tests/copilot_usage/test_models.py.
  • Add TestParseTokenInt covering invalid inputs (return None) and valid inputs (return positive int, including whole-float coercion).
  • Assert return type behavior to ensure whole-number floats produce int (not float).

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@microsasa microsasa merged commit 065a617 into main Apr 9, 2026
8 checks passed
@microsasa microsasa deleted the add-parse-token-int-tests-886-52ef5a62307a15e4 branch April 9, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow aw-quality-gate-approved Quality gate approved the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][test audit] models.py: parse_token_int has no dedicated unit tests despite being a public API function

2 participants