Skip to content
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

MNT: fix pylint errors in the tests module #632

Merged
merged 10 commits into from
Jul 9, 2024
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
run: flake8 rocketpy/ tests/
- name: Run pylint
run: |
pylint rocketpy/
pylint rocketpy/ tests/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ flake8:
flake8 rocketpy/ tests/

pylint:
-pylint rocketpy --output=.pylint-report.txt
-pylint rocketpy/ tests/ --output=.pylint-report.txt

build-docs:
cd docs && $(PYTHON) -m pip install -r requirements.txt && make html
Expand Down
1 change: 1 addition & 0 deletions rocketpy/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def _flutter_prints(
print(f"Altitude of minimum Safety Factor: {altitude_min_sf:.3f} m (AGL)\n")


# TODO: deprecate and delete this function. Never used and now we have Monte Carlo.
def create_dispersion_dictionary(filename):
"""Creates a dictionary with the rocket data provided by a .csv file.
File should be organized in four columns: attribute_class, parameter_name,
Expand Down
28 changes: 15 additions & 13 deletions tests/acceptance/test_ndrt_2020_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ def test_ndrt_2020_rocket_data_asserts_acceptance():
}

# Environment conditions
Env23 = Environment(
env = Environment(
gravity=9.81,
latitude=41.775447,
longitude=-86.572467,
date=(2020, 2, 23, 16),
elevation=206,
)
Env23.set_atmospheric_model(
env.set_atmospheric_model(
type="Reanalysis",
file="tests/fixtures/acceptance/NDRT_2020/ndrt_2020_weather_data_ERA5.nc",
dictionary="ECMWF",
)
Env23.max_expected_height = 2000
env.max_expected_height = 2000

# motor information
L1395 = SolidMotor(
Expand Down Expand Up @@ -134,13 +134,13 @@ def test_ndrt_2020_rocket_data_asserts_acceptance():
)

# Parachute set-up
def drogue_trigger(p, h, y):
def drogue_trigger(p, h, y): # pylint: disable=unused-argument
# p = pressure
# y = [x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
# activate drogue when vz < 0 m/s.
return True if y[5] < 0 else False

def main_trigger(p, h, y):
def main_trigger(p, h, y): # pylint: disable=unused-argument
# p = pressure
# y = [x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
# activate main when vz < 0 m/s and z < 167.64 m (AGL) or 550 ft (AGL)
Expand All @@ -164,17 +164,19 @@ def main_trigger(p, h, y):
)

# Flight
Flight23 = Flight(
rocketpy_flight = Flight(
rocket=NDRT2020,
environment=Env23,
environment=env,
rail_length=parameters.get("rail_length")[0],
inclination=parameters.get("inclination")[0],
heading=parameters.get("heading")[0],
)
df_ndrt_rocketpy = pd.DataFrame(Flight23.z[:, :], columns=["Time", "Altitude"])
df_ndrt_rocketpy["Vertical Velocity"] = Flight23.vz[:, 1]
# df_ndrt_rocketpy["Vertical Acceleration"] = Flight23.az[:, 1]
df_ndrt_rocketpy["Altitude"] -= Env23.elevation
df_ndrt_rocketpy = pd.DataFrame(
rocketpy_flight.z[:, :], columns=["Time", "Altitude"]
)
df_ndrt_rocketpy["Vertical Velocity"] = rocketpy_flight.vz[:, 1]
# df_ndrt_rocketpy["Vertical Acceleration"] = rocketpy_flight.az[:, 1]
df_ndrt_rocketpy["Altitude"] -= env.elevation

# Reading data from the flightData (sensors: Raven)
df_ndrt_raven = pd.read_csv(
Expand Down Expand Up @@ -205,14 +207,14 @@ def main_trigger(p, h, y):
apogee_time_measured = df_ndrt_raven.loc[
df_ndrt_raven[" Altitude (Ft-AGL)"].idxmax(), " Time (s)"
]
apogee_time_simulated = Flight23.apogee_time
apogee_time_simulated = rocketpy_flight.apogee_time

assert (
abs(max(df_ndrt_raven[" Altitude (m-AGL)"]) - max(df_ndrt_rocketpy["Altitude"]))
/ max(df_ndrt_raven[" Altitude (m-AGL)"])
< 0.015
)
assert (max(velocity_raven_filt) - Flight23.max_speed) / max(
assert (max(velocity_raven_filt) - rocketpy_flight.max_speed) / max(
velocity_raven_filt
) < 0.06
assert (
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/function/function_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def lambda_quad_func():
Function
A lambda function based on a string.
"""
func = lambda x: x**2 # pylint: disable=unnecessary-lambda
func = lambda x: x**2 # pylint: disable=unnecessary-lambda-assignment
return Function(
source=func,
)
25 changes: 25 additions & 0 deletions tests/fixtures/motor/solid_motor_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,28 @@ def dimensionless_cesaroni_m1670(kg, m): # old name: dimensionless_motor
coordinate_system_orientation="nozzle_to_combustion_chamber",
)
return example_motor


