Skip to content

Commit

Permalink
Add test for dataframe performance
Browse files Browse the repository at this point in the history
  • Loading branch information
enekomartinmartinez committed Dec 23, 2023
1 parent 3b0ed72 commit c0933c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
37 changes: 23 additions & 14 deletions tests/pytest_pysd/pytest_pysd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -31,6 +33,7 @@
test_model_stepper = more_tests.joinpath(
"stepper_cache/stepper_cache.mdl")


class TestPySD():

@pytest.mark.parametrize("model_path", [test_model])
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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"]
}
}
)
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/test-models

0 comments on commit c0933c5

Please sign in to comment.