Skip to content

Commit c6cbc90

Browse files
CopilotaZira371
andcommitted
Refactor 3DOF fixtures to flight_fixtures.py and reuse existing environment fixture
Co-authored-by: aZira371 <99824864+aZira371@users.noreply.github.com>
1 parent 1dfd06e commit c6cbc90

File tree

2 files changed

+123
-115
lines changed

2 files changed

+123
-115
lines changed

tests/acceptance/test_3dof_flight.py

Lines changed: 11 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
1515
Note: These tests are designed for the 3 DOF feature implemented in issue #882.
1616
They will be skipped until PointMassMotor and PointMassRocket are available.
17+
All fixtures are defined in tests/fixtures/flight/flight_fixtures.py.
1718
"""
1819

1920
import numpy as np
2021
import pytest
2122

22-
from rocketpy import Environment, Flight
23+
from rocketpy import Flight
2324

2425
# Try to import 3DOF-specific classes, skip tests if not available
2526
try:
@@ -29,8 +30,6 @@
2930
THREEDOF_AVAILABLE = True
3031
except ImportError:
3132
THREEDOF_AVAILABLE = False
32-
PointMassMotor = None
33-
PointMassRocket = None
3433

3534
# Skip all tests in this module if 3DOF is not available
3635
pytestmark = pytest.mark.skipif(
@@ -40,109 +39,6 @@
4039
)
4140

4241

43-
@pytest.fixture
44-
def acceptance_environment():
45-
"""Create a realistic environment for acceptance testing.
46-
47-
Returns
48-
-------
49-
rocketpy.Environment
50-
An environment with realistic atmospheric conditions.
51-
"""
52-
env = Environment(
53-
gravity=9.81,
54-
latitude=32.99,
55-
longitude=-106.975,
56-
elevation=1400,
57-
)
58-
# Use standard atmosphere
59-
env.set_atmospheric_model(type="standard_atmosphere")
60-
env.max_expected_height = 3000
61-
return env
62-
63-
64-
@pytest.fixture
65-
def acceptance_point_mass_motor():
66-
"""Create a realistic point mass motor for acceptance testing.
67-
68-
Returns
69-
-------
70-
rocketpy.PointMassMotor
71-
A point mass motor with realistic thrust and mass properties.
72-
"""
73-
return PointMassMotor(
74-
thrust_source=1500, # 1500 N constant thrust
75-
dry_mass=2.5, # 2.5 kg dry mass
76-
propellant_initial_mass=3.0, # 3.0 kg propellant
77-
burn_time=3.5, # 3.5 s burn time
78-
)
79-
80-
81-
@pytest.fixture
82-
def acceptance_point_mass_rocket(acceptance_point_mass_motor):
83-
"""Create a realistic point mass rocket for acceptance testing.
84-
85-
Parameters
86-
----------
87-
acceptance_point_mass_motor : rocketpy.PointMassMotor
88-
The motor to be added to the rocket.
89-
90-
Returns
91-
-------
92-
rocketpy.PointMassRocket
93-
A point mass rocket with realistic dimensions and properties.
94-
"""
95-
rocket = PointMassRocket(
96-
radius=0.0635, # 127 mm diameter (5 inches)
97-
mass=5.0, # 5 kg without motor
98-
center_of_mass_without_motor=0.5,
99-
power_off_drag=0.45,
100-
power_on_drag=0.50,
101-
)
102-
rocket.add_motor(acceptance_point_mass_motor, position=0)
103-
return rocket
104-
105-
106-
@pytest.fixture
107-
def flight_3dof_no_weathercock(acceptance_environment, acceptance_point_mass_rocket):
108-
"""Create a 3 DOF flight without weathercocking.
109-
110-
Returns
111-
-------
112-
rocketpy.Flight
113-
A 3 DOF flight simulation with weathercock_coeff=0.0.
114-
"""
115-
return Flight(
116-
rocket=acceptance_point_mass_rocket,
117-
environment=acceptance_environment,
118-
rail_length=5.0,
119-
inclination=85, # 85 degrees from horizontal (5 degrees from vertical)
120-
heading=0,
121-
simulation_mode="3 DOF",
122-
weathercock_coeff=0.0,
123-
)
124-
125-
126-
@pytest.fixture
127-
def flight_3dof_with_weathercock(acceptance_environment, acceptance_point_mass_rocket):
128-
"""Create a 3 DOF flight with weathercocking enabled.
129-
130-
Returns
131-
-------
132-
rocketpy.Flight
133-
A 3 DOF flight simulation with weathercock_coeff=1.0.
134-
"""
135-
return Flight(
136-
rocket=acceptance_point_mass_rocket,
137-
environment=acceptance_environment,
138-
rail_length=5.0,
139-
inclination=85,
140-
heading=0,
141-
simulation_mode="3 DOF",
142-
weathercock_coeff=1.0,
143-
)
144-
145-
14642
def test_3dof_flight_basic_trajectory(flight_3dof_no_weathercock):
14743
"""Test that 3 DOF flight produces reasonable trajectory.
14844
@@ -452,23 +348,23 @@ def test_3dof_flight_thrust_profile(flight_3dof_no_weathercock):
452348

