Skip to content

Commit 0d01bf0

Browse files
MNT: fix pylint errors in the tests module
1 parent 92e29ad commit 0d01bf0

31 files changed

+657
-631
lines changed

.github/workflows/linters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
run: flake8 rocketpy/ tests/
4141
- name: Run pylint
4242
run: |
43-
pylint rocketpy/
43+
pylint rocketpy/ tests/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ flake8:
3737
flake8 rocketpy/ tests/
3838

3939
pylint:
40-
-pylint rocketpy --output=.pylint-report.txt
40+
-pylint rocketpy/ tests/ --output=.pylint-report.txt
4141

4242
build-docs:
4343
cd docs && $(PYTHON) -m pip install -r requirements.txt && make html

rocketpy/utilities.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def _flutter_prints(
424424
print(f"Altitude of minimum Safety Factor: {altitude_min_sf:.3f} m (AGL)\n")
425425

426426

427+
# TODO: deprecate and delete this function. Never used and now we have Monte Carlo.
427428
def create_dispersion_dictionary(filename):
428429
"""Creates a dictionary with the rocket data provided by a .csv file.
429430
File should be organized in four columns: attribute_class, parameter_name,

tests/acceptance/test_ndrt_2020_rocket.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ def test_ndrt_2020_rocket_data_asserts_acceptance():
6464
}
6565

6666
# Environment conditions
67-
Env23 = Environment(
67+
env = Environment(
6868
gravity=9.81,
6969
latitude=41.775447,
7070
longitude=-86.572467,
7171
date=(2020, 2, 23, 16),
7272
elevation=206,
7373
)
74-
Env23.set_atmospheric_model(
74+
env.set_atmospheric_model(
7575
type="Reanalysis",
7676
file="tests/fixtures/acceptance/NDRT_2020/ndrt_2020_weather_data_ERA5.nc",
7777
dictionary="ECMWF",
7878
)
79-
Env23.max_expected_height = 2000
79+
env.max_expected_height = 2000
8080

8181
# motor information
8282
L1395 = SolidMotor(
@@ -134,13 +134,13 @@ def test_ndrt_2020_rocket_data_asserts_acceptance():
134134
)
135135

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

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

166166
# Flight
167-
Flight23 = Flight(
167+
rocketpy_flight = Flight(
168168
rocket=NDRT2020,
169-
environment=Env23,
169+
environment=env,
170170
rail_length=parameters.get("rail_length")[0],
171171
inclination=parameters.get("inclination")[0],
172172
heading=parameters.get("heading")[0],
173173
)
174-
df_ndrt_rocketpy = pd.DataFrame(Flight23.z[:, :], columns=["Time", "Altitude"])
175-
df_ndrt_rocketpy["Vertical Velocity"] = Flight23.vz[:, 1]
176-
# df_ndrt_rocketpy["Vertical Acceleration"] = Flight23.az[:, 1]
177-
df_ndrt_rocketpy["Altitude"] -= Env23.elevation
174+
df_ndrt_rocketpy = pd.DataFrame(
175+
rocketpy_flight.z[:, :], columns=["Time", "Altitude"]
176+
)
177+
df_ndrt_rocketpy["Vertical Velocity"] = rocketpy_flight.vz[:, 1]
178+
# df_ndrt_rocketpy["Vertical Acceleration"] = rocketpy_flight.az[:, 1]
179+
df_ndrt_rocketpy["Altitude"] -= env.elevation
178180

179181
# Reading data from the flightData (sensors: Raven)
180182
df_ndrt_raven = pd.read_csv(
@@ -205,14 +207,14 @@ def main_trigger(p, h, y):
205207
apogee_time_measured = df_ndrt_raven.loc[
206208
df_ndrt_raven[" Altitude (Ft-AGL)"].idxmax(), " Time (s)"
207209
]
208-
apogee_time_simulated = Flight23.apogee_time
210+
apogee_time_simulated = rocketpy_flight.apogee_time
209211

210212
assert (
211213
abs(max(df_ndrt_raven[" Altitude (m-AGL)"]) - max(df_ndrt_rocketpy["Altitude"]))
212214
/ max(df_ndrt_raven[" Altitude (m-AGL)"])
213215
< 0.015
214216
)
215-
assert (max(velocity_raven_filt) - Flight23.max_speed) / max(
217+
assert (max(velocity_raven_filt) - rocketpy_flight.max_speed) / max(
216218
velocity_raven_filt
217219
) < 0.06
218220
assert (

tests/fixtures/function/function_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def lambda_quad_func():
134134
Function
135135
A lambda function based on a string.
136136
"""
137-
func = lambda x: x**2 # pylint: disable=unnecessary-lambda
137+
func = lambda x: x**2 # pylint: disable=unnecessary-lambda-assignment
138138
return Function(
139139
source=func,
140140
)

tests/fixtures/motor/solid_motor_fixtures.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,28 @@ def dimensionless_cesaroni_m1670(kg, m): # old name: dimensionless_motor
117117
coordinate_system_orientation="nozzle_to_combustion_chamber",
118118
)
119119
return example_motor
120+
121+
122+
@pytest.fixture
123+
def dummy_empty_motor():
124+
# Create a motor with ZERO thrust and ZERO mass to keep the rocket's speed constant
125+
# TODO: why don t we use these same values to create EmptyMotor class?
126+
return SolidMotor(
127+
thrust_source=1e-300,
128+
burn_time=1e-10,
129+
dry_mass=1.815,
130+
dry_inertia=(0.125, 0.125, 0.002),
131+
center_of_dry_mass_position=0.317,
132+
grains_center_of_mass_position=0.397,
133+
grain_number=5,
134+
grain_separation=5 / 1000,
135+
grain_density=1e-300,
136+
grain_outer_radius=33 / 1000,
137+
grain_initial_inner_radius=15 / 1000,
138+
grain_initial_height=120 / 1000,
139+
nozzle_radius=33 / 1000,
140+
throat_radius=11 / 1000,
141+
nozzle_position=0,
142+
interpolation_method="linear",
143+
coordinate_system_orientation="nozzle_to_combustion_chamber",
144+
)

