Skip to content

Commit 13629ed

Browse files
TST: refactors environment.set_date test
TST: refactors tests/unit/test_environment TST: refactors environment_fixtures DOC: fix doc typo in decimal_degrees_to_arc_seconds TST: fixes example_spaceport_env legacy references Fix code style issues with Black TST: Fixes example_plain_env TST: Fixes environment unit teardown Fix code style issues with Black
1 parent 65b3315 commit 13629ed

File tree

7 files changed

+214
-216
lines changed

7 files changed

+214
-216
lines changed

rocketpy/environment/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3696,7 +3696,7 @@ def decimal_degrees_to_arc_seconds(angle):
36963696
-------
36973697
degrees : float
36983698
The degrees.
3699-
arc_minutes : float
3699+
arc_minutes : int
37003700
The arc minutes. 1 arc-minute = (1/60)*degree
37013701
arc_seconds : float
37023702
The arc Seconds. 1 arc-second = (1/3600)*degree

tests/fixtures/environment/environment_fixtures.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,55 @@
1-
import datetime
2-
31
import pytest
4-
2+
from datetime import datetime, timedelta
53
from rocketpy import Environment, EnvironmentAnalysis
64

75

86
@pytest.fixture
9-
def example_env():
10-
"""Create a simple object of the Environment class to be used in the tests.
11-
This allows to avoid repeating the same code in all tests. The environment
12-
set here is the simplest possible, with no parameters set.
7+
def example_plain_env():
8+
"""Simple object of the Environment class to be used in the tests.
139
1410
Returns
1511
-------
1612
rocketpy.Environment
17-
The simplest object of the Environment class
1813
"""
1914
return Environment()
2015

2116

2217
@pytest.fixture
23-
def example_env_robust():
24-
"""Create an object of the Environment class to be used in the tests. This
25-
allows to avoid repeating the same code in all tests. The environment set
26-
here is a bit more complex than the one in the example_env fixture. This
27-
time the latitude, longitude and elevation are set, as well as the datum and
28-
the date. The location refers to the Spaceport America Cup launch site,
29-
while the date is set to tomorrow at noon.
18+
def example_date_naive():
19+
"""Naive tomorrow date
20+
21+
Returns
22+
-------
23+
datetime.datetime
24+
"""
25+
return datetime.now() + timedelta(days=1)
26+
27+
28+
@pytest.fixture
29+
def example_spaceport_env(example_date_naive):
30+
"""Environment class with location set to Spaceport America Cup launch site
3031
3132
Returns
3233
-------
3334
rocketpy.Environment
34-
An object of the Environment class
3535
"""
36-
env = Environment(
36+
spaceport_env = Environment(
3737
latitude=32.990254,
3838
longitude=-106.974998,
3939
elevation=1400,
4040
datum="WGS84",
4141
)
42-
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
43-
env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))
44-
return env
42+
spaceport_env.set_date(example_date_naive)
43+
return spaceport_env
4544

4645

