Skip to content

Commit

Permalink
TST: fixes warnings in problematic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-FernandesBR committed Jun 16, 2024
1 parent e4ce81d commit 00bf148
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 32 deletions.
110 changes: 100 additions & 10 deletions tests/fixtures/monte_carlo/example.inputs.txt

Large diffs are not rendered by default.

110 changes: 100 additions & 10 deletions tests/fixtures/monte_carlo/example.outputs.txt

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions tests/fixtures/monte_carlo/monte_carlo_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ def monte_carlo_calisto(stochastic_environment, stochastic_calisto, stochastic_f
rocket=stochastic_calisto,
flight=stochastic_flight,
)


@pytest.fixture
def monte_carlo_calisto_pre_loaded(
stochastic_environment, stochastic_calisto, stochastic_flight
):
"""Creates a MonteCarlo object with some already imported simulations."""
monte_carlo = MonteCarlo(
filename="monte_carlo_test",
environment=stochastic_environment,
rocket=stochastic_calisto,
flight=stochastic_flight,
)
monte_carlo.import_results(
filename="tests/fixtures/monte_carlo/example.outputs.txt"
)
return monte_carlo
1 change: 1 addition & 0 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def test_gefs_atmosphere(mock_show, example_spaceport_env):
assert example_spaceport_env.all_info() == None


@pytest.mark.skip(reason="legacy tests") # deprecated method
@patch("matplotlib.pyplot.show")
def test_info_returns(mock_show, example_plain_env):
"""Tests the all_info_returned() all_plot_info_returned() and methods of the
Expand Down
3 changes: 1 addition & 2 deletions tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def test_setters(func_from_csv, func_2d_from_csv):
assert func_2d_from_csv.get_outputs() == ["Scalar3"]
func_2d_from_csv.set_interpolation("shepard")
assert func_2d_from_csv.get_interpolation_method() == "shepard"
func_2d_from_csv.set_extrapolation("zero")
# 2d functions do not support zero extrapolation, must change to natural
func_2d_from_csv.set_extrapolation("natural")
assert func_2d_from_csv.get_extrapolation_method() == "natural"


Expand Down
18 changes: 9 additions & 9 deletions tests/test_monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_monte_carlo_set_inputs_log(monte_carlo_calisto):
"""
monte_carlo_calisto.input_file = "tests/fixtures/monte_carlo/example.inputs.txt"
monte_carlo_calisto.set_inputs_log()
assert len(monte_carlo_calisto.inputs_log) == 10
assert len(monte_carlo_calisto.inputs_log) == 100
assert all(isinstance(item, dict) for item in monte_carlo_calisto.inputs_log)
assert all(
"gravity" in item and "elevation" in item
Expand All @@ -125,7 +125,7 @@ def test_monte_carlo_set_outputs_log(monte_carlo_calisto):
"""
monte_carlo_calisto.output_file = "tests/fixtures/monte_carlo/example.outputs.txt"
monte_carlo_calisto.set_outputs_log()
assert len(monte_carlo_calisto.outputs_log) == 10
assert len(monte_carlo_calisto.outputs_log) == 100
assert all(isinstance(item, dict) for item in monte_carlo_calisto.outputs_log)
assert all(
"apogee" in item and "impact_velocity" in item
Expand All @@ -145,24 +145,24 @@ def test_monte_carlo_prints(monte_carlo_calisto):


@patch("matplotlib.pyplot.show")
def test_monte_carlo_plots(mock_show, monte_carlo_calisto):
def test_monte_carlo_plots(mock_show, monte_carlo_calisto_pre_loaded):
"""Tests the plots methods of the MonteCarlo class."""
assert monte_carlo_calisto.all_info() is None
assert monte_carlo_calisto_pre_loaded.all_info() is None


def test_monte_carlo_export_ellipses_to_kml(monte_carlo_calisto):
def test_monte_carlo_export_ellipses_to_kml(monte_carlo_calisto_pre_loaded):
"""Tests the export_ellipses_to_kml method of the MonteCarlo class.
Parameters
----------
monte_carlo_calisto : MonteCarlo
monte_carlo_calisto_pre_loaded : MonteCarlo
The MonteCarlo object, this is a pytest fixture.
"""
assert (
monte_carlo_calisto.export_ellipses_to_kml(
monte_carlo_calisto_pre_loaded.export_ellipses_to_kml(
filename="monte_carlo_class_example.kml",
origin_lat=32,
origin_lon=-104,
origin_lat=32.990254,
origin_lon=-106.974998,
type="impact",
)
is None
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def test_savetxt(request, func):
), "Couldn't save the file using the Function.savetxt method."

read_func = Function(
"test_func.csv", interpolation="linear", extrapolation="natural"
"test_func.csv",
interpolation="linear" if func.get_domain_dim() == 1 else "shepard",
extrapolation="natural",
)
if callable(func.source):
source = np.column_stack(
Expand Down

0 comments on commit 00bf148

Please sign in to comment.