Skip to content

Commit

Permalink
#359 Add coverage for multiple model runs
Browse files Browse the repository at this point in the history
  • Loading branch information
fcooper8472 committed May 3, 2019
1 parent 3c8bfbf commit db7cf82
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions tests/data_layer/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def results_with_results(results_no_results):
results_no_results._store.write_results(sample_results, 'model_run_1', 'b_model', 2025, 0)
results_no_results._store.write_results(sample_results, 'model_run_1', 'b_model', 2030, 0)

results_no_results._store.write_results(sample_results, 'model_run_2', 'b_model', 2010, 0)
results_no_results._store.write_results(sample_results, 'model_run_2', 'b_model', 2015, 0)
results_no_results._store.write_results(sample_results, 'model_run_2', 'b_model', 2020, 0)
results_no_results._store.write_results(sample_results, 'model_run_2', 'b_model', 2025, 0)
results_no_results._store.write_results(sample_results, 'model_run_2', 'b_model', 2030, 0)

return results_no_results


Expand Down Expand Up @@ -197,6 +203,21 @@ def test_available_results(self, results_with_results):
output_answer_b = {0: [2010, 2015, 2020, 2025, 2030]}
assert outputs_b['sample_output'] == output_answer_b

available = results_with_results.available_results('model_run_2')

assert available['model_run'] == 'model_run_2'
assert available['sos_model'] == 'a_sos_model'

sec_models = available['sector_models']
assert sorted(sec_models.keys()) == ['b_model']

# Check a_model outputs are correct
outputs = sec_models['b_model']['outputs']
assert sorted(outputs_a.keys()) == ['sample_output']

output_answer = {0: [2010, 2015, 2020, 2025, 2030]}
assert outputs['sample_output'] == output_answer

def test_read_validate_names(self, results_with_results):

# Passing anything other than one sector model or output is current not implemented
Expand Down Expand Up @@ -233,10 +254,8 @@ def test_read_validate_names(self, results_with_results):
assert 'requires at least one output name' in str(e.value)

def test_read(self, results_with_results):
# This is difficult to test without fixtures defining an entire canonical project.
# See smif issue #304 (https://github.com/nismod/smif/issues/304).

# should pass validation
# Read one model run and one output
results_data = results_with_results.read(
model_run_names=['model_run_1'],
model_names=['a_model'],
Expand All @@ -256,3 +275,22 @@ def test_read(self, results_with_results):
)

pd.testing.assert_frame_equal(results_data, expected)

# Read two model runs and one output
results_data = results_with_results.read(
model_run_names=['model_run_1', 'model_run_2'],
model_names=['b_model'],
output_names=['sample_output']
)

expected = pd.DataFrame(
OrderedDict([
('model_run', ['model_run_1'] * 10 + ['model_run_2'] * 10),
('timestep', [2010, 2015, 2020, 2025, 2030] * 4),
('decision', 0),
('sample_dim', ['a'] * 5 + ['b'] * 5 + ['a'] * 5 + ['b'] * 5),
('sample_output', 0.0),
])
)

pd.testing.assert_frame_equal(results_data, expected)

0 comments on commit db7cf82

Please sign in to comment.