Skip to content

Commit

Permalink
TST: refactors environment.set_date test
Browse files Browse the repository at this point in the history
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
TST: fixes example_plain_env legacy references
TST: Rollback teardown logic in unit env test
  • Loading branch information
GabrielBarberini committed Mar 7, 2024
1 parent 65b3315 commit 3894504
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 215 deletions.
2 changes: 1 addition & 1 deletion rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3696,7 +3696,7 @@ def decimal_degrees_to_arc_seconds(angle):
-------
degrees : float
The degrees.
arc_minutes : float
arc_minutes : int
The arc minutes. 1 arc-minute = (1/60)*degree
arc_seconds : float
The arc Seconds. 1 arc-second = (1/3600)*degree
Expand Down
43 changes: 20 additions & 23 deletions tests/fixtures/environment/environment_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,55 @@
import datetime

import pytest

from datetime import datetime, timedelta
from rocketpy import Environment, EnvironmentAnalysis


@pytest.fixture
def example_env():
"""Create a simple object of the Environment class to be used in the tests.
This allows to avoid repeating the same code in all tests. The environment
set here is the simplest possible, with no parameters set.
def example_plain_env():
"""Simple object of the Environment class to be used in the tests.
Returns
-------
rocketpy.Environment
The simplest object of the Environment class
"""
return Environment()


@pytest.fixture
def example_env_robust():
"""Create an object of the Environment class to be used in the tests. This
allows to avoid repeating the same code in all tests. The environment set
here is a bit more complex than the one in the example_env fixture. This
time the latitude, longitude and elevation are set, as well as the datum and
the date. The location refers to the Spaceport America Cup launch site,
while the date is set to tomorrow at noon.
def example_date_naive():
"""Naive tomorrow date
Returns
-------
datetime.datetime
"""
return datetime.now() + timedelta(days=1)


@pytest.fixture
def example_spaceport_env(example_date_naive):
"""Environment class with location set to Spaceport America Cup launch site
Returns
-------
rocketpy.Environment
An object of the Environment class
"""
env = Environment(
spaceport_env = Environment(
latitude=32.990254,
longitude=-106.974998,
elevation=1400,
datum="WGS84",
)
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))
return env
spaceport_env.set_date(example_date_naive)
return spaceport_env


@pytest.fixture
def env_analysis():
"""Create a simple object of the Environment Analysis class to be used in
the tests. This allows to avoid repeating the same code in all tests.
"""Environment Analysis class with hardcoded parameters
Returns
-------
EnvironmentAnalysis
A simple object of the Environment Analysis class
"""
env_analysis = EnvironmentAnalysis(
start_date=datetime.datetime(2019, 10, 23),
Expand Down
30 changes: 15 additions & 15 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 All @@ -62,7 +62,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):


@pytest.fixture
def flight_calisto_robust(calisto_robust, example_env_robust):
def flight_calisto_robust(calisto_robust, example_spaceport_env):
"""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 fixture. This time the latitude,
Expand All @@ -74,7 +74,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
----------
calisto_robust : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env_robust : rocketpy.Environment
example_spaceport_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
Expand All @@ -84,7 +84,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
condition.
"""
return Flight(
environment=example_env_robust,
environment=example_spaceport_env,
rocket=calisto_robust,
rail_length=5.2,
inclination=85,
Expand All @@ -94,7 +94,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):


@pytest.fixture
def flight_calisto_custom_wind(calisto_robust, example_env_robust):
def flight_calisto_custom_wind(calisto_robust, example_spaceport_env):
"""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
Expand All @@ -104,15 +104,15 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):
----------
calisto_robust : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env_robust : rocketpy.Environment
example_spaceport_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
-------
rocketpy.Flight
"""
env = example_env_robust
env = example_spaceport_env
env.set_atmospheric_model(
type="custom_atmosphere",
temperature=300,
Expand All @@ -130,7 +130,7 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):


@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
Loading

0 comments on commit 3894504

Please sign in to comment.