From c801e865439ffc4d0738fbe15f843f9d8b1de11d Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 8 Sep 2023 23:21:24 -0300 Subject: [PATCH 01/11] TST: a new set of tests to the Flight class --- tests/conftest.py | 102 ++++++++++++++++++ tests/test_flight.py | 251 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 353 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 8d11efb54..338e74409 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -139,6 +139,43 @@ def calisto(cesaroni_m1670): # old name: rocket return calisto +@pytest.fixture +def calisto_nose_to_tail(cesaroni_m1670): + """Create a simple object of the Rocket class to be used in the tests. This + is the same as the calisto fixture, but with the coordinate system + orientation set to "nose_to_tail" instead of "tail_to_nose". This allows to + check if the coordinate system orientation is being handled correctly in + the code. + + Parameters + ---------- + cesaroni_m1670 : rocketpy.SolidMotor + An object of the SolidMotor class. This is a pytest fixture too. + + Returns + ------- + rocketpy.Rocket + The Calisto rocket with the coordinate system orientation set to + "nose_to_tail". Rail buttons are already set, as well as the motor. + """ + calisto = Rocket( + radius=0.0635, + mass=14.426, + inertia=(6.321, 6.321, 0.034), + power_off_drag="data/calisto/powerOffDragCurve.csv", + power_on_drag="data/calisto/powerOnDragCurve.csv", + center_of_mass_without_motor=0, + coordinate_system_orientation="nose_to_tail", + ) + calisto.add_motor(cesaroni_m1670, position=1.373) + calisto.set_rail_buttons( + upper_button_position=-0.082, + lower_button_position=0.618, + angular_position=45, + ) + return calisto + + @pytest.fixture def calisto_liquid_modded(liquid_motor): """Create a simple object of the Rocket class to be used in the tests. This @@ -729,6 +766,35 @@ def flight_calisto(calisto, example_env): # old name: flight ) +@pytest.fixture +def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_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. + + Parameters + ---------- + calisto_nose_to_tail : rocketpy.Rocket + An object of the Rocket class. This is a pytest fixture too. + example_env : rocketpy.Environment + An object of the Environment class. This is a pytest fixture too. + + Returns + ------- + rocketpy.Flight + The Calisto rocket with the coordinate system orientation set to + "nose_to_tail". + """ + return Flight( + environment=example_env, + rocket=calisto_nose_to_tail, + rail_length=5.2, + inclination=85, + heading=0, + terminate_on_apogee=False, + ) + + @pytest.fixture def flight_calisto_robust(calisto_robust, example_env_robust): """A rocketpy.Flight object of the Calisto rocket. This uses the calisto @@ -761,6 +827,42 @@ def flight_calisto_robust(calisto_robust, example_env_robust): ) +@pytest.fixture +def flight_calisto_custom_wind(calisto_robust, example_env_robust): + """A rocketpy.Flight object of the Calisto rocket. This uses the calisto + with the aerodynamic surfaces and parachutes. The environment is a bit more + complex than the one in the flight_calisto_robust fixture. Now the wind is + set to 5m/s (x direction) and 2m/s (y direction), constant with altitude. + + Parameters + ---------- + calisto_robust : rocketpy.Rocket + An object of the Rocket class. This is a pytest fixture too. + example_env_robust : rocketpy.Environment + An object of the Environment class. This is a pytest fixture too. + + Returns + ------- + rocketpy.Flight + + """ + env = example_env_robust + env.set_atmospheric_model( + type="custom_atmosphere", + temperature=300, + wind_u=[(0, 5), (4000, 5)], + wind_v=[(0, 2), (4000, 2)], + ) + return Flight( + environment=env, + rocket=calisto_robust, + rail_length=5.2, + inclination=85, + heading=0, + terminate_on_apogee=False, + ) + + ## Dimensionless motors and rockets diff --git a/tests/test_flight.py b/tests/test_flight.py index ed5483845..d57322d21 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -12,6 +12,24 @@ # Helper functions +def assert_approx_equal(test_value, expected_value, atol=1e-4, label=""): + """Asserts if two values are approximately equal. If the values are not + approximately equal, an AssertionError is raised, with a message containing + the label and the values. + + Parameters + ---------- + test_value : float + Value to be tested + expected_value : float + Expected value + atol : float, optional + Absolute tolerance error, by default 1e-4 + label : str, optional + Label to be printed in the error message, by default "" + """ + assert pytest.approx(test_value, abs=atol) == expected_value, f"Assertion failed at {label}: {test_value} != {expected_value}" + def setup_rocket_with_given_static_margin(rocket, static_margin): """Takes any rocket, removes its aerodynamic surfaces and adds a set of @@ -79,6 +97,8 @@ def compute_static_margin_error_given_distance(position, static_margin, rocket): return rocket +# Tests + @patch("matplotlib.pyplot.show") def test_all_info(mock_show, flight_calisto_robust): """Test that the flight class is working as intended. This basically calls @@ -594,3 +614,234 @@ def test_hybrid_motor_flight(mock_show, calisto_hybrid_modded): ) assert test_flight.all_info() == None + + +def test_surface_wind(flight_calisto_custom_wind, atol=1e-8): + """Tests the surface wind of the flight simulation. The expected values + are provided by the definition of the 'light_calisto_custom_wind' fixture. + If the fixture changes, this test must be updated. + + Parameters + ---------- + flight_calisto_custom_wind : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info + regarding this pytest fixture. + atol : float, optional + Absolute tolerance error, by default 1e-8 + """ + test = flight_calisto_custom_wind + assert pytest.approx(2.0, abs=atol) == test.frontal_surface_wind + assert pytest.approx(-5.0, abs=atol) == test.lateral_surface_wind + + +def test_effective_rail_length( + flight_calisto_robust, flight_calisto_nose_to_tail, atol=1e-8 +): + """Tests the effective rail length of the flight simulation. The expected + values are calculated by hand, and should be valid as long as the rail + length and the position of the buttons and nozzle do not change in the + fixtures. If the fixtures change, this test must be updated. It is important + to keep + + Parameters + ---------- + flight_calisto_robust : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info + regarding this pytest fixture. + flight_calisto_nose_to_tail : rocketpy.Flight + Flight object to be tested. The difference here is that the rocket is + defined with the "nose_to_tail" orientation instead of the + "tail_to_nose" orientation. See the conftest.py file for more info + regarding this pytest fixture. + atol : float, optional + The absolute tolerance error, by default 1e-8 + """ + test1 = flight_calisto_robust + test2 = flight_calisto_nose_to_tail + + rail_length = 5.2 + upper_button_position = 0.082 + lower_button_position = -0.618 + nozzle_position = -1.373 + + effective_1rl = rail_length - abs(upper_button_position - nozzle_position) + effective_2rl = rail_length - abs(lower_button_position - nozzle_position) + + # test 1: Rocket with "tail_to_nose" orientation + assert pytest.approx(test1.effective_1rl, abs=atol) == effective_1rl + assert pytest.approx(test1.effective_2rl, abs=atol) == effective_2rl + # test 2: Rocket with "nose_to_tail" orientation + assert pytest.approx(test2.effective_1rl, abs=atol) == effective_1rl + assert pytest.approx(test2.effective_2rl, abs=atol) == effective_2rl + + +def test_max_values(flight_calisto_robust, atol=1e-4): + """Test the max values of the flight. This tests if the max values are + close to the expected values. However, the expected values were NOT + calculated by hand, it was just copied from the test results. This is + because the expected values are not easy to calculate by hand, and the + results are not expected to change. If the results change, the test will + fail, and the expected values must be updated. If if want to update the + values, always double check if the results are really correct. Acceptable + reasons for changes in the results are: 1) changes in the code that + improve the accuracy of the simulation, 2) a bug was found and fixed. Keep + in mind that other tests may be more accurate than this one, for example, + the acceptance tests, which are based on the results of real flights. + + Parameters + ---------- + flight_calisto_robust : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info + regarding this pytest fixture. + atol : float, optional + Absolute tolerance error, by default 1e-4 + """ + test = flight_calisto_robust + assert pytest.approx(0.14996, abs=atol) == test.max_acceleration_power_on_time + assert pytest.approx(105.2774, abs=atol) == test.max_acceleration_power_on + assert pytest.approx(11.88541, abs=atol) == test.max_acceleration_power_off_time + assert pytest.approx(12.58658, abs=atol) == test.max_acceleration_power_off + assert pytest.approx(0.14996, abs=atol) == test.max_acceleration_time + assert pytest.approx(105.2774, abs=atol) == test.max_acceleration + assert pytest.approx(3.39630, abs=atol) == test.max_mach_number_time + assert pytest.approx(0.85999, abs=atol) == test.max_mach_number + assert pytest.approx(3.31516, abs=atol) == test.max_reynolds_number_time + assert pytest.approx(2138372.40383, abs=atol) == test.max_reynolds_number + assert pytest.approx(3.34463, abs=atol) == test.max_dynamic_pressure_time + assert pytest.approx(41528.39153, abs=atol) == test.max_dynamic_pressure + assert pytest.approx(3.29872, abs=atol) == test.max_total_pressure_time + assert pytest.approx(130467.16722, abs=atol) == test.max_total_pressure + + +def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-4): + """Test the rail buttons forces. This tests if the rail buttons forces are + close to the expected values. However, the expected values were NOT + calculated by hand, it was just copied from the test results. The results + are not expected to change, unless the code is changed for bug fixes or + accuracy improvements. + + Parameters + ---------- + flight_calisto_custom_wind : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info + regarding this pytest fixture. + atol : float, optional + The absolute tolerance error, by default 1e-4 + """ + test = flight_calisto_custom_wind + assert pytest.approx(3.80358, abs=atol) == test.max_rail_button1_normal_force + assert pytest.approx(1.63602, abs=atol) == test.max_rail_button1_shear_force + assert pytest.approx(1.19353, abs=atol) == test.max_rail_button2_normal_force + assert pytest.approx(0.51337, abs=atol) == test.max_rail_button2_shear_force + + +def test_accelerations(flight_calisto_custom_wind, atol=1e-4): + """Tests if the acceleration in some particular points of the trajectory is + correct. The expected values were NOT calculated by hand, it was just + copied from the test results. The results are not expected to change, + unless the code is changed for bug fixes or accuracy improvements. + + Parameters + ---------- + flight_calisto_custom_wind : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info. + atol : float, optional + The absolute tolerance error, by default 1e-4 + """ + test = flight_calisto_custom_wind + + points = { + "t_initial": (test.t_initial, 0, 0, 0), + "out_of_rail_time": (test.out_of_rail_time, 0, 7.8068, 89.2325), + "apogee_time": (test.apogee_time, 0.07534, -0.058127, -9.614386), + "t_final": (test.t_final, 0, 0, 0.0017346294117130806), + } + + for label, (t, expected_ax, expected_ay, expected_az) in points.items(): + assert_approx_equal(test.ax(t), expected_ax, atol, label) + assert_approx_equal(test.ay(t), expected_ay, atol, label) + assert_approx_equal(test.az(t), expected_az, atol, label) + + +def test_velocities(flight_calisto_custom_wind, atol=1e-4): + """Tests if the velocity in some particular points of the trajectory is + correct. The expected values were NOT calculated by hand, it was just + copied from the test results. The results are not expected to change, + unless the code is changed for bug fixes or accuracy improvements. + + Parameters + ---------- + flight_calisto_custom_wind : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info. + atol : float, optional + The absolute tolerance error, by default 1e-4 + """ + test = flight_calisto_custom_wind + + points = { + "t_initial": (test.t_initial, 0, 0, 0), + "out_of_rail_time": (test.out_of_rail_time, 0, 2.248727, 25.703072), + "apogee_time": (test.apogee_time, -13.209436, 16.05115, -0.000257), + "t_final": (test.t_final, 5, 2, -5.334289), + } + + for label, (t, expected_vx, expected_vy, expected_vz) in points.items(): + assert_approx_equal(test.vx(t), expected_vx, atol, label) + assert_approx_equal(test.vy(t), expected_vy, atol, label) + assert_approx_equal(test.vz(t), expected_vz, atol, label) + + +def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-4): + """Tests if the aerodynamic forces in some particular points of the + trajectory is correct. The expected values were NOT calculated by hand, it + was just copied from the test results. The results are not expected to + change, unless the code is changed for bug fixes or accuracy improvements. + + Parameters + ---------- + flight_calisto_custom_wind : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info. + atol : float, optional + The absolute tolerance error, by default 1e-4 + """ + test = flight_calisto_custom_wind + + points = { + "t_initial": (test.t_initial, 1.6542528, 0.65918, -0.067107), + "out_of_rail_time": (test.out_of_rail_time, 5.05334, 2.01364, -1.7541), + "apogee_time": (test.apogee_time, 2.35291, -1.8275, -0.87851), + "t_final": (test.t_final, 0, 0, 141.42421), + } + + for label, (t, expected_R1, expected_R2, expected_R3) in points.items(): + assert_approx_equal(test.R1(t), expected_R1, atol, label) + assert_approx_equal(test.R2(t), expected_R2, atol, label) + assert_approx_equal(test.R3(t), expected_R3, atol, label) + + +def test_aerodynamic_moments(flight_calisto_custom_wind, atol=1e-4): + """Tests if the aerodynamic moments in some particular points of the + trajectory is correct. The expected values were NOT calculated by hand, it + was just copied from the test results. The results are not expected to + change, unless the code is changed for bug fixes or accuracy improvements. + + Parameters + ---------- + flight_calisto_custom_wind : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info. + atol : float, optional + The absolute tolerance error, by default 1e-4 + """ + test = flight_calisto_custom_wind + + points = { + "t_initial": (test.t_initial, 0.17179073815516033, -0.431117, 0), + "out_of_rail_time": (test.out_of_rail_time, 0.547026, -1.3727895, 0), + "apogee_time": (test.apogee_time, -0.5874848151271623, -0.7563596, 0), + "t_final": (test.t_final, 0, 0, 0), + } + + for label, (t, expected_M1, expected_M2, expected_M3) in points.items(): + assert_approx_equal(test.M1(t), expected_M1, atol, label) + assert_approx_equal(test.M2(t), expected_M2, atol, label) + assert_approx_equal(test.M3(t), expected_M3, atol, label) From 937e5cfe2b1a9bfc54ba5882288d2fe9f6b71229 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 8 Sep 2023 23:22:40 -0300 Subject: [PATCH 02/11] STY: apply black to files --- tests/conftest.py | 6 +++--- tests/test_flight.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 338e74409..fe13185f2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -157,7 +157,7 @@ def calisto_nose_to_tail(cesaroni_m1670): rocketpy.Rocket The Calisto rocket with the coordinate system orientation set to "nose_to_tail". Rail buttons are already set, as well as the motor. - """ + """ calisto = Rocket( radius=0.0635, mass=14.426, @@ -770,7 +770,7 @@ def flight_calisto(calisto, example_env): # old name: flight def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_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. + calisto_nose_to_tail fixture. Parameters ---------- @@ -784,7 +784,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env): rocketpy.Flight The Calisto rocket with the coordinate system orientation set to "nose_to_tail". - """ + """ return Flight( environment=example_env, rocket=calisto_nose_to_tail, diff --git a/tests/test_flight.py b/tests/test_flight.py index d57322d21..d7b560ba4 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -12,6 +12,7 @@ # Helper functions + def assert_approx_equal(test_value, expected_value, atol=1e-4, label=""): """Asserts if two values are approximately equal. If the values are not approximately equal, an AssertionError is raised, with a message containing @@ -28,7 +29,9 @@ def assert_approx_equal(test_value, expected_value, atol=1e-4, label=""): label : str, optional Label to be printed in the error message, by default "" """ - assert pytest.approx(test_value, abs=atol) == expected_value, f"Assertion failed at {label}: {test_value} != {expected_value}" + assert ( + pytest.approx(test_value, abs=atol) == expected_value + ), f"Assertion failed at {label}: {test_value} != {expected_value}" def setup_rocket_with_given_static_margin(rocket, static_margin): @@ -99,6 +102,7 @@ def compute_static_margin_error_given_distance(position, static_margin, rocket): # Tests + @patch("matplotlib.pyplot.show") def test_all_info(mock_show, flight_calisto_robust): """Test that the flight class is working as intended. This basically calls @@ -739,7 +743,7 @@ def test_accelerations(flight_calisto_custom_wind, atol=1e-4): """Tests if the acceleration in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, - unless the code is changed for bug fixes or accuracy improvements. + unless the code is changed for bug fixes or accuracy improvements. Parameters ---------- @@ -747,7 +751,7 @@ def test_accelerations(flight_calisto_custom_wind, atol=1e-4): Flight object to be tested. See the conftest.py file for more info. atol : float, optional The absolute tolerance error, by default 1e-4 - """ + """ test = flight_calisto_custom_wind points = { @@ -767,7 +771,7 @@ def test_velocities(flight_calisto_custom_wind, atol=1e-4): """Tests if the velocity in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, - unless the code is changed for bug fixes or accuracy improvements. + unless the code is changed for bug fixes or accuracy improvements. Parameters ---------- @@ -775,7 +779,7 @@ def test_velocities(flight_calisto_custom_wind, atol=1e-4): Flight object to be tested. See the conftest.py file for more info. atol : float, optional The absolute tolerance error, by default 1e-4 - """ + """ test = flight_calisto_custom_wind points = { @@ -803,7 +807,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-4): Flight object to be tested. See the conftest.py file for more info. atol : float, optional The absolute tolerance error, by default 1e-4 - """ + """ test = flight_calisto_custom_wind points = { @@ -831,7 +835,7 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, atol=1e-4): Flight object to be tested. See the conftest.py file for more info. atol : float, optional The absolute tolerance error, by default 1e-4 - """ + """ test = flight_calisto_custom_wind points = { From 7929b9d937c8500d4fd90afa5e538217ac76e92c Mon Sep 17 00:00:00 2001 From: Guilherme Date: Sat, 9 Sep 2023 03:32:44 +0000 Subject: [PATCH 03/11] TST: increase abs tolerance due to different OS --- tests/test_flight.py | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index d7b560ba4..1d9e35206 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -679,7 +679,7 @@ def test_effective_rail_length( assert pytest.approx(test2.effective_2rl, abs=atol) == effective_2rl -def test_max_values(flight_calisto_robust, atol=1e-4): +def test_max_values(flight_calisto_robust, atol=1e-3): """Test the max values of the flight. This tests if the max values are close to the expected values. However, the expected values were NOT calculated by hand, it was just copied from the test results. This is @@ -698,26 +698,16 @@ def test_max_values(flight_calisto_robust, atol=1e-4): Flight object to be tested. See the conftest.py file for more info regarding this pytest fixture. atol : float, optional - Absolute tolerance error, by default 1e-4 + Absolute tolerance error, by default 1e-3 """ test = flight_calisto_robust - assert pytest.approx(0.14996, abs=atol) == test.max_acceleration_power_on_time assert pytest.approx(105.2774, abs=atol) == test.max_acceleration_power_on - assert pytest.approx(11.88541, abs=atol) == test.max_acceleration_power_off_time - assert pytest.approx(12.58658, abs=atol) == test.max_acceleration_power_off - assert pytest.approx(0.14996, abs=atol) == test.max_acceleration_time assert pytest.approx(105.2774, abs=atol) == test.max_acceleration - assert pytest.approx(3.39630, abs=atol) == test.max_mach_number_time assert pytest.approx(0.85999, abs=atol) == test.max_mach_number - assert pytest.approx(3.31516, abs=atol) == test.max_reynolds_number_time - assert pytest.approx(2138372.40383, abs=atol) == test.max_reynolds_number - assert pytest.approx(3.34463, abs=atol) == test.max_dynamic_pressure_time - assert pytest.approx(41528.39153, abs=atol) == test.max_dynamic_pressure - assert pytest.approx(3.29872, abs=atol) == test.max_total_pressure_time - assert pytest.approx(130467.16722, abs=atol) == test.max_total_pressure + assert pytest.approx(285.90240,abs=atol) == test.max_speed -def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-4): +def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-3): """Test the rail buttons forces. This tests if the rail buttons forces are close to the expected values. However, the expected values were NOT calculated by hand, it was just copied from the test results. The results @@ -730,7 +720,7 @@ def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-4): Flight object to be tested. See the conftest.py file for more info regarding this pytest fixture. atol : float, optional - The absolute tolerance error, by default 1e-4 + The absolute tolerance error, by default 1e-3 """ test = flight_calisto_custom_wind assert pytest.approx(3.80358, abs=atol) == test.max_rail_button1_normal_force @@ -739,7 +729,7 @@ def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-4): assert pytest.approx(0.51337, abs=atol) == test.max_rail_button2_shear_force -def test_accelerations(flight_calisto_custom_wind, atol=1e-4): +def test_accelerations(flight_calisto_custom_wind, atol=5e-3): """Tests if the acceleration in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -750,7 +740,7 @@ def test_accelerations(flight_calisto_custom_wind, atol=1e-4): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. atol : float, optional - The absolute tolerance error, by default 1e-4 + The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind @@ -767,7 +757,7 @@ def test_accelerations(flight_calisto_custom_wind, atol=1e-4): assert_approx_equal(test.az(t), expected_az, atol, label) -def test_velocities(flight_calisto_custom_wind, atol=1e-4): +def test_velocities(flight_calisto_custom_wind, atol=5e-3): """Tests if the velocity in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -778,7 +768,7 @@ def test_velocities(flight_calisto_custom_wind, atol=1e-4): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. atol : float, optional - The absolute tolerance error, by default 1e-4 + The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind @@ -795,7 +785,7 @@ def test_velocities(flight_calisto_custom_wind, atol=1e-4): assert_approx_equal(test.vz(t), expected_vz, atol, label) -def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-4): +def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-3): """Tests if the aerodynamic forces in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -806,7 +796,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-4): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. atol : float, optional - The absolute tolerance error, by default 1e-4 + The absolute tolerance error, by default 1e-3 """ test = flight_calisto_custom_wind @@ -823,7 +813,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-4): assert_approx_equal(test.R3(t), expected_R3, atol, label) -def test_aerodynamic_moments(flight_calisto_custom_wind, atol=1e-4): +def test_aerodynamic_moments(flight_calisto_custom_wind, atol=1e-3): """Tests if the aerodynamic moments in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -834,7 +824,7 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, atol=1e-4): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. atol : float, optional - The absolute tolerance error, by default 1e-4 + The absolute tolerance error, by default 1e-3 """ test = flight_calisto_custom_wind From cab5ba662d523d3fbb9ec76ca87ba919f6d58d97 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Sat, 9 Sep 2023 03:33:24 +0000 Subject: [PATCH 04/11] Fix code style issues with Black --- tests/test_flight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index 1d9e35206..4d6537d83 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -704,7 +704,7 @@ def test_max_values(flight_calisto_robust, atol=1e-3): assert pytest.approx(105.2774, abs=atol) == test.max_acceleration_power_on assert pytest.approx(105.2774, abs=atol) == test.max_acceleration assert pytest.approx(0.85999, abs=atol) == test.max_mach_number - assert pytest.approx(285.90240,abs=atol) == test.max_speed + assert pytest.approx(285.90240, abs=atol) == test.max_speed def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-3): From 917ecee1e535f4e00857d95ab650ae99c741bc99 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sat, 9 Sep 2023 00:52:52 -0300 Subject: [PATCH 05/11] TST: increase tolerances again --- tests/test_flight.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index 4d6537d83..492115ba1 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -679,7 +679,7 @@ def test_effective_rail_length( assert pytest.approx(test2.effective_2rl, abs=atol) == effective_2rl -def test_max_values(flight_calisto_robust, atol=1e-3): +def test_max_values(flight_calisto_robust, atol=5e-3): """Test the max values of the flight. This tests if the max values are close to the expected values. However, the expected values were NOT calculated by hand, it was just copied from the test results. This is @@ -698,7 +698,7 @@ def test_max_values(flight_calisto_robust, atol=1e-3): Flight object to be tested. See the conftest.py file for more info regarding this pytest fixture. atol : float, optional - Absolute tolerance error, by default 1e-3 + Absolute tolerance error, by default 5e-3 """ test = flight_calisto_robust assert pytest.approx(105.2774, abs=atol) == test.max_acceleration_power_on @@ -707,7 +707,7 @@ def test_max_values(flight_calisto_robust, atol=1e-3): assert pytest.approx(285.90240, abs=atol) == test.max_speed -def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-3): +def test_rail_buttons_forces(flight_calisto_custom_wind, atol=5e-3): """Test the rail buttons forces. This tests if the rail buttons forces are close to the expected values. However, the expected values were NOT calculated by hand, it was just copied from the test results. The results @@ -720,7 +720,7 @@ def test_rail_buttons_forces(flight_calisto_custom_wind, atol=1e-3): Flight object to be tested. See the conftest.py file for more info regarding this pytest fixture. atol : float, optional - The absolute tolerance error, by default 1e-3 + The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind assert pytest.approx(3.80358, abs=atol) == test.max_rail_button1_normal_force @@ -785,7 +785,7 @@ def test_velocities(flight_calisto_custom_wind, atol=5e-3): assert_approx_equal(test.vz(t), expected_vz, atol, label) -def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-3): +def test_aerodynamic_forces(flight_calisto_custom_wind, atol=5e-3): """Tests if the aerodynamic forces in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -796,7 +796,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-3): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. atol : float, optional - The absolute tolerance error, by default 1e-3 + The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind @@ -813,7 +813,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, atol=1e-3): assert_approx_equal(test.R3(t), expected_R3, atol, label) -def test_aerodynamic_moments(flight_calisto_custom_wind, atol=1e-3): +def test_aerodynamic_moments(flight_calisto_custom_wind, atol=5e-3): """Tests if the aerodynamic moments in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -824,7 +824,7 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, atol=1e-3): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. atol : float, optional - The absolute tolerance error, by default 1e-3 + The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind From 7cd424144810d9fa405dc292694055d205fc1fc3 Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Wed, 20 Sep 2023 14:26:09 -0300 Subject: [PATCH 06/11] FIX: remove testing tolerances from parameters. --- tests/test_flight.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index 492115ba1..cb3ebce3e 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -620,7 +620,7 @@ def test_hybrid_motor_flight(mock_show, calisto_hybrid_modded): assert test_flight.all_info() == None -def test_surface_wind(flight_calisto_custom_wind, atol=1e-8): +def test_surface_wind(flight_calisto_custom_wind): """Tests the surface wind of the flight simulation. The expected values are provided by the definition of the 'light_calisto_custom_wind' fixture. If the fixture changes, this test must be updated. @@ -634,13 +634,12 @@ def test_surface_wind(flight_calisto_custom_wind, atol=1e-8): Absolute tolerance error, by default 1e-8 """ test = flight_calisto_custom_wind + atol = 1e-8 assert pytest.approx(2.0, abs=atol) == test.frontal_surface_wind assert pytest.approx(-5.0, abs=atol) == test.lateral_surface_wind -def test_effective_rail_length( - flight_calisto_robust, flight_calisto_nose_to_tail, atol=1e-8 -): +def test_effective_rail_length(flight_calisto_robust, flight_calisto_nose_to_tail): """Tests the effective rail length of the flight simulation. The expected values are calculated by hand, and should be valid as long as the rail length and the position of the buttons and nozzle do not change in the @@ -662,6 +661,7 @@ def test_effective_rail_length( """ test1 = flight_calisto_robust test2 = flight_calisto_nose_to_tail + atol = 1e-8 rail_length = 5.2 upper_button_position = 0.082 @@ -679,7 +679,7 @@ def test_effective_rail_length( assert pytest.approx(test2.effective_2rl, abs=atol) == effective_2rl -def test_max_values(flight_calisto_robust, atol=5e-3): +def test_max_values(flight_calisto_robust): """Test the max values of the flight. This tests if the max values are close to the expected values. However, the expected values were NOT calculated by hand, it was just copied from the test results. This is @@ -701,13 +701,14 @@ def test_max_values(flight_calisto_robust, atol=5e-3): Absolute tolerance error, by default 5e-3 """ test = flight_calisto_robust + atol = 5e-3 assert pytest.approx(105.2774, abs=atol) == test.max_acceleration_power_on assert pytest.approx(105.2774, abs=atol) == test.max_acceleration assert pytest.approx(0.85999, abs=atol) == test.max_mach_number assert pytest.approx(285.90240, abs=atol) == test.max_speed -def test_rail_buttons_forces(flight_calisto_custom_wind, atol=5e-3): +def test_rail_buttons_forces(flight_calisto_custom_wind): """Test the rail buttons forces. This tests if the rail buttons forces are close to the expected values. However, the expected values were NOT calculated by hand, it was just copied from the test results. The results @@ -723,13 +724,14 @@ def test_rail_buttons_forces(flight_calisto_custom_wind, atol=5e-3): The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind + atol = 5e-3 assert pytest.approx(3.80358, abs=atol) == test.max_rail_button1_normal_force assert pytest.approx(1.63602, abs=atol) == test.max_rail_button1_shear_force assert pytest.approx(1.19353, abs=atol) == test.max_rail_button2_normal_force assert pytest.approx(0.51337, abs=atol) == test.max_rail_button2_shear_force -def test_accelerations(flight_calisto_custom_wind, atol=5e-3): +def test_accelerations(flight_calisto_custom_wind): """Tests if the acceleration in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -743,6 +745,7 @@ def test_accelerations(flight_calisto_custom_wind, atol=5e-3): The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind + atol = 5e-3 points = { "t_initial": (test.t_initial, 0, 0, 0), @@ -757,7 +760,7 @@ def test_accelerations(flight_calisto_custom_wind, atol=5e-3): assert_approx_equal(test.az(t), expected_az, atol, label) -def test_velocities(flight_calisto_custom_wind, atol=5e-3): +def test_velocities(flight_calisto_custom_wind): """Tests if the velocity in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -771,6 +774,7 @@ def test_velocities(flight_calisto_custom_wind, atol=5e-3): The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind + atol = 5e-3 points = { "t_initial": (test.t_initial, 0, 0, 0), @@ -785,7 +789,7 @@ def test_velocities(flight_calisto_custom_wind, atol=5e-3): assert_approx_equal(test.vz(t), expected_vz, atol, label) -def test_aerodynamic_forces(flight_calisto_custom_wind, atol=5e-3): +def test_aerodynamic_forces(flight_calisto_custom_wind): """Tests if the aerodynamic forces in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -799,6 +803,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, atol=5e-3): The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind + atol = 5e-3 points = { "t_initial": (test.t_initial, 1.6542528, 0.65918, -0.067107), @@ -813,7 +818,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, atol=5e-3): assert_approx_equal(test.R3(t), expected_R3, atol, label) -def test_aerodynamic_moments(flight_calisto_custom_wind, atol=5e-3): +def test_aerodynamic_moments(flight_calisto_custom_wind): """Tests if the aerodynamic moments in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -827,6 +832,7 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, atol=5e-3): The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind + atol = 5e-3 points = { "t_initial": (test.t_initial, 0.17179073815516033, -0.431117, 0), From cf9ac95048e2e888a8d6616b3027027cf7b780d2 Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Wed, 20 Sep 2023 15:39:50 -0300 Subject: [PATCH 07/11] TST: parametrize flight attribute tests and lable. --- tests/test_flight.py | 137 +++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index cb3ebce3e..4f4d62333 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -13,27 +13,6 @@ # Helper functions -def assert_approx_equal(test_value, expected_value, atol=1e-4, label=""): - """Asserts if two values are approximately equal. If the values are not - approximately equal, an AssertionError is raised, with a message containing - the label and the values. - - Parameters - ---------- - test_value : float - Value to be tested - expected_value : float - Expected value - atol : float, optional - Absolute tolerance error, by default 1e-4 - label : str, optional - Label to be printed in the error message, by default "" - """ - assert ( - pytest.approx(test_value, abs=atol) == expected_value - ), f"Assertion failed at {label}: {test_value} != {expected_value}" - - def setup_rocket_with_given_static_margin(rocket, static_margin): """Takes any rocket, removes its aerodynamic surfaces and adds a set of nose, fins and tail specially designed to have a given static margin. @@ -731,7 +710,16 @@ def test_rail_buttons_forces(flight_calisto_custom_wind): assert pytest.approx(0.51337, abs=atol) == test.max_rail_button2_shear_force -def test_accelerations(flight_calisto_custom_wind): +@pytest.mark.parametrize( + "params", + [ + ("t_initial", 0, 0, 0), + ("out_of_rail_time", 0, 7.8068, 89.2325), + ("apogee_time", 0.07534, -0.058127, -9.614386), + ("t_final", 0, 0, 0.0017346294117130806), + ], +) +def test_accelerations(flight_calisto_custom_wind, params): """Tests if the acceleration in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -744,23 +732,28 @@ def test_accelerations(flight_calisto_custom_wind): atol : float, optional The absolute tolerance error, by default 5e-3 """ + expected_attr, *expected_acc = params + test = flight_calisto_custom_wind + t = getattr(test, expected_attr) atol = 5e-3 - points = { - "t_initial": (test.t_initial, 0, 0, 0), - "out_of_rail_time": (test.out_of_rail_time, 0, 7.8068, 89.2325), - "apogee_time": (test.apogee_time, 0.07534, -0.058127, -9.614386), - "t_final": (test.t_final, 0, 0, 0.0017346294117130806), - } - - for label, (t, expected_ax, expected_ay, expected_az) in points.items(): - assert_approx_equal(test.ax(t), expected_ax, atol, label) - assert_approx_equal(test.ay(t), expected_ay, atol, label) - assert_approx_equal(test.az(t), expected_az, atol, label) + assert ( + pytest.approx(expected_acc, abs=atol) == (test.ax(t), test.ay(t), test.az(t)), + f"Assertion error for acceleration vector at {expected_attr}.", + ) -def test_velocities(flight_calisto_custom_wind): +@pytest.mark.parametrize( + "params", + [ + ("t_initial", 0, 0, 0), + ("out_of_rail_time", 0, 2.248727, 25.703072), + ("apogee_time", -13.209436, 16.05115, -0.000257), + ("t_final", 5, 2, -5.334289), + ], +) +def test_velocities(flight_calisto_custom_wind, params): """Tests if the velocity in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -773,23 +766,28 @@ def test_velocities(flight_calisto_custom_wind): atol : float, optional The absolute tolerance error, by default 5e-3 """ + expected_attr, *expected_vel = params + test = flight_calisto_custom_wind + t = getattr(test, expected_attr) atol = 5e-3 - points = { - "t_initial": (test.t_initial, 0, 0, 0), - "out_of_rail_time": (test.out_of_rail_time, 0, 2.248727, 25.703072), - "apogee_time": (test.apogee_time, -13.209436, 16.05115, -0.000257), - "t_final": (test.t_final, 5, 2, -5.334289), - } - - for label, (t, expected_vx, expected_vy, expected_vz) in points.items(): - assert_approx_equal(test.vx(t), expected_vx, atol, label) - assert_approx_equal(test.vy(t), expected_vy, atol, label) - assert_approx_equal(test.vz(t), expected_vz, atol, label) + assert ( + pytest.approx(expected_vel, abs=atol) == (test.vx(t), test.vy(t), test.vz(t)), + f"Assertion error for velocity vector at {expected_attr}.", + ) -def test_aerodynamic_forces(flight_calisto_custom_wind): +@pytest.mark.parametrize( + "params", + [ + ("t_initial", 1.6542528, 0.65918, -0.067107), + ("out_of_rail_time", 5.05334, 2.01364, -1.7541), + ("apogee_time", 2.35291, -1.8275, -0.87851), + ("t_final", 0, 0, 141.42421), + ], +) +def test_aerodynamic_forces(flight_calisto_custom_wind, params): """Tests if the aerodynamic forces in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -802,23 +800,28 @@ def test_aerodynamic_forces(flight_calisto_custom_wind): atol : float, optional The absolute tolerance error, by default 5e-3 """ + expected_attr, *expected_R = params + test = flight_calisto_custom_wind + t = getattr(test, expected_attr) atol = 5e-3 - points = { - "t_initial": (test.t_initial, 1.6542528, 0.65918, -0.067107), - "out_of_rail_time": (test.out_of_rail_time, 5.05334, 2.01364, -1.7541), - "apogee_time": (test.apogee_time, 2.35291, -1.8275, -0.87851), - "t_final": (test.t_final, 0, 0, 141.42421), - } - - for label, (t, expected_R1, expected_R2, expected_R3) in points.items(): - assert_approx_equal(test.R1(t), expected_R1, atol, label) - assert_approx_equal(test.R2(t), expected_R2, atol, label) - assert_approx_equal(test.R3(t), expected_R3, atol, label) + assert ( + pytest.approx(expected_R, abs=atol) == (test.R1(t), test.R2(t), test.R3(t)), + f"Assertion error for aerodynamic forces vector at {expected_attr}.", + ) -def test_aerodynamic_moments(flight_calisto_custom_wind): +@pytest.mark.parametrize( + "params", + [ + ("t_initial", 0.17179073815516033, -0.431117, 0), + ("out_of_rail_time", 0.547026, -1.3727895, 0), + ("apogee_time", -0.5874848151271623, -0.7563596, 0), + ("t_final", 0, 0, 0), + ], +) +def test_aerodynamic_moments(flight_calisto_custom_wind, params): """Tests if the aerodynamic moments in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -831,17 +834,13 @@ def test_aerodynamic_moments(flight_calisto_custom_wind): atol : float, optional The absolute tolerance error, by default 5e-3 """ + expected_attr, *expected_M = params + test = flight_calisto_custom_wind + t = getattr(test, expected_attr) atol = 5e-3 - points = { - "t_initial": (test.t_initial, 0.17179073815516033, -0.431117, 0), - "out_of_rail_time": (test.out_of_rail_time, 0.547026, -1.3727895, 0), - "apogee_time": (test.apogee_time, -0.5874848151271623, -0.7563596, 0), - "t_final": (test.t_final, 0, 0, 0), - } - - for label, (t, expected_M1, expected_M2, expected_M3) in points.items(): - assert_approx_equal(test.M1(t), expected_M1, atol, label) - assert_approx_equal(test.M2(t), expected_M2, atol, label) - assert_approx_equal(test.M3(t), expected_M3, atol, label) + assert ( + pytest.approx(expected_M, abs=atol) == (test.M1(t), test.M2(t), test.M3(t)), + f"Assertion error for moment vector at {expected_attr}.", + ) From e1a60f389deb2b8df243cba6822ef5e9be18c577 Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Thu, 21 Sep 2023 00:05:10 -0300 Subject: [PATCH 08/11] FIX: mistake in parameter syntax of labeling assert. --- tests/test_flight.py | 92 +++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index 4f4d62333..b1c245d0b 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -711,15 +711,15 @@ def test_rail_buttons_forces(flight_calisto_custom_wind): @pytest.mark.parametrize( - "params", + "flight_time, expected_values", [ - ("t_initial", 0, 0, 0), - ("out_of_rail_time", 0, 7.8068, 89.2325), - ("apogee_time", 0.07534, -0.058127, -9.614386), - ("t_final", 0, 0, 0.0017346294117130806), + ("t_initial", (0, 0, 0)), + ("out_of_rail_time", (0, 7.8068, 89.2325)), + ("apogee_time", (0.07534, -0.058127, -9.614386)), + ("t_final", (0, 0, 0.0017346294117130806)), ], ) -def test_accelerations(flight_calisto_custom_wind, params): +def test_accelerations(flight_calisto_custom_wind, flight_time, expected_values): """Tests if the acceleration in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -732,28 +732,29 @@ def test_accelerations(flight_calisto_custom_wind, params): atol : float, optional The absolute tolerance error, by default 5e-3 """ - expected_attr, *expected_acc = params + expected_attr, expected_acc = flight_time, expected_values test = flight_calisto_custom_wind t = getattr(test, expected_attr) atol = 5e-3 - assert ( - pytest.approx(expected_acc, abs=atol) == (test.ax(t), test.ay(t), test.az(t)), - f"Assertion error for acceleration vector at {expected_attr}.", - ) + assert pytest.approx(expected_acc, abs=atol) == ( + test.ax(t), + test.ay(t), + test.az(t), + ), f"Assertion error for acceleration vector at {expected_attr}." @pytest.mark.parametrize( - "params", + "flight_time, expected_values", [ - ("t_initial", 0, 0, 0), - ("out_of_rail_time", 0, 2.248727, 25.703072), - ("apogee_time", -13.209436, 16.05115, -0.000257), - ("t_final", 5, 2, -5.334289), + ("t_initial", (0, 0, 0)), + ("out_of_rail_time", (0, 2.248727, 25.703072)), + ("apogee_time", (-13.209436, 16.05115, -0.000257)), + ("t_final", (5, 2, -5.334289)), ], ) -def test_velocities(flight_calisto_custom_wind, params): +def test_velocities(flight_calisto_custom_wind, flight_time, expected_values): """Tests if the velocity in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to change, @@ -766,28 +767,29 @@ def test_velocities(flight_calisto_custom_wind, params): atol : float, optional The absolute tolerance error, by default 5e-3 """ - expected_attr, *expected_vel = params + expected_attr, expected_vel = flight_time, expected_values test = flight_calisto_custom_wind t = getattr(test, expected_attr) atol = 5e-3 - assert ( - pytest.approx(expected_vel, abs=atol) == (test.vx(t), test.vy(t), test.vz(t)), - f"Assertion error for velocity vector at {expected_attr}.", - ) + assert pytest.approx(expected_vel, abs=atol) == ( + test.vx(t), + test.vy(t), + test.vz(t), + ), f"Assertion error for velocity vector at {expected_attr}." @pytest.mark.parametrize( - "params", + "flight_time, expected_values", [ - ("t_initial", 1.6542528, 0.65918, -0.067107), - ("out_of_rail_time", 5.05334, 2.01364, -1.7541), - ("apogee_time", 2.35291, -1.8275, -0.87851), - ("t_final", 0, 0, 141.42421), + ("t_initial", (1.6542528, 0.65918, -0.067107)), + ("out_of_rail_time", (5.05334, 2.01364, -1.7541)), + ("apogee_time", (2.35291, -1.8275, -0.87851)), + ("t_final", (0, 0, 141.42421)), ], ) -def test_aerodynamic_forces(flight_calisto_custom_wind, params): +def test_aerodynamic_forces(flight_calisto_custom_wind, flight_time, expected_values): """Tests if the aerodynamic forces in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -800,28 +802,29 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, params): atol : float, optional The absolute tolerance error, by default 5e-3 """ - expected_attr, *expected_R = params + expected_attr, expected_R = flight_time, expected_values test = flight_calisto_custom_wind t = getattr(test, expected_attr) atol = 5e-3 - assert ( - pytest.approx(expected_R, abs=atol) == (test.R1(t), test.R2(t), test.R3(t)), - f"Assertion error for aerodynamic forces vector at {expected_attr}.", - ) + assert pytest.approx(expected_R, abs=atol) == ( + test.R1(t), + test.R2(t), + test.R3(t), + ), f"Assertion error for aerodynamic forces vector at {expected_attr}." @pytest.mark.parametrize( - "params", + "flight_time, expected_values", [ - ("t_initial", 0.17179073815516033, -0.431117, 0), - ("out_of_rail_time", 0.547026, -1.3727895, 0), - ("apogee_time", -0.5874848151271623, -0.7563596, 0), - ("t_final", 0, 0, 0), + ("t_initial", (0.17179073815516033, -0.431117, 0)), + ("out_of_rail_time", (0.547026, -1.3727895, 0)), + ("apogee_time", (-0.5874848151271623, -0.7563596, 0)), + ("t_final", (0, 0, 0)), ], ) -def test_aerodynamic_moments(flight_calisto_custom_wind, params): +def test_aerodynamic_moments(flight_calisto_custom_wind, flight_time, expected_values): """Tests if the aerodynamic moments in some particular points of the trajectory is correct. The expected values were NOT calculated by hand, it was just copied from the test results. The results are not expected to @@ -834,13 +837,14 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, params): atol : float, optional The absolute tolerance error, by default 5e-3 """ - expected_attr, *expected_M = params + expected_attr, expected_M = flight_time, expected_values test = flight_calisto_custom_wind t = getattr(test, expected_attr) atol = 5e-3 - assert ( - pytest.approx(expected_M, abs=atol) == (test.M1(t), test.M2(t), test.M3(t)), - f"Assertion error for moment vector at {expected_attr}.", - ) + assert pytest.approx(expected_M, abs=atol) == ( + test.M1(t), + test.M2(t), + test.M3(t), + ), f"Assertion error for moment vector at {expected_attr}." From abd5ca5d6db460a74b59b64bfbcc201f6e64c6b3 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Sun, 29 Oct 2023 04:05:50 +0000 Subject: [PATCH 09/11] Fix code style issues with Black --- tests/conftest.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fe88c1a18..443cff647 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,11 +4,28 @@ import numpy as np import pytest -from rocketpy import (CylindricalTank, Environment, EnvironmentAnalysis, - Flight, Fluid, Function, GenericMotor, HybridMotor, - LevelBasedTank, LiquidMotor, MassBasedTank, NoseCone, - Parachute, RailButtons, Rocket, SolidMotor, - SphericalTank, Tail, TrapezoidalFins, UllageBasedTank) +from rocketpy import ( + CylindricalTank, + Environment, + EnvironmentAnalysis, + Flight, + Fluid, + Function, + GenericMotor, + HybridMotor, + LevelBasedTank, + LiquidMotor, + MassBasedTank, + NoseCone, + Parachute, + RailButtons, + Rocket, + SolidMotor, + SphericalTank, + Tail, + TrapezoidalFins, + UllageBasedTank, +) # Pytest configuration From f3ad1dc764747ca74529e36492b3c04378f39c6e Mon Sep 17 00:00:00 2001 From: phmbressan Date: Sun, 29 Oct 2023 16:30:50 -0300 Subject: [PATCH 10/11] DOC: update docstrings for new tests parameters. --- tests/test_flight.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index b2009fc41..d0ef8b9cc 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -791,8 +791,12 @@ def test_accelerations(flight_calisto_custom_wind, flight_time, expected_values) ---------- flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. - atol : float, optional - The absolute tolerance error, by default 5e-3 + flight_time : str + The name of the attribute of the flight object that contains the time + of the point to be tested. + expected_values : tuple + The expected values of the acceleration vector at the point to be + tested. """ expected_attr, expected_acc = flight_time, expected_values @@ -826,8 +830,11 @@ def test_velocities(flight_calisto_custom_wind, flight_time, expected_values): ---------- flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. - atol : float, optional - The absolute tolerance error, by default 5e-3 + flight_time : str + The name of the attribute of the flight object that contains the time + of the point to be tested. + expected_values : tuple + The expected values of the velocity vector at the point to be tested. """ expected_attr, expected_vel = flight_time, expected_values @@ -861,8 +868,12 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, flight_time, expected_va ---------- flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. - atol : float, optional - The absolute tolerance error, by default 5e-3 + flight_time : str + The name of the attribute of the flight object that contains the time + of the point to be tested. + expected_values : tuple + The expected values of the aerodynamic forces vector at the point to be + tested. """ expected_attr, expected_R = flight_time, expected_values @@ -896,8 +907,12 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, flight_time, expected_v ---------- flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. - atol : float, optional - The absolute tolerance error, by default 5e-3 + flight_time : str + The name of the attribute of the flight object that contains the time + of the point to be tested. + expected_values : tuple + The expected values of the aerodynamic moments vector at the point to + be tested. """ expected_attr, expected_M = flight_time, expected_values From 81118ea7e03efbba237e826ae3e41817d6079614 Mon Sep 17 00:00:00 2001 From: phmbressan Date: Sun, 29 Oct 2023 16:32:55 -0300 Subject: [PATCH 11/11] DOC: fix docstrings describing old tolerance parameters. --- tests/test_flight.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/test_flight.py b/tests/test_flight.py index d0ef8b9cc..279d4c427 100644 --- a/tests/test_flight.py +++ b/tests/test_flight.py @@ -671,8 +671,6 @@ def test_surface_wind(flight_calisto_custom_wind): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info regarding this pytest fixture. - atol : float, optional - Absolute tolerance error, by default 1e-8 """ test = flight_calisto_custom_wind atol = 1e-8 @@ -697,8 +695,6 @@ def test_effective_rail_length(flight_calisto_robust, flight_calisto_nose_to_tai defined with the "nose_to_tail" orientation instead of the "tail_to_nose" orientation. See the conftest.py file for more info regarding this pytest fixture. - atol : float, optional - The absolute tolerance error, by default 1e-8 """ test1 = flight_calisto_robust test2 = flight_calisto_nose_to_tail @@ -738,8 +734,6 @@ def test_max_values(flight_calisto_robust): flight_calisto_robust : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info regarding this pytest fixture. - atol : float, optional - Absolute tolerance error, by default 5e-3 """ test = flight_calisto_robust atol = 5e-3 @@ -761,8 +755,6 @@ def test_rail_buttons_forces(flight_calisto_custom_wind): flight_calisto_custom_wind : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info regarding this pytest fixture. - atol : float, optional - The absolute tolerance error, by default 5e-3 """ test = flight_calisto_custom_wind atol = 5e-3