Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test_pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ jobs:
- name: Run Unit Tests
run: pytest tests/unit --cov=rocketpy

# The changelog workflow only runs after a merge, so its script is tested here.
- name: Test the changelog script
run: pytest .github/scripts/test_update_changelog.py

- name: Run Documentation Tests
run: |
pip install numpy --upgrade
Expand Down
3 changes: 2 additions & 1 deletion requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ statsmodels
prettytable
contextily>=1.0.0; python_version < '3.14'
pyvista>=0.45
imageio-ffmpeg>=0.5
imageio-ffmpeg>=0.5
folium>=0.14
31 changes: 14 additions & 17 deletions tests/acceptance/test_defiance_rocket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Acceptance test for the 2024 Defiance example flight."""
"""Defiance 2024 flight: apogee against the measured flight, the rest as a regression."""

import pytest

Expand All @@ -9,12 +9,12 @@

MEASURED_APOGEE_AGL = 9308.32
MAX_RELATIVE_APOGEE_ERROR = 0.01
REFERENCE_MAX_SPEED = 444.24
REFERENCE_MAX_ACCELERATION = 10400.76
REFERENCE_IMPACT_X = 1550.23
REFERENCE_IMPACT_Y = 104.80
REFERENCE_METRIC_RELATIVE_TOLERANCE = 0.01
REFERENCE_IMPACT_ABSOLUTE_TOLERANCE = 3.0
# RocketPy's own output, not flight data: they only catch unintended changes.
REGRESSION_MAX_SPEED = 444.24
REGRESSION_IMPACT_X = 1550.23
REGRESSION_IMPACT_Y = 104.80
REGRESSION_RELATIVE_TOLERANCE = 0.01
REGRESSION_IMPACT_ABSOLUTE_TOLERANCE = 3.0


def _build_defiance_flight():
Expand Down Expand Up @@ -122,21 +122,18 @@ def test_defiance_rocket_apogee_matches_measured_flight(defiance_flight):
)


def test_defiance_rocket_matches_reference_flight_metrics(defiance_flight):
"""Guard the deterministic example's peak and impact metrics."""
tolerance = {"rel": REFERENCE_METRIC_RELATIVE_TOLERANCE}
def test_defiance_rocket_regression_flight_metrics(defiance_flight):
"""Guard the example's max speed and impact point against unintended changes."""
tolerance = {"rel": REGRESSION_RELATIVE_TOLERANCE}
impact_tolerance = {
**tolerance,
"abs": REFERENCE_IMPACT_ABSOLUTE_TOLERANCE,
"abs": REGRESSION_IMPACT_ABSOLUTE_TOLERANCE,
}

assert defiance_flight.max_speed == pytest.approx(REFERENCE_MAX_SPEED, **tolerance)
assert defiance_flight.max_acceleration == pytest.approx(
REFERENCE_MAX_ACCELERATION, **tolerance
)
assert defiance_flight.max_speed == pytest.approx(REGRESSION_MAX_SPEED, **tolerance)
assert defiance_flight.x_impact == pytest.approx(
REFERENCE_IMPACT_X, **impact_tolerance
REGRESSION_IMPACT_X, **impact_tolerance
)
assert defiance_flight.y_impact == pytest.approx(
REFERENCE_IMPACT_Y, **impact_tolerance
REGRESSION_IMPACT_Y, **impact_tolerance
)
2 changes: 1 addition & 1 deletion tests/fixtures/environment/environment_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def env_analysis():
end_hour=18,
surface_data_file="./data/weather/EuroC_single_level_reanalysis_2002_2021.nc",
pressure_level_data_file="./data/weather/EuroC_pressure_levels_reanalysis_2001-2021.nc",
timezone=None,
timezone="Europe/Lisbon", # what timezonefinder gives, without needing it
unit_system="metric",
forecast_date=None,
forecast_args=None,
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/environment/test_environment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from unittest.mock import patch

import matplotlib as plt
import pytest

from rocketpy import Environment

