-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_parameter.py
44 lines (34 loc) · 1.6 KB
/
test_parameter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pytest
from components.parameter import IntegerParameter, FloatParameter, BooleanParameter, Parameter
class TestParameters:
def test_create_parameters(self):
make_int_param = Parameter(1, 0, 10)
make_int_value_param = Parameter(1)
make_float_param = Parameter(1.0, 0.0, 10.0)
make_bool_param = Parameter(True)
assert isinstance(make_int_param.value, IntegerParameter)
assert isinstance(make_int_value_param.value, IntegerParameter)
assert isinstance(make_float_param.value, FloatParameter)
assert isinstance(make_bool_param.value, BooleanParameter)
def test_initialize_parameters(self):
int_param = IntegerParameter(1, 0, 10)
float_param = FloatParameter(1.0, 0.0, 10.0)
bool_param = BooleanParameter(True)
assert int_param.value == 1
assert int_param.min_value == 0
assert int_param.max_value == 10
assert float_param.value == 1.0
assert float_param.min_value == 0.0
assert float_param.max_value == 10.0
assert bool_param.value == True
with pytest.raises(ValueError):
bad_int_param = IntegerParameter(11, 0, 10)
bad_float_param = FloatParameter(11.0, 0.0, 10.0)
bad_bool_param = BooleanParameter(1)
def test_params_str(self):
int_param = IntegerParameter(1, 0, 10)
int_param.name = 'int_param'
bool_param = BooleanParameter(True)
bool_param.name = 'bool_param'
assert str(int_param) == 'int_param : 1 (min_value=0, max_value=10)'
assert str(bool_param) == 'bool_param : True'