-
-
Notifications
You must be signed in to change notification settings - Fork 211
Enh/custom warning no motor parachute aerosurface #871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Enh/custom warning no motor parachute aerosurface #871
Conversation
| """Tests the _check_missing_components method for a complete Rocket.""" | ||
| # Call directly — no warnings expected | ||
| calisto_robust._check_missing_components() | ||
| # If any warning occurs, pytest will fail automatically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure?
# If any warning occurs, pytest will fail automatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review!You're correct.By default, pytest only displays warnings but doesn't fail.I will updated the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changelog seems weird @phmbressan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback. Could you please clarify which part of the changelog seems weird? I want to make sure my addition follows the proper format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your added line is listed along together other changes that have already been deployed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changelog seems weird @phmbressan
I can double-check later, but this branch might not be up to date with develop (v1.11), which is why the CHANGELOG seems outdated. Could you @C8H10O2 try rebasing this branch with the current develop so that all conflicts are sorted out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changelog seems weird @phmbressan
I can double-check later, but this branch might not be up to date with develop (v1.11), which is why the CHANGELOG seems outdated. Could you @C8H10O2 try rebasing this branch with the current develop so that all conflicts are sorted out?
Understood, I’ll take care of it. Thanks for pointing it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a rocket without parachute is something quite common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up on issue #285 and your comment:
I wanted to clarify: for rockets without parachutes, should the custom warning be changed to a notice/info message instead, or should it only trigger under specific conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should never raise an warning for "parachuteless rockets", so to say
Added a placeholder in the [Unreleased] section for the upcoming feature to add custom warnings when a rocket is missing motors and/or aero-surface. See RocketPy-Team#285.
This enhancement adds a warning when a Rocket object has no motors, parachutes, or AeroSurface components. It notifies the user so that they can add missing components before running simulations. See RocketPy-Team#285
Only warn if motor or aerodynamic surfaces are missing. Never raise a warning for no parachute. See RocketPy-Team#285
016acae to
1d75f80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds unit tests for the new _check_missing_components() method in the Rocket class, which verifies whether a rocket has essential components (motor and aerodynamic surfaces) and issues warnings when components are missing.
- Adds
_check_missing_components()method to detect missing rocket components - Implements three unit tests covering all scenarios: all components missing, some missing, and none missing
- Updates CHANGELOG to document the enhancement
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| rocketpy/rocket/rocket.py | Adds _check_missing_components() method to warn users about missing motor or aerodynamic surfaces |
| tests/unit/rocket/test_rocket.py | Adds three unit tests to verify warning behavior for different component configurations |
| CHANGELOG.md | Documents the custom exception errors and messages enhancement |
| missing_components = [] | ||
| if isinstance(self.motor, EmptyMotor): | ||
| missing_components.append("motor") | ||
| if not self.aerodynamic_surfaces or len(self.aerodynamic_surfaces) == 0: |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition not self.aerodynamic_surfaces already covers empty lists, making the explicit len(self.aerodynamic_surfaces) == 0 check redundant. Simplify to just if not self.aerodynamic_surfaces:.
| if not self.aerodynamic_surfaces or len(self.aerodynamic_surfaces) == 0: | |
| if not self.aerodynamic_surfaces: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
| Notes: | ||
| - The warning uses Python's built-in `warnings.warn` function. |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring is missing a 'Returns' section. According to NumPy docstring format, if a method doesn't return anything, it should include 'Returns\n-------\nNone' to be explicit. This aligns with RocketPy's requirement for comprehensive NumPy-style docstrings.
| Notes: | |
| - The warning uses Python's built-in `warnings.warn` function. | |
| Notes | |
| ----- | |
| - The warning uses Python's built-in `warnings.warn` function. | |
| Returns | |
| ------- | |
| None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
| if missing_components: | ||
| component_list = ", ".join(missing_components) | ||
| warnings.warn( | ||
| f"[WARNING] Rocket has no {component_list} defined.", UserWarning |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The '[WARNING]' prefix in the warning message is redundant since warnings.warn() already identifies messages as warnings. Remove the prefix to avoid duplication: f'Rocket has no {component_list} defined.'
| f"[WARNING] Rocket has no {component_list} defined.", UserWarning | |
| f"Rocket has no {component_list} defined.", UserWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
|
|
||
| def test_check_missing_some_components(calisto): | ||
| """Tests the _check_missing_components method for a Rocket missing some components.""" | ||
| calisto.parachutes = [] |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test modifies calisto.parachutes = [] on line 388, but the _check_missing_components() method doesn't check for parachutes—only motor and aerodynamic surfaces. This modification is unnecessary and may confuse future maintainers about what the method actually validates. Remove line 388.
| calisto.parachutes = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
|
@Bizo883 please address all the comments, fix tests and linters. You can let me know when the PR is ready for review again |
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior
There is no test for the _check_missing_components().
New behavior
This PR adds unit tests to verify the warning behavior of the
_check_missing_components()method.Specifically, it includes three test cases:
These tests are defined in
tests/unit/test_rocket.py.Breaking change