4746
@pytest.fixture
4847
def env_analysis():
49-
"""Create a simple object of the Environment Analysis class to be used in
50-
the tests. This allows to avoid repeating the same code in all tests.
48+
"""Environment Analysis class with hardcoded parameters
5149
5250
Returns
5351
-------
5452
EnvironmentAnalysis
55-
A simple object of the Environment Analysis class
5653
"""
5754
env_analysis = EnvironmentAnalysis(
5855
start_date=datetime.datetime(2019, 10, 23),

tests/fixtures/flight/flight_fixtures.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@pytest.fixture
7-
def flight_calisto(calisto, example_env): # old name: flight
7+
def flight_calisto(calisto, example_plain_env): # old name: flight
88
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
99
without the aerodynamic surfaces and parachutes. The environment is the
1010
simplest possible, with no parameters set.
@@ -13,7 +13,7 @@ def flight_calisto(calisto, example_env): # old name: flight
1313
----------
1414
calisto : rocketpy.Rocket
1515
An object of the Rocket class. This is a pytest fixture too.
16-
example_env : rocketpy.Environment
16+
example_plain_env : rocketpy.Environment
1717
An object of the Environment class. This is a pytest fixture too.
1818
1919
Returns
@@ -23,7 +23,7 @@ def flight_calisto(calisto, example_env): # old name: flight
2323
conditions.
2424
"""
2525
return Flight(
26-
environment=example_env,
26+
environment=example_plain_env,
2727
rocket=calisto,
2828
rail_length=5.2,
2929
inclination=85,
@@ -33,7 +33,7 @@ def flight_calisto(calisto, example_env): # old name: flight
3333

3434

3535
@pytest.fixture
36-
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
36+
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_plain_env):
3737
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
3838
with "nose_to_tail" coordinate system orientation, just as described in the
3939
calisto_nose_to_tail fixture.
@@ -42,7 +42,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
4242
----------
4343
calisto_nose_to_tail : rocketpy.Rocket
4444
An object of the Rocket class. This is a pytest fixture too.
45-
example_env : rocketpy.Environment
45+
example_plain_env : rocketpy.Environment
4646
An object of the Environment class. This is a pytest fixture too.
4747
4848
Returns
@@ -52,7 +52,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
5252
"nose_to_tail".
5353
"""
5454
return Flight(
55-
environment=example_env,
55+
environment=example_plain_env,
5656
rocket=calisto_nose_to_tail,
5757
rail_length=5.2,
5858
inclination=85,
@@ -62,7 +62,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
6262

6363

6464
@pytest.fixture
65-
def flight_calisto_robust(calisto_robust, example_env_robust):
65+
def flight_calisto_robust(calisto_robust, example_spaceport_env):
6666
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
6767
with the aerodynamic surfaces and parachutes. The environment is a bit more
6868
complex than the one in the flight_calisto fixture. This time the latitude,
@@ -74,7 +74,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
7474
----------
7575
calisto_robust : rocketpy.Rocket
7676
An object of the Rocket class. This is a pytest fixture too.
77-
example_env_robust : rocketpy.Environment
77+
example_spaceport_env : rocketpy.Environment
7878
An object of the Environment class. This is a pytest fixture too.
7979
8080
Returns
@@ -84,7 +84,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
8484
condition.
8585
"""
8686
return Flight(
87-
environment=example_env_robust,
87+
environment=example_spaceport_env,
8888
rocket=calisto_robust,
8989
rail_length=5.2,
9090
inclination=85,
@@ -94,7 +94,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
9494

9595

9696
@pytest.fixture
97-
def flight_calisto_custom_wind(calisto_robust, example_env_robust):
97+
def flight_calisto_custom_wind(calisto_robust, example_spaceport_env):
9898
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
9999
with the aerodynamic surfaces and parachutes. The environment is a bit more
100100
complex than the one in the flight_calisto_robust fixture. Now the wind is
@@ -104,15 +104,15 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):
104104
----------
105105
calisto_robust : rocketpy.Rocket
106106
An object of the Rocket class. This is a pytest fixture too.
107-
example_env_robust : rocketpy.Environment
107+
example_spaceport_env : rocketpy.Environment
108108
An object of the Environment class. This is a pytest fixture too.
109109
110110
Returns
111111
-------
112112
rocketpy.Flight
113113
114114
"""
115-
env = example_env_robust
115+
env = example_spaceport_env
116116
env.set_atmospheric_model(
117117
type="custom_atmosphere",
118118
temperature=300,
@@ -130,7 +130,7 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):
130130

131131

132132
@pytest.fixture
133-
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
133+
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_plain_env):
134134
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
135135
with the aerodynamic surfaces and air brakes. The environment is the
136136
simplest possible, with no parameters set. The air brakes are set to clamp
@@ -140,7 +140,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
140140
----------
141141
calisto_air_brakes_clamp_on : rocketpy.Rocket
142142
An object of the Rocket class.
143-
example_env : rocketpy.Environment
143+
example_plain_env : rocketpy.Environment
144144
An object of the Environment class.
145145
146146
Returns
@@ -151,7 +151,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
151151
"""
152152
return Flight(
153153
rocket=calisto_air_brakes_clamp_on,
154-
environment=example_env,
154+
environment=example_plain_env,
155155
rail_length=5.2,
156156
inclination=85,
157157
heading=0,

0 commit comments

Comments
 (0)