@pytest.fixture
def dummy_empty_motor():
# Create a motor with ZERO thrust and ZERO mass to keep the rocket's speed constant
# TODO: why don t we use these same values to create EmptyMotor class?
return SolidMotor(
thrust_source=1e-300,
burn_time=1e-10,
dry_mass=1.815,
dry_inertia=(0.125, 0.125, 0.002),
center_of_dry_mass_position=0.317,
grains_center_of_mass_position=0.397,
grain_number=5,
grain_separation=5 / 1000,
grain_density=1e-300,
grain_outer_radius=33 / 1000,
grain_initial_inner_radius=15 / 1000,
grain_initial_height=120 / 1000,
nozzle_radius=33 / 1000,
throat_radius=11 / 1000,
nozzle_position=0,
interpolation_method="linear",
coordinate_system_orientation="nozzle_to_combustion_chamber",
)
17 changes: 8 additions & 9 deletions tests/integration/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_gefs_atmosphere(
@patch("matplotlib.pyplot.show")
def test_custom_atmosphere(
mock_show, example_plain_env
): # pylint: disable: unused-argument
): # pylint: disable=unused-argument
"""Tests the custom atmosphere model in the environment object.

Parameters
Expand All @@ -127,7 +127,7 @@ def test_custom_atmosphere(
@patch("matplotlib.pyplot.show")
def test_standard_atmosphere(
mock_show, example_plain_env
): # pylint: disable: unused-argument
): # pylint: disable=unused-argument
"""Tests the standard atmosphere model in the environment object.

Parameters
Expand All @@ -148,7 +148,7 @@ def test_standard_atmosphere(
@patch("matplotlib.pyplot.show")
def test_wyoming_sounding_atmosphere(
mock_show, example_plain_env
): # pylint: disable: unused-argument
): # pylint: disable=unused-argument
"""Asserts whether the Wyoming sounding model in the environment
object behaves as expected with respect to some attributes such
as pressure, barometric_height, wind_velocity and temperature.
Expand All @@ -163,15 +163,14 @@ def test_wyoming_sounding_atmosphere(

# TODO:: this should be added to the set_atmospheric_model() method as a
# "file" option, instead of receiving the URL as a string.
URL = "http://weather.uwyo.edu/cgi-bin/sounding?region=samer&TYPE=TEXT%3ALIST&YEAR=2019&MONTH=02&FROM=0500&TO=0512&STNM=83779"
url = "http://weather.uwyo.edu/cgi-bin/sounding?region=samer&TYPE=TEXT%3ALIST&YEAR=2019&MONTH=02&FROM=0500&TO=0512&STNM=83779"
# give it at least 5 times to try to download the file
for i in range(5):
try:
example_plain_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
except Exception: # pylint: disable=broad-except
time.sleep(2**i)
assert example_plain_env.all_info() is None
assert abs(example_plain_env.pressure(0) - 93600.0) < 1e-8
assert (
Expand Down Expand Up @@ -227,7 +226,7 @@ def test_hiresw_ensemble_atmosphere(
@patch("matplotlib.pyplot.show")
def test_cmc_atmosphere(
mock_show, example_spaceport_env
): # pylint: disable: unused-argument
): # pylint: disable=unused-argument
"""Tests the Ensemble model with the CMC file.

Parameters
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_environment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_all_info(mock_show, env_analysis):
def test_all_info(mock_show, env_analysis): # pylint: disable=unused-argument
"""Test the EnvironmentAnalysis.all_info() method, which already invokes
several other methods. It is a good way to test the whole class in a first view.
However, if it fails, it is hard to know which method is failing.
Expand All @@ -32,7 +32,7 @@ def test_all_info(mock_show, env_analysis):

@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_exports(mock_show, env_analysis):
def test_exports(mock_show, env_analysis): # pylint: disable=unused-argument
"""Check the export methods of the EnvironmentAnalysis class. It
only checks if the method runs without errors. It does not check if the
files are correct, as this would require a lot of work and would be
Expand Down
Loading
Loading