tests/integration/test_environment.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_gefs_atmosphere(
100100
@patch("matplotlib.pyplot.show")
101101
def test_custom_atmosphere(
102102
mock_show, example_plain_env
103-
): # pylint: disable: unused-argument
103+
): # pylint: disable=unused-argument
104104
"""Tests the custom atmosphere model in the environment object.
105105
106106
Parameters
@@ -127,7 +127,7 @@ def test_custom_atmosphere(
127127
@patch("matplotlib.pyplot.show")
128128
def test_standard_atmosphere(
129129
mock_show, example_plain_env
130-
): # pylint: disable: unused-argument
130+
): # pylint: disable=unused-argument
131131
"""Tests the standard atmosphere model in the environment object.
132132
133133
Parameters
@@ -148,7 +148,7 @@ def test_standard_atmosphere(
148148
@patch("matplotlib.pyplot.show")
149149
def test_wyoming_sounding_atmosphere(
150150
mock_show, example_plain_env
151-
): # pylint: disable: unused-argument
151+
): # pylint: disable=unused-argument
152152
"""Asserts whether the Wyoming sounding model in the environment
153153
object behaves as expected with respect to some attributes such
154154
as pressure, barometric_height, wind_velocity and temperature.
@@ -163,15 +163,14 @@ def test_wyoming_sounding_atmosphere(
163163

164164
# TODO:: this should be added to the set_atmospheric_model() method as a
165165
# "file" option, instead of receiving the URL as a string.
166-
URL = "http://weather.uwyo.edu/cgi-bin/sounding?region=samer&TYPE=TEXT%3ALIST&YEAR=2019&MONTH=02&FROM=0500&TO=0512&STNM=83779"
166+
url = "http://weather.uwyo.edu/cgi-bin/sounding?region=samer&TYPE=TEXT%3ALIST&YEAR=2019&MONTH=02&FROM=0500&TO=0512&STNM=83779"
167167
# give it at least 5 times to try to download the file
168168
for i in range(5):
169169
try:
170-
example_plain_env.set_atmospheric_model(type="wyoming_sounding", file=URL)
170+
example_plain_env.set_atmospheric_model(type="wyoming_sounding", file=url)
171171
break
172-
except:
173-
time.sleep(1) # wait 1 second before trying again
174-
pass
172+
except Exception: # pylint: disable=broad-except
173+
time.sleep(2**i)
175174
assert example_plain_env.all_info() is None
176175
assert abs(example_plain_env.pressure(0) - 93600.0) < 1e-8
177176
assert (
@@ -227,7 +226,7 @@ def test_hiresw_ensemble_atmosphere(
227226
@patch("matplotlib.pyplot.show")
228227
def test_cmc_atmosphere(
229228
mock_show, example_spaceport_env
230-
): # pylint: disable: unused-argument
229+
): # pylint: disable=unused-argument
231230
"""Tests the Ensemble model with the CMC file.
232231
233232
Parameters

tests/integration/test_environment_analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

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

0 commit comments

Comments
 (0)