test: cover untested branches in render_detail.py (#1058)#1060
Merged
test: cover untested branches in render_detail.py (#1058)#1060
Conversation
Add tests for three untested code paths:
- TestBuildEventDetailsSessionShutdown: SESSION_SHUTDOWN arm of
_build_event_details with non-empty type, empty type, and malformed
data sub-cases
- TestRenderShutdownCyclesNoneTimestamp: ts=None path in
_render_shutdown_cycles renders '—' in Date column
- test_truncate_non_positive_max_len_returns_empty: parametrized test
for _truncate max_len <= 0 guard with values {0, -1, -100}
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds targeted unit tests to increase branch coverage for private helpers in src/copilot_usage/render_detail.py, addressing gaps identified in issue #1058 without modifying production code.
Changes:
- Adds tests for
_build_event_details()handling ofEventType.SESSION_SHUTDOWN(including empty/non-empty shutdown types). - Adds a test covering
_render_shutdown_cycles()when a shutdown cycle timestamp isNone(renders"—"). - Adds a parametrized test covering
_truncate()’smax_len <= 0guard.
Replace inline (StringIO, Console) setup with existing _buf_console() helper in TestRenderShutdownCyclesNoneTimestamp to reduce duplication and keep console configuration consistent across tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Commit pushed:
|
Replace inline StringIO/Console setup in TestRenderCodeChanges with the existing _buf_console() helper to keep console configuration consistent across tests and reduce duplication. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Commit pushed:
|
Contributor
There was a problem hiding this comment.
Quality Gate: APPROVE ✅
Low-impact, test-only PR adding coverage for three previously untested branches in render_detail.py:
_build_event_detailsSESSION_SHUTDOWN arm_render_shutdown_cycleswithts=None_truncatewithmax_len ≤ 0
Also refactors 5 existing tests to consistently use the _buf_console() helper. All 9 CI checks pass. No source changes. 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 #1058
Adds direct test coverage for three untested branches in
src/copilot_usage/render_detail.py:Gap 1 —
_build_event_details: SESSION_SHUTDOWN armNew
TestBuildEventDetailsSessionShutdownclass with three tests:test_non_empty_shutdown_type— verifies"type=routine"outputtest_empty_shutdown_type— verifies empty string outputtest_malformed_data_returns_empty— intshutdownTypetriggersValidationError→""Gap 2 —
_render_shutdown_cycles:ts=NonepathNew
TestRenderShutdownCyclesNoneTimestampclass:test_none_timestamp_renders_dash—(None, sd)tuple renders"—"in Date columnGap 3 —
_truncate:max_len ≤ 0guardParametrized test covering
max_len ∈ {0, -1, -100}:test_truncate_non_positive_max_len_returns_empty— all return""Notes
make checklocally (network-blocked sandbox;uvnot available), but CI will validateWarning
The following domains were blocked by the firewall during workflow execution:
astral.shpypi.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.