Skip to content

Conversation

@Bizo883
Copy link

@Bizo883 Bizo883 commented Nov 5, 2025

Pull request type

  • Code changes (bugfix, features)
  • Code maintenance (refactoring, formatting, tests)
  • ReadMe, Docs and GitHub updates

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest tests -m slow --runslow) have passed locally
  • CHANGELOG.md has 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:

  1. All components missing → expects a single warning listing all missing elements.
  2. Some components missing → ensures only the absent components appear in the warning message.
  3. No components missing → ensures no warning is issued.

These tests are defined in tests/unit/test_rocket.py.

Breaking change

  • Yes
  • No

@Bizo883 Bizo883 requested a review from a team as a code owner November 5, 2025 15:22
"""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
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

changelog seems weird @phmbressan

Copy link

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.

Copy link
Member

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

Copy link
Collaborator

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?

Copy link

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.

Copy link
Member

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.

Copy link

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:

#285 (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?

Copy link
Member

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

C8H10O2 and others added 5 commits November 15, 2025 00:23
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
@C8H10O2 C8H10O2 force-pushed the enh/custom-warning-no-motor-parachute-aerosurface branch from 016acae to 1d75f80 Compare November 14, 2025 23:32
@Gui-FernandesBR Gui-FernandesBR changed the base branch from master to develop November 19, 2025 01:50
Copilot finished reviewing on behalf of Gui-FernandesBR November 19, 2025 01:52
Copy link

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

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:
Copy link

Copilot AI Nov 19, 2025

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:.

Suggested change
if not self.aerodynamic_surfaces or len(self.aerodynamic_surfaces) == 0:
if not self.aerodynamic_surfaces:

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

true

Comment on lines +398 to +399
Notes:
- The warning uses Python's built-in `warnings.warn` function.
Copy link

Copilot AI Nov 19, 2025

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.

Suggested change
Notes:
- The warning uses Python's built-in `warnings.warn` function.
Notes
-----
- The warning uses Python's built-in `warnings.warn` function.
Returns
-------
None

Copilot uses AI. Check for mistakes.
Copy link
Member

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
Copy link

Copilot AI Nov 19, 2025

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.'

Suggested change
f"[WARNING] Rocket has no {component_list} defined.", UserWarning
f"Rocket has no {component_list} defined.", UserWarning

Copilot uses AI. Check for mistakes.
Copy link
Member

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 = []
Copy link

Copilot AI Nov 19, 2025

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.

Suggested change
calisto.parachutes = []

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

true

@Gui-FernandesBR
Copy link
Member

@Bizo883 please address all the comments, fix tests and linters. You can let me know when the PR is ready for review again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants