Skip to content

Commit

Permalink
TST: Fixes example_plain_env
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBarberini committed Mar 7, 2024
1 parent 831c221 commit 5f28285
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 63 deletions.
18 changes: 9 additions & 9 deletions tests/fixtures/flight/flight_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.fixture
def flight_calisto(calisto, example_env): # old name: flight
def flight_calisto(calisto, example_plain_env): # old name: flight
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
without the aerodynamic surfaces and parachutes. The environment is the
simplest possible, with no parameters set.
Expand All @@ -13,7 +13,7 @@ def flight_calisto(calisto, example_env): # old name: flight
----------
calisto : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
Expand All @@ -23,7 +23,7 @@ def flight_calisto(calisto, example_env): # old name: flight
conditions.
"""
return Flight(
environment=example_env,
environment=example_plain_env,
rocket=calisto,
rail_length=5.2,
inclination=85,
Expand All @@ -33,7 +33,7 @@ def flight_calisto(calisto, example_env): # old name: flight


@pytest.fixture
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_plain_env):
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
with "nose_to_tail" coordinate system orientation, just as described in the
calisto_nose_to_tail fixture.
Expand All @@ -42,7 +42,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
----------
calisto_nose_to_tail : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
Expand All @@ -52,7 +52,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
"nose_to_tail".
"""
return Flight(
environment=example_env,
environment=example_plain_env,
rocket=calisto_nose_to_tail,
rail_length=5.2,
inclination=85,
Expand Down Expand Up @@ -130,7 +130,7 @@ def flight_calisto_custom_wind(calisto_robust, example_spaceport_env):


@pytest.fixture
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_plain_env):
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
with the aerodynamic surfaces and air brakes. The environment is the
simplest possible, with no parameters set. The air brakes are set to clamp
Expand All @@ -140,7 +140,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
----------
calisto_air_brakes_clamp_on : rocketpy.Rocket
An object of the Rocket class.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
An object of the Environment class.
Returns
Expand All @@ -151,7 +151,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
"""
return Flight(
rocket=calisto_air_brakes_clamp_on,
environment=example_env,
environment=example_plain_env,
rail_length=5.2,
inclination=85,
heading=0,
Expand Down
66 changes: 33 additions & 33 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,58 @@


@patch("matplotlib.pyplot.show")
def test_standard_atmosphere(mock_show, example_env):
def test_standard_atmosphere(mock_show, example_plain_env):
"""Tests the standard atmosphere model in the environment object.
Parameters
----------
mock_show : mock
Mock object to replace matplotlib.pyplot.show() method.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
Example environment object to be tested.
"""
example_env.set_atmospheric_model(type="standard_atmosphere")
assert example_env.info() == None
assert example_env.all_info() == None
assert abs(example_env.pressure(0) - 101325.0) < 1e-8
assert abs(example_env.barometric_height(101325.0)) < 1e-2
assert example_env.prints.print_earth_details() == None
example_plain_env.set_atmospheric_model(type="standard_atmosphere")
assert example_plain_env.info() == None
assert example_plain_env.all_info() == None
assert abs(example_plain_env.pressure(0) - 101325.0) < 1e-8
assert abs(example_plain_env.barometric_height(101325.0)) < 1e-2
assert example_plain_env.prints.print_earth_details() == None


@patch("matplotlib.pyplot.show")
def test_custom_atmosphere(mock_show, example_env):
def test_custom_atmosphere(mock_show, example_plain_env):
"""Tests the custom atmosphere model in the environment object.
Parameters
----------
mock_show : mock
Mock object to replace matplotlib.pyplot.show() method.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
Example environment object to be tested.
"""
example_env.set_atmospheric_model(
example_plain_env.set_atmospheric_model(
type="custom_atmosphere",
pressure=None,
temperature=300,
wind_u=[(0, 5), (1000, 10)],
wind_v=[(0, -2), (500, 3), (1600, 2)],
)
assert example_env.all_info() == None
assert abs(example_env.pressure(0) - 101325.0) < 1e-8
assert abs(example_env.barometric_height(101325.0)) < 1e-2
assert abs(example_env.wind_velocity_x(0) - 5) < 1e-8
assert abs(example_env.temperature(100) - 300) < 1e-8
assert example_plain_env.all_info() == None
assert abs(example_plain_env.pressure(0) - 101325.0) < 1e-8
assert abs(example_plain_env.barometric_height(101325.0)) < 1e-2
assert abs(example_plain_env.wind_velocity_x(0) - 5) < 1e-8
assert abs(example_plain_env.temperature(100) - 300) < 1e-8


@patch("matplotlib.pyplot.show")
def test_wyoming_sounding_atmosphere(mock_show, example_env):
def test_wyoming_sounding_atmosphere(mock_show, example_plain_env):
"""Tests the Wyoming sounding model in the environment object.
Parameters
----------
mock_show : mock
Mock object to replace matplotlib.pyplot.show() method.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
Example environment object to be tested.
"""
# TODO:: this should be added to the set_atmospheric_model() method as a
Expand All @@ -66,26 +66,26 @@ def test_wyoming_sounding_atmosphere(mock_show, example_env):
# give it at least 5 times to try to download the file
for i in range(5):
try:
example_env.set_atmospheric_model(type="wyoming_sounding", file=URL)
example_plain_env.set_atmospheric_model(type="wyoming_sounding", file=URL)
break
except:
time.sleep(1) # wait 1 second before trying again
pass
assert example_env.all_info() == None
assert abs(example_env.pressure(0) - 93600.0) < 1e-8
assert abs(example_env.barometric_height(example_env.pressure(0)) - 722.0) < 1e-8
assert abs(example_env.wind_velocity_x(0) - -2.9005178894925043) < 1e-8
assert abs(example_env.temperature(100) - 291.75) < 1e-8
assert example_plain_env.all_info() == None
assert abs(example_plain_env.pressure(0) - 93600.0) < 1e-8
assert abs(example_plain_env.barometric_height(example_plain_env.pressure(0)) - 722.0) < 1e-8
assert abs(example_plain_env.wind_velocity_x(0) - -2.9005178894925043) < 1e-8
assert abs(example_plain_env.temperature(100) - 291.75) < 1e-8


@pytest.mark.skip(reason="legacy tests")
@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_noaa_ruc_sounding_atmosphere(mock_show, example_env):
def test_noaa_ruc_sounding_atmosphere(mock_show, example_plain_env):
URL = r"https://rucsoundings.noaa.gov/get_raobs.cgi?data_source=RAOB&latest=latest&start_year=2019&start_month_name=Feb&start_mday=5&start_hour=12&start_min=0&n_hrs=1.0&fcst_len=shortest&airport=83779&text=Ascii%20text%20%28GSD%20format%29&hydrometeors=false&start=latest"
example_env.set_atmospheric_model(type="NOAARucSounding", file=URL)
assert example_env.all_info() == None
assert example_env.pressure(0) == 100000.0
example_plain_env.set_atmospheric_model(type="NOAARucSounding", file=URL)
assert example_plain_env.all_info() == None
assert example_plain_env.pressure(0) == 100000.0


@pytest.mark.slow
Expand Down Expand Up @@ -170,21 +170,21 @@ def test_gefs_atmosphere(mock_show, example_spaceport_env):


@patch("matplotlib.pyplot.show")
def test_info_returns(mock_show, example_env):
def test_info_returns(mock_show, example_plain_env):
"""Tests the all_info_returned() all_plot_info_returned() and methods of the
Environment class.
Parameters
----------
mock_show : mock
Mock object to replace matplotlib.pyplot.show() method.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
Example environment object to be tested.
"""
returned_plots = example_env.all_plot_info_returned()
returned_infos = example_env.all_info_returned()
returned_plots = example_plain_env.all_plot_info_returned()
returned_infos = example_plain_env.all_info_returned()
expected_info = {
"grav": example_env.gravity,
"grav": example_plain_env.gravity,
"elevation": 0,
"model_type": "standard_atmosphere",
"model_type_max_expected_height": 80000,
Expand Down
34 changes: 17 additions & 17 deletions tests/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def compute_static_margin_error_given_distance(position, static_margin, rocket):


@patch("matplotlib.pyplot.show")
def test_initial_solution(mock_show, example_env, calisto_robust):
def test_initial_solution(mock_show, example_plain_env, calisto_robust):
"""Tests the initial_solution option of the Flight class. This test simply
simulates the flight using the initial_solution option and checks if the
all_info method returns None.
Expand All @@ -92,14 +92,14 @@ def test_initial_solution(mock_show, example_env, calisto_robust):
----------
mock_show : unittest.mock.MagicMock
Mock object to replace matplotlib.pyplot.show
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
Environment to be simulated. See the conftest.py file for more info.
calisto_robust : rocketpy.Rocket
Rocket to be simulated. See the conftest.py file for more info.
"""
test_flight = Flight(
rocket=calisto_robust,
environment=example_env,
environment=example_plain_env,
rail_length=5,
inclination=85,
heading=0,
Expand Down Expand Up @@ -128,10 +128,10 @@ def test_initial_solution(mock_show, example_env, calisto_robust):


@patch("matplotlib.pyplot.show")
def test_empty_motor_flight(mock_show, example_env, calisto_motorless):
def test_empty_motor_flight(mock_show, example_plain_env, calisto_motorless):
flight = Flight(
rocket=calisto_motorless,
environment=example_env,
environment=example_plain_env,
rail_length=5,
initial_solution=[ # a random flight starting at apogee
22.945995194368354,
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_stability_static_margins(wind_u, wind_v, static_margin, max_time):
@patch("matplotlib.pyplot.show")
def test_rolling_flight(
mock_show,
example_env,
example_plain_env,
cesaroni_m1670,
calisto,
calisto_nose_cone,
Expand All @@ -286,7 +286,7 @@ def test_rolling_flight(

test_flight = Flight(
rocket=test_rocket,
environment=example_env,
environment=example_plain_env,
rail_length=5.2,
inclination=85,
heading=0,
Expand Down Expand Up @@ -316,7 +316,7 @@ def test_air_brakes_flight(mock_show, flight_calisto_air_brakes):


@patch("matplotlib.pyplot.show")
def test_simpler_parachute_triggers(mock_show, example_env, calisto_robust):
def test_simpler_parachute_triggers(mock_show, example_plain_env, calisto_robust):
"""Tests different types of parachute triggers. This is important to ensure
the code is working as intended, since the parachute triggers can have very
different format definitions. It will add 3 parachutes using different
Expand All @@ -327,7 +327,7 @@ def test_simpler_parachute_triggers(mock_show, example_env, calisto_robust):
----------
mock_show : unittest.mock.MagicMock
Mock object to replace matplotlib.pyplot.show
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
Environment to be simulated. See the conftest.py file for more info.
calisto_robust : rocketpy.Rocket
Rocket to be simulated. See the conftest.py file for more info.
Expand Down Expand Up @@ -360,7 +360,7 @@ def test_simpler_parachute_triggers(mock_show, example_env, calisto_robust):

