From c0933c5757a2f8f7c77d96254b1194230ca3cd11 Mon Sep 17 00:00:00 2001 From: Eneko Martin-Martinez Date: Sat, 23 Dec 2023 12:53:41 +0100 Subject: [PATCH] Add test for dataframe performance --- tests/pytest_pysd/pytest_pysd.py | 37 ++++++++++++++++++++------------ tests/test-models | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/tests/pytest_pysd/pytest_pysd.py b/tests/pytest_pysd/pytest_pysd.py index d0996f97..f68a76ac 100644 --- a/tests/pytest_pysd/pytest_pysd.py +++ b/tests/pytest_pysd/pytest_pysd.py @@ -23,6 +23,8 @@ test_model_data = Path( "test-models/tests/get_data_args_3d_xls/test_get_data_args_3d_xls.mdl") +test_model_query = Path("test-models/samples/Query_file/Query_file.mdl") + more_tests = Path("more-tests") test_model_constant_pipe = more_tests.joinpath( @@ -31,6 +33,7 @@ test_model_stepper = more_tests.joinpath( "stepper_cache/stepper_cache.mdl") + class TestPySD(): @pytest.mark.parametrize("model_path", [test_model]) @@ -964,12 +967,12 @@ def test_set_initial_condition_origin_full(self, model): set_temp = model.components.teacup_temperature() set_time = model.components.time() - assert set_temp != initial_temp,\ + assert set_temp != initial_temp, \ "Test definition is wrong, please change configuration" assert set_temp == 500 - assert initial_time != new_time,\ + assert initial_time != new_time, \ "Test definition is wrong, please change configuration" assert new_time == set_time @@ -992,12 +995,12 @@ def test_set_initial_condition_origin_short(self, model): set_temp = model.components.teacup_temperature() set_time = model.components.time() - assert set_temp != initial_temp,\ + assert set_temp != initial_temp, \ "Test definition is wrong, please change configuration" assert set_temp == 500 - assert initial_time != new_time,\ + assert initial_time != new_time, \ "Test definition is wrong, please change configuration" assert new_time == set_time @@ -1020,12 +1023,12 @@ def test_set_initial_condition_for_stock_component(self, model): set_temp = model.components.teacup_temperature() set_time = model.components.time() - assert set_temp != initial_temp,\ + assert set_temp != initial_temp, \ "Test definition is wrong, please change configuration" assert set_temp == 500 - assert initial_time != 10,\ + assert initial_time != 10, \ "Test definition is wrong, please change configuration" assert set_time == 10 @@ -1087,27 +1090,27 @@ def test_get_args(self, model, args): "Initial Values": { "One Dimensional Subscript": ["Entry 1", "Entry 2", "Entry 3"], - "Second Dimension Subscript":["Column 1", "Column 2"] + "Second Dimension Subscript": ["Column 1", "Column 2"] }, "initial_values": { "One Dimensional Subscript": ["Entry 1", "Entry 2", "Entry 3"], - "Second Dimension Subscript":["Column 1", "Column 2"] + "Second Dimension Subscript": ["Column 1", "Column 2"] }, "Stock A": { "One Dimensional Subscript": ["Entry 1", "Entry 2", "Entry 3"], - "Second Dimension Subscript":["Column 1", "Column 2"] + "Second Dimension Subscript": ["Column 1", "Column 2"] }, "stock_a": { "One Dimensional Subscript": ["Entry 1", "Entry 2", "Entry 3"], - "Second Dimension Subscript":["Column 1", "Column 2"] + "Second Dimension Subscript": ["Column 1", "Column 2"] }, "_integ_stock_a": { "One Dimensional Subscript": ["Entry 1", "Entry 2", "Entry 3"], - "Second Dimension Subscript":["Column 1", "Column 2"] + "Second Dimension Subscript": ["Column 1", "Column 2"] } } ) @@ -1230,7 +1233,7 @@ def test__integrate(self, tmp_path, model): res = model.output.handler.ds assert isinstance(res, dict) assert 'teacup_temperature' in res - assert np.array_equal(res['time'], list(range(0, 5, 2))) + assert np.array_equal(res['time'], np.arange(0, 5, 2)) model.reload() model.time.add_return_timestamps(list(range(0, 5, 2))) @@ -1290,6 +1293,10 @@ def test_files(self, model, model_path, tmp_path): # Check mdl_file assert model.mdl_file == str(path) + @pytest.mark.parametrize("model_path", [test_model_query]) + def test_performance_dataframe(self, model): + model.run() + class TestModelInteraction(): """ The tests in this class test pysd's interaction with itself @@ -1582,6 +1589,7 @@ def test_run_export_import(self, tmp_path, model, return_ts, final_t): if return_ts[2]: assert_frames_close(stocks2, stocks.loc[return_ts[2]]) + class TestStepper(): @pytest.mark.parametrize("model_path", [test_model_stepper]) @@ -1603,7 +1611,7 @@ def test_stepper_cache_assignment(self, model): steps = int((model["final_time"] - model["initial_time"]) / model["time_step"]) - for i in range(1,steps + 1): + for i in range(1, steps+1): model.step(1, {"foo": i}) res = output.collect(model) @@ -1630,5 +1638,6 @@ def test_stepper_workflow(self, model): result_df = output.collect(model) - np.array_equal(result_df["Room Temperature"].values, result_temperatures) + np.array_equal( + result_df["Room Temperature"].values, result_temperatures) assert np.floor(result_df.loc[5, "Teacup Temperature"]) == 144 diff --git a/tests/test-models b/tests/test-models index df9d4316..ac2edbcd 160000 --- a/tests/test-models +++ b/tests/test-models @@ -1 +1 @@ -Subproject commit df9d4316c0453f71d887eeb262695402d32a6d05 +Subproject commit ac2edbcde87aec2dfd8cc338d0574970c549a2d9