Skip to content

TST: cover the rocket and Monte Carlo plot branches - #1178

Draft
ting-hong-shieh wants to merge 1 commit into
RocketPy-Team:developfrom
ting-hong-shieh:tst/rocket-and-monte-carlo-plots
Draft

TST: cover the rocket and Monte Carlo plot branches#1178
ting-hong-shieh wants to merge 1 commit into
RocketPy-Team:developfrom
ting-hong-shieh:tst/rocket-and-monte-carlo-plots

Conversation

@ting-hong-shieh

Copy link
Copy Markdown

TST: cover the rocket and Monte Carlo plot branches

Works toward #709.

Why these two modules

At 4263fa95d7fe6f63d9593f01e4ff7a088369e195, plots/rocket_plots.py measures 73.9% and plots/monte_carlo_plots.py 85.1% in the run that gates every pull request. Neither is untested; the fixtures simply never reach several branches.

Rocket.draw dispatches per component type, and the test rockets only ever carry a nose cone, a tail and a fin set on a solid motor. So the branches for an individual Fin, for a GenericSurface, for hybrid and liquid motors, for a ring cluster, and for a nozzle that sits behind the last aerodynamic surface were never entered.

The ellipse plots read their series out of results with try/except KeyError, so the warning paths only run when a results file is missing a series — which no fixture produces.

What this adds

Two test-only files. No production code changes.

tests/unit/rocket/test_rocket_plots.py, 15 cases:

Case Branch it reaches
a rocket carrying one Fin, three fin classes × two planes _draw_fin, which rotates a single fin out of its own frame rather than a set
a rocket carrying a GenericSurface, two planes _draw_generic_surface, the only branch that reads position by index
a hybrid motor the HybridMotor arm of _generate_motor_patches
a liquid motor the LiquidMotor arm
a ring cluster the loop that strips the legend from every grain but the first
a nozzle behind the last surface, both coordinate systems both arms of _draw_nozzle_tube
no aerodynamic surfaces, and an undefined plane the two refusals in __validate_aerodynamic_surfaces

tests/unit/simulation/test_monte_carlo_plots.py, 8 cases: results missing their apogee series, missing their impact series, missing both, an image path that does not exist, and an image drawn together with actual_landing_point — for both ellipses and ellipses_comparison.

Background-map fetching stays where it already lives, in test_monte_carlo_plots_background.py. Everything added here passes background=None and contacts no tile provider.

Effect

Before After
plots/rocket_plots.py 73.8832% (76 missed) 99.3127% (2 missed)
plots/monte_carlo_plots.py 85.0622% (36 missed) 96.6805% (8 missed)
Project, non-slow 84.5781% 85.1600%

That is +102 statements. The unit step goes from 2,185 to 2,208 passing, and no step slows measurably: 133.83s to 134.14s for unit, 89.90s to 89.40s for integration.

Measured by running the five steps of test_pytest.yaml in order — unit, doctests, integration with the three animation deselects, the VTK animation tests, acceptance — each --cov-append, before and after this branch on the same machine with the same script. The baseline agrees with Codecov's figure for the same commit to the statement: 14,824 covered, 2,703 missed, against Codecov's 84.57%.

This branch sits on develop, not on #1176. The two touch disjoint modules — that one moves the EnvironmentAnalysis files, this one moves the two plot files — so the +945 and the +102 add rather than overlap, which would put the pair above the 90% this issue asks for. That is arithmetic on disjoint sets rather than a measured combined run; Codecov will report each against develop on its own.

One thing worth fixing separately

That baseline only agrees once contextily is installed, and make install does not install it. It is declared in the monte-carlo extra in pyproject.toml but not in requirements-optional.txt, which is what the Makefile reads. test_monte_carlo_plots_background.py opens with pytest.importorskip("contextily"), so a contributor following the documented setup silently skips 18 tests and measures 53 statements less than CI reports, with nothing pointing at why. The workflow installs .[all], so CI is unaffected. Raised separately rather than folded in here.

$ ruff check rocketpy/ tests/ && ruff format --check rocketpy/ tests/
All checks passed!

$ pylint tests/unit/rocket/test_rocket_plots.py tests/unit/simulation/test_monte_carlo_plots.py
Your code has been rated at 10.00/10

No CHANGELOG entry: the file asks for tests to be left out.

Measured on Python 3.12.3, Linux.

rocket_plots.py sat at 73.9% and monte_carlo_plots.py at 63.1% because the
fixtures never reached several drawing branches.

For rocket_plots, add drawings for a rocket carrying one individual Fin
rather than a fin set, one carrying a GenericSurface, one on a hybrid
motor, one on a liquid motor, one on a ring cluster, and one whose nozzle
sits behind its last aerodynamic surface in each coordinate system. Add the
two validation refusals.

For monte_carlo_plots, cover the ellipse branches that run when a results
file is missing its apogee or its impact series, when it has neither, when
the image path does not exist, and when a landing point and an image are
drawn. Background-map fetching stays in test_monte_carlo_plots_background.py;
everything added here runs with background=None and contacts no provider.

No production code changes.
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.16%. Comparing base (4263fa9) to head (4d9dd22).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1178      +/-   ##
===========================================
+ Coverage    84.57%   85.16%   +0.58%     
===========================================
  Files          131      131              
  Lines        17527    17527              
===========================================
+ Hits         14824    14926     +102     
+ Misses        2703     2601     -102     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ting-hong-shieh
ting-hong-shieh marked this pull request as draft August 16, 2026 19:10
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.

1 participant