test_flight = Flight(
rocket=calisto_robust,
environment=example_env,
environment=example_plain_env,
rail_length=5,
inclination=85,
heading=0,
Expand All @@ -372,14 +372,14 @@ def test_simpler_parachute_triggers(mock_show, example_env, calisto_robust):
assert (
abs(
test_flight.z(test_flight.parachute_events[1][0])
- (800 + example_env.elevation)
- (800 + example_plain_env.elevation)
)
<= 1
)
assert (
abs(
test_flight.z(test_flight.parachute_events[2][0])
- (400 + example_env.elevation)
- (400 + example_plain_env.elevation)
)
<= 1
)
Expand All @@ -405,12 +405,12 @@ def test_lat_lon_conversion_robust(mock_show, example_spaceport_env, calisto_rob


@patch("matplotlib.pyplot.show")
def test_lat_lon_conversion_from_origin(mock_show, example_env, calisto_robust):
def test_lat_lon_conversion_from_origin(mock_show, example_plain_env, calisto_robust):
"additional tests to capture incorrect behaviors during lat/lon conversions"

test_flight = Flight(
rocket=calisto_robust,
environment=example_env,
environment=example_plain_env,
rail_length=5.2,
inclination=85,
heading=0,
Expand All @@ -430,7 +430,7 @@ def test_lat_lon_conversion_from_origin(mock_show, example_env, calisto_robust):
(100000, 100003.35594050681),
],
)
def test_rail_length(calisto_robust, example_env, rail_length, out_of_rail_time):
def test_rail_length(calisto_robust, example_plain_env, rail_length, out_of_rail_time):
"""Tests the rail length parameter of the Flight class. This test simply
simulate the flight using different rail lengths and checks if the expected
out of rail altitude is achieved. Four different rail lengths are
Expand All @@ -443,7 +443,7 @@ def test_rail_length(calisto_robust, example_env, rail_length, out_of_rail_time)
calisto_robust : rocketpy.Rocket
The rocket to be simulated. In this case, the fixture rocket is used.
See the conftest.py file for more information.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
The environment to be simulated. In this case, the fixture environment
is used. See the conftest.py file for more information.
rail_length : float, int
Expand All @@ -454,7 +454,7 @@ def test_rail_length(calisto_robust, example_env, rail_length, out_of_rail_time)
"""
test_flight = Flight(
rocket=calisto_robust,
environment=example_env,
environment=example_plain_env,
rail_length=rail_length,
inclination=85,
heading=0,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_compare(mock_show, flight_calisto):


@patch("matplotlib.pyplot.show")
def test_compare_flights(mock_show, calisto, example_env):
def test_compare_flights(mock_show, calisto, example_plain_env):
"""Tests the CompareFlights class. It simply ensures that all the methods
are being called without errors. It does not test the actual plots, which
would be very difficult to do.
Expand All @@ -54,14 +54,14 @@ def test_compare_flights(mock_show, calisto, example_env):
Mocks the matplotlib.pyplot.show() function to avoid showing the plots.
calisto : rocketpy.Rocket
Rocket object to be used in the tests. See conftest.py for more details.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
Environment object to be used in the tests. See conftest.py for more details.
Returns
-------
None
"""
example_env.set_atmospheric_model(
example_plain_env.set_atmospheric_model(
type="custom_atmosphere",
pressure=None,
temperature=300,
Expand All @@ -77,7 +77,7 @@ def test_compare_flights(mock_show, calisto, example_env):
for heading in headings:
for inclination in inclinations:
flight = Flight(
environment=example_env,
environment=example_plain_env,
rocket=calisto,
rail_length=5,
inclination=inclination,
Expand Down

0 comments on commit 5f28285

Please sign in to comment.