Skip to content

test: reach 99.9% coverage for nodates feature - #278

Merged
ChrisMarsden833 merged 7 commits into
nodatesfrom
fix/pr-205-coverage
Aug 11, 2026
Merged

test: reach 99.9% coverage for nodates feature#278
ChrisMarsden833 merged 7 commits into
nodatesfrom
fix/pr-205-coverage

Conversation

@RussellSB

@RussellSB RussellSB commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

Improves test coverage from 95% to 99.9% by adding integration tests for previously uncovered lines in PR #205. Also removes one unreachable dead code guard added defensively in PR #205.

Commits

  1. test: add coverage tests for remaining uncovered lines — 7 new integration tests covering 14 of 16 previously uncovered lines
  2. refactor: remove unreachable guard in abrupt_shaving — removes dead code at line 93 (integer index boundary guard that never triggers)
  3. revert: restore original artifact_cleanup.py formatting — reverts cosmetic changes that were accidentally included
  4. test: use explicit segment values in coverage tests — hardcoded expected values instead of referencing results.segments[0]
  5. test: add direct plot_pytrendy tests for prev fill and next noise fill branches — 5 new tests calling plot_pytrendy directly with crafted segments to exercise lines 172-178, 182, 210-216

What was covered

File Lines Test Approach
detect_trends.py :40 test_integer_date_col_returns_integer Pass integer column as date_col
plot_pytrendy.py :172-176, 182 test_string_prev_fill_direct plot_pytrendy with string index, crafted Flat→Up with invalid displacement
plot_pytrendy.py :177-178 test_integer_prev_fill_direct Same pattern, integer index
plot_pytrendy.py :211 test_date_next_noise_fill_direct plot_pytrendy with date index, crafted Down→Noise with invalid displacement
plot_pytrendy.py :213-214 test_string_next_noise_fill_direct Same pattern, string index
plot_pytrendy.py :215-216 test_integer_next_noise_fill_direct Same pattern, integer index

What was removed

File Line What Why removed
abrupt_shaving.py :93 continue for out-of-range bounds Dead code added defensively in PR #205. The pipeline never produces abrupt segments at df.index[0]. On develop, the equivalent datetime path has no guard and works fine. See commit 8afd742.

Remaining uncovered (1 line)

File Line What Status
artifact_cleanup.py :115 has_partial_overlap_prev trend-after-flat branch Pre-existing dead code from Copilot PR #46, never triggered by any test data. Tracked in #279.

Notes

  • All tests are integration tests through detect_trends or the public plot_pytrendy API

  • No internal functions called directly

  • test_coverage.py naming follows Chris's existing convention. TODO: move direct plot tests to tests_plotting/edgecases/ when restructuring.

  • Note on direct plot tests (TestPlotPrevFillDirect, TestPlotNextNoiseFillDirect): the hand-crafted segment lists are a bit contrived — they force specific displacement conditions that don't occur naturally in the existing datasets. They serve to reach the previously uncovered branches in plot_pytrendy. A TODO is left in the test file to redo these with more realistic synthetic scenarios when a natural dataset produces these patterns.

Related issues

Add integration tests targeting the 16 previously uncovered lines:
- detect_trends:40 — integer date_col path
- plot_pytrendy:172-178,182 — prev fill (string + integer branches)
- plot_pytrendy:210-216 — next noise fill (string + integer + date branches)
- abrupt_shaving:93 and artifact_cleanup:115 tested via detect_trends inputs

Coverage improved from 16 to 2 missed lines (99% -> 99.8%).
plot_pytrendy.py now at 100%.
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The out-of-range guard at line 93 (new_start < df.index[0]) was added
in PR #205 when the index logic changed from datetime to generic.
However, the pipeline never produces abrupt segments at df.index[0]
(the Savitzky-Golay window requirement prevents it), making this
dead code. On develop, the equivalent datetime path has no guard
and works fine.
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

📚 Docs preview removed

The docs preview for this PR has been cleaned up.

github-actions Bot added a commit that referenced this pull request Aug 4, 2026
@RussellSB RussellSB changed the title test: reach 99.8% coverage for nodates feature test: reach 99.9% coverage for nodates feature Aug 4, 2026
Comment thread pytrendy/post_processing/segments_refine/abrupt_shaving.py
@RussellSB
RussellSB marked this pull request as draft August 4, 2026 18:31
@RussellSB
RussellSB removed the request for review from ChrisMarsden833 August 4, 2026 18:31
…_cleanup

The nodates branch reindexes DataFrames to contiguous integers
before the pipeline runs. All segments store integer positions.
But artifact_cleanup.py still used pd.to_datetime(), .strftime(),
and pd.Timedelta() — leftover from the old datetime code.

Replaced all datetime operations with plain integer arithmetic
(+1, -1) matching the pattern used by abrupt_shaving, expand_contract,
and update_neighbours. Also updated fill_in_flats to store integer
values directly instead of formatting as date strings.
github-actions Bot added a commit that referenced this pull request Aug 5, 2026
Revert cosmetic changes (dict syntax, whitespace, docstring) that
were accidentally included in the previous commit. The functional
code is identical to origin/nodates.
github-actions Bot added a commit that referenced this pull request Aug 5, 2026
github-actions Bot added a commit that referenced this pull request Aug 5, 2026
@RussellSB
RussellSB marked this pull request as ready for review August 5, 2026 07:32
…l branches

Add tests that call plot_pytrendy directly with crafted segments to
exercise the prev fill (lines 172-178, 182) and next noise fill
(lines 210-216) branches. Uses custom data with dip/spike patterns
to trigger invalid displacement conditions.

Coverage: plot_pytrendy.py 92% -> 100%, total 99.9% (1 line remaining)

TODO: move tests to tests_plotting/edgecases/ when restructuring.
github-actions Bot added a commit that referenced this pull request Aug 5, 2026
…t tests

- Rename TestPlotPrevFill -> TestPrevFill, TestPlotNextNoiseFill ->
  TestNextNoiseFill (they assert segments via detect_trends, not plots)
- Convert 5 direct plot tests to @pytest.mark.mpl_image_compare with
  baseline PNGs saved to tests/tests_plotting/edgecases/
- Tests call detect_trends then craft segments to trigger the prev fill
  and next noise fill branches in plot_pytrendy (lines 172-178, 182, 210-216)
- TODO left to redo with more realistic synthetic scenarios later

plot_pytrendy.py now at 100% coverage; total 99% (1 line remaining:
artifact_cleanup:115, pre-existing dead code tracked in #279)
github-actions Bot added a commit that referenced this pull request Aug 5, 2026
@ChrisMarsden833
ChrisMarsden833 merged commit 77e35f7 into nodates Aug 11, 2026
7 checks passed
@ChrisMarsden833
ChrisMarsden833 deleted the fix/pr-205-coverage branch August 11, 2026 08:54
github-actions Bot added a commit that referenced this pull request Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants