Skip to content

Commit c140f9e

Browse files
committed
refactor(tests): move test_negative_inputs to unit test
Although it uses Param and Model, it is focussed on testing functionality of Model in detecting invalid parameters, so feels appropriately classified as a unit test
1 parent 3f1d018 commit c140f9e

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

tests/test_functionaltest.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,6 @@
2020
from simulation.model import Param, Model, Runner, MonitoredResource
2121

2222

23-
@pytest.mark.parametrize('param_name, value, rule', [
24-
('patient_inter', 0, 'positive'),
25-
('mean_n_consult_time', 0, 'positive'),
26-
('number_of_runs', 0, 'positive'),
27-
('audit_interval', 0, 'positive'),
28-
('warm_up_period', -1, 'non_negative'),
29-
('data_collection_period', -1, 'non_negative')
30-
])
31-
def test_negative_inputs(param_name, value, rule):
32-
"""
33-
Check that the model fails when inputs that are zero or negative are used.
34-
35-
Arguments:
36-
param_name (string):
37-
Name of parameter to change in the Param() class.
38-
value (float|int):
39-
Invalid value for parameter.
40-
rule (string):
41-
Either 'positive' (if value must be > 0) or 'non-negative' (if
42-
value must be >= 0).
43-
"""
44-
# Create parameter class with an invalid value
45-
param = Param(**{param_name: value})
46-
47-
# Construct the expected error message
48-
if rule == 'positive':
49-
expected_message = f'Parameter "{param_name}" must be greater than 0.'
50-
else:
51-
expected_message = (f'Parameter "{param_name}" must be greater than ' +
52-
'or equal to 0.')
53-
54-
# Verify that initialising the model raises the correct error
55-
with pytest.raises(ValueError, match=expected_message):
56-
Model(param=param, run_number=0)
57-
58-
5923
def test_negative_results():
6024
"""
6125
Check that values are non-negative.

tests/test_unittest.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import pytest
2323

2424
from simulation.logging import SimLogger
25-
from simulation.model import Param, Exponential
25+
from simulation.model import Param, Model, Exponential
2626

2727

2828
def test_new_attribute():
@@ -38,6 +38,42 @@ def test_new_attribute():
3838
param.new_entry = 3
3939

4040

41+
@pytest.mark.parametrize('param_name, value, rule', [
42+
('patient_inter', 0, 'positive'),
43+
('mean_n_consult_time', 0, 'positive'),
44+
('number_of_runs', 0, 'positive'),
45+
('audit_interval', 0, 'positive'),
46+
('warm_up_period', -1, 'non_negative'),
47+
('data_collection_period', -1, 'non_negative')
48+
])
49+
def test_negative_inputs(param_name, value, rule):
50+
"""
51+
Check that the model fails when inputs that are zero or negative are used.
52+
53+
Arguments:
54+
param_name (string):
55+
Name of parameter to change in the Param() class.
56+
value (float|int):
57+
Invalid value for parameter.
58+
rule (string):
59+
Either 'positive' (if value must be > 0) or 'non-negative' (if
60+
value must be >= 0).
61+
"""
62+
# Create parameter class with an invalid value
63+
param = Param(**{param_name: value})
64+
65+
# Construct the expected error message
66+
if rule == 'positive':
67+
expected_message = f'Parameter "{param_name}" must be greater than 0.'
68+
else:
69+
expected_message = (f'Parameter "{param_name}" must be greater than ' +
70+
'or equal to 0.')
71+
72+
# Verify that initialising the model raises the correct error
73+
with pytest.raises(ValueError, match=expected_message):
74+
Model(param=param, run_number=0)
75+
76+
4177
def test_exponentional():
4278
"""
4379
Test that the Exponentional class behaves as expected.

0 commit comments

Comments
 (0)