453349

454350
def test_3dof_flight_reproducibility(
455-
acceptance_environment, acceptance_point_mass_rocket
351+
example_spaceport_env, acceptance_point_mass_rocket
456352
):
457353
"""Test that 3 DOF flights are reproducible.
458354
459355
Running the same simulation multiple times should produce identical results.
460356
461357
Parameters
462358
----------
463-
acceptance_environment : rocketpy.Environment
464-
Environment fixture for testing.
359+
example_spaceport_env : rocketpy.Environment
360+
Environment fixture for Spaceport America.
465361
acceptance_point_mass_rocket : rocketpy.PointMassRocket
466362
Rocket fixture for testing.
467363
"""
468364
# Run simulation twice with same parameters
469365
flight1 = Flight(
470366
rocket=acceptance_point_mass_rocket,
471-
environment=acceptance_environment,
367+
environment=example_spaceport_env,
472368
rail_length=5.0,
473369
inclination=85,
474370
heading=0,
@@ -478,7 +374,7 @@ def test_3dof_flight_reproducibility(
478374

479375
flight2 = Flight(
480376
rocket=acceptance_point_mass_rocket,
481-
environment=acceptance_environment,
377+
environment=example_spaceport_env,
482378
rail_length=5.0,
483379
inclination=85,
484380
heading=0,
@@ -499,7 +395,7 @@ def test_3dof_flight_reproducibility(
499395

500396

501397
def test_3dof_flight_different_weathercock_coefficients(
502-
acceptance_environment, acceptance_point_mass_rocket
398+
example_spaceport_env, acceptance_point_mass_rocket
503399
):
504400
"""Test 3 DOF flight with various weathercock coefficients.
505401
@@ -508,8 +404,8 @@ def test_3dof_flight_different_weathercock_coefficients(
508404
509405
Parameters
510406
----------
511-
acceptance_environment : rocketpy.Environment
512-
Environment fixture for testing.
407+
example_spaceport_env : rocketpy.Environment
408+
Environment fixture for Spaceport America.
513409
acceptance_point_mass_rocket : rocketpy.PointMassRocket
514410
Rocket fixture for testing.
515411
"""
@@ -519,7 +415,7 @@ def test_3dof_flight_different_weathercock_coefficients(
519415
for coeff in coefficients:
520416
flight = Flight(
521417
rocket=acceptance_point_mass_rocket,
522-
environment=acceptance_environment,
418+
environment=example_spaceport_env,
523419
rail_length=5.0,
524420
inclination=85,
525421
heading=0,

tests/fixtures/flight/flight_fixtures.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,115 @@ def flight_flat(example_plain_env, cesaroni_m1670):
361361
inclination=85,
362362
heading=0,
363363
)
364+
365+
366+
# 3 DOF Flight Fixtures
367+
# These fixtures are for testing the 3 DOF flight simulation mode
368+
# They will be available when PointMassMotor and PointMassRocket are implemented
369+
370+
try:
371+
from rocketpy.motors.point_mass_motor import PointMassMotor
372+
from rocketpy.rocket.point_mass_rocket import PointMassRocket
373+
374+
THREEDOF_AVAILABLE = True
375+
except ImportError:
376+
THREEDOF_AVAILABLE = False
377+
PointMassMotor = None
378+
PointMassRocket = None
379+
380+
381+
if THREEDOF_AVAILABLE:
382+
383+
@pytest.fixture
384+
def acceptance_point_mass_motor():
385+
"""Create a realistic point mass motor for acceptance testing.
386+
387+
Returns
388+
-------
389+
rocketpy.PointMassMotor
390+
A point mass motor with realistic thrust and mass properties.
391+
"""
392+
return PointMassMotor(
393+
thrust_source=1500, # 1500 N constant thrust
394+
dry_mass=2.5, # 2.5 kg dry mass
395+
propellant_initial_mass=3.0, # 3.0 kg propellant
396+
burn_time=3.5, # 3.5 s burn time
397+
)
398+
399+
@pytest.fixture
400+
def acceptance_point_mass_rocket(acceptance_point_mass_motor):
401+
"""Create a realistic point mass rocket for acceptance testing.
402+
403+
Parameters
404+
----------
405+
acceptance_point_mass_motor : rocketpy.PointMassMotor
406+
The motor to be added to the rocket.
407+
408+
Returns
409+
-------
410+
rocketpy.PointMassRocket
411+
A point mass rocket with realistic dimensions and properties.
412+
"""
413+
rocket = PointMassRocket(
414+
radius=0.0635, # 127 mm diameter (5 inches)
415+
mass=5.0, # 5 kg without motor
416+
center_of_mass_without_motor=0.5,
417+
power_off_drag=0.45,
418+
power_on_drag=0.50,
419+
)
420+
rocket.add_motor(acceptance_point_mass_motor, position=0)
421+
return rocket
422+
423+
@pytest.fixture
424+
def flight_3dof_no_weathercock(example_spaceport_env, acceptance_point_mass_rocket):
425+
"""Create a 3 DOF flight without weathercocking.
426+
427+
Parameters
428+
----------
429+
example_spaceport_env : rocketpy.Environment
430+
Environment fixture for Spaceport America.
431+
acceptance_point_mass_rocket : rocketpy.PointMassRocket
432+
Point mass rocket fixture.
433+
434+
Returns
435+
-------
436+
rocketpy.Flight
437+
A 3 DOF flight simulation with weathercock_coeff=0.0.
438+
"""
439+
return Flight(
440+
rocket=acceptance_point_mass_rocket,
441+
environment=example_spaceport_env,
442+
rail_length=5.0,
443+
inclination=85, # 85 degrees from horizontal (5 degrees from vertical)
444+
heading=0,
445+
simulation_mode="3 DOF",
446+
weathercock_coeff=0.0,
447+
)
448+
449+
@pytest.fixture
450+
def flight_3dof_with_weathercock(
451+
example_spaceport_env, acceptance_point_mass_rocket
452+
):
453+
"""Create a 3 DOF flight with weathercocking enabled.
454+
455+
Parameters
456+
----------
457+
example_spaceport_env : rocketpy.Environment
458+
Environment fixture for Spaceport America.
459+
acceptance_point_mass_rocket : rocketpy.PointMassRocket
460+
Point mass rocket fixture.
461+
462+
Returns
463+
-------
464+
rocketpy.Flight
465+
A 3 DOF flight simulation with weathercock_coeff=1.0.
466+
"""
467+
return Flight(
468+
rocket=acceptance_point_mass_rocket,
469+
environment=example_spaceport_env,
470+
rail_length=5.0,
471+
inclination=85,
472+
heading=0,
473+
simulation_mode="3 DOF",
474+
weathercock_coeff=1.0,
475+
)

0 commit comments

Comments
 (0)