plt.rcParams.update({"figure.max_open_warning": 0})


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_all_info(mock_show, env_analysis): # pylint: disable=unused-argument
"""Test the EnvironmentAnalysis.all_info() method, which already invokes
Expand All @@ -24,12 +26,16 @@ def test_all_info(mock_show, env_analysis): # pylint: disable=unused-argument
-------
None
"""
pytest.importorskip("windrose")
pytest.importorskip("ipywidgets")
pytest.importorskip("IPython")
assert env_analysis.info() is None
assert env_analysis.all_info() is None
assert env_analysis.plots.info() is None
os.remove("wind_rose.gif") # remove the files created by the method


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_exports(mock_show, env_analysis): # pylint: disable=unused-argument
"""Check the export methods of the EnvironmentAnalysis class. It
Expand All @@ -42,6 +48,10 @@ def test_exports(mock_show, env_analysis): # pylint: disable=unused-argument
env_analysis : EnvironmentAnalysis
A simple object of the EnvironmentAnalysis class.
"""
pytest.importorskip("windrose")
pytest.importorskip("ipywidgets")
pytest.importorskip("IPython")
pytest.importorskip("jsonpickle")

assert env_analysis.export_mean_profiles() is None
assert env_analysis.save("env_analysis_dict") is None
Expand All @@ -56,6 +66,7 @@ def test_exports(mock_show, env_analysis): # pylint: disable=unused-argument
os.remove("export_env_analysis.json")


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_create_environment_object(mock_show, env_analysis): # pylint: disable=unused-argument
assert isinstance(env_analysis.create_environment_object(), Environment)
10 changes: 10 additions & 0 deletions tests/unit/environment/test_environment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_missing_timezonefinder_defaults_to_utc(
assert analysis.end_date.tzinfo is not None


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_distribution_plots(mock_show, env_analysis): # pylint: disable=unused-argument
"""Tests the distribution plots method of the EnvironmentAnalysis class. It
Expand Down Expand Up @@ -78,6 +79,7 @@ def test_distribution_plots(mock_show, env_analysis): # pylint: disable=unused-
)


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_average_plots(mock_show, env_analysis): # pylint: disable=unused-argument
"""Tests the average plots method of the EnvironmentAnalysis class. It
Expand All @@ -94,6 +96,7 @@ def test_average_plots(mock_show, env_analysis): # pylint: disable=unused-argum
-------
None
"""
pytest.importorskip("windrose")
# Check "average" plots
assert env_analysis.plots.average_surface_temperature_evolution() is None
assert env_analysis.plots.average_surface10m_wind_speed_evolution(False) is None
Expand All @@ -103,6 +106,7 @@ def test_average_plots(mock_show, env_analysis): # pylint: disable=unused-argum
assert env_analysis.plots.average_wind_rose_specific_hour(12) is None


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_profile_plots(mock_show, env_analysis): # pylint: disable=unused-argument
"""Check the profile plots method of the EnvironmentAnalysis class. It
Expand Down Expand Up @@ -144,6 +148,7 @@ def test_profile_plots(mock_show, env_analysis): # pylint: disable=unused-argum
)


@pytest.mark.slow
def test_values(env_analysis):
"""Check the numeric properties of the EnvironmentAnalysis class. It computes
a few values and compares them to the expected values. Not all the values are
Expand All @@ -167,6 +172,7 @@ def test_values(env_analysis):
assert pytest.approx(env_analysis.std_pressure_at_30000ft, 1e-6) == 38.48947


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_animation_plots(mock_show, env_analysis): # pylint: disable=unused-argument
"""Check the animation plots method of the EnvironmentAnalysis class. It
Expand All @@ -181,6 +187,9 @@ def test_animation_plots(mock_show, env_analysis): # pylint: disable=unused-arg
env_analysis : EnvironmentAnalysis
A simple object of the EnvironmentAnalysis class.
"""
pytest.importorskip("windrose")
pytest.importorskip("ipywidgets")
pytest.importorskip("IPython")
# import dependencies
widgets = import_optional_dependency("ipywidgets")
HTML = import_optional_dependency("IPython.display").HTML
Expand All @@ -197,6 +206,7 @@ def test_animation_plots(mock_show, env_analysis): # pylint: disable=unused-arg
os.remove("wind_rose.gif") # remove the files created by the method


@pytest.mark.slow
def test_pressure_level_wind_profile_uses_velocity_components(env_analysis):
"""Regression for PR #1041: the redundant per-level ``wind_heading`` and
``wind_direction`` functions were removed from the pressure-level data.
Expand Down
Loading