Commit d583db67 authored by David Trudgian's avatar David Trudgian
Browse files

Don't test load twice

parent f7c1af04
import os
import pytest
from runner.param import ParamFile, ParamFileException, IntRange, RealRange, ChoiceRange
from runner.param import ParamFile, ParamFileException, IntRange, RealRange, \
ChoiceRange
class TestParams:
class TestParams:
def test_validate(self):
md = ParamFile(os.path.dirname(os.path.abspath(__file__)) + '/test_data/test_params.yaml')
md = ParamFile(os.path.dirname(
os.path.abspath(__file__)) + '/test_data/test_params.yaml')
assert md.validate()
def test_validate_exception(self):
md = ParamFile(os.path.dirname(os.path.abspath(__file__)) + '/test_data/test_params_invalid.yaml')
md = ParamFile(os.path.dirname(
os.path.abspath(__file__)) + '/test_data/test_params_invalid.yaml')
with pytest.raises(ParamFileException):
md.validate()
def test_load(self):
md = ParamFile(os.path.dirname(os.path.abspath(__file__)) + '/test_data/test_params.yaml')
md.load()
assert md.vals
md = ParamFile(os.path.dirname(
os.path.abspath(__file__)) + '/test_data/test_params.yaml')
md.load()
assert md.vals
# IMPLICIT md.compute_param_ranges()
# min: 0
# max: 32
# step: 2
assert md.vals['parameters'][0]['range'] == range(0, 32 + 1, 2)
# optional: true
# min: 0.1
# max: 100
# scale: 10
assert md.vals['parameters'][1]['range'] == [None, 0.1, 1.0, 10.0,
100.0]
# values:
# - step
# - sigmoid
assert md.vals['parameters'][2]['range'] == ['step', 'sigmoid']
def test_int_range_single(self):
ir = IntRange({'id': 'test', 'min': 0, 'max': 5})
assert ir.to_list() == [0, 1, 2, 3, 4 ,5]
assert ir.to_list() == [0, 1, 2, 3, 4, 5]
def test_int_range_step(self):
ir = IntRange({'id': 'test', 'min': 0, 'max': 10, 'step': 2})
......@@ -32,17 +52,17 @@ class TestParams:
assert ir.to_list() == [1, 10, 100, 1000, 10000]
def test_int_range_step_scale(self):
ir = IntRange({'id': 'test', 'min': 0, 'max': 10000, 'scale': 10, 'step': 9})
ir = IntRange(
{'id': 'test', 'min': 0, 'max': 10000, 'scale': 10, 'step': 9})
assert ir.to_list() == [0, 9, 99, 999, 9999]
def test_int_range_optional(self):
ir = IntRange({'id': 'test', 'min': 0, 'max': 5, 'optional': True})
assert ir.to_list() == [None, 0, 1, 2, 3, 4 ,5]
assert ir.to_list() == [None, 0, 1, 2, 3, 4, 5]
def test_real_range_single(self):
rr = RealRange({'id': 'test', 'min': 0.1, 'max': 5.1})
assert rr.to_list() == pytest.approx([0.1, 1.1, 2.1, 3.1, 4.1 ,5.1])
assert rr.to_list() == pytest.approx([0.1, 1.1, 2.1, 3.1, 4.1, 5.1])
def test_real_range_step(self):
rr = RealRange({'id': 'test', 'min': 0.1, 'max': 4.9, 'step': 1.2})
......@@ -53,35 +73,22 @@ class TestParams:
assert rr.to_list() == pytest.approx([0.001, 0.01, 0.1, 1.0, 10.0])
def test_real_range_step_scale(self):
rr = RealRange({'id': 'test', 'min': 0.001, 'max': 1000.0, 'scale': 10, 'step': 0.2})
rr = RealRange({'id': 'test', 'min': 0.001, 'max': 1000.0, 'scale': 10,
'step': 0.2})
assert rr.to_list() == pytest.approx([0.001, 0.21, 2.3, 23.2, 232.2])
def test_real_range_optional(self):
rr = RealRange({'id': 'test', 'min': 0.001, 'max': 10.0, 'scale': 10, 'optional': True })
assert rr.to_list() == pytest.approx([None, 0.001, 0.01, 0.1, 1.0, 10.0])
rr = RealRange({'id': 'test', 'min': 0.001, 'max': 10.0, 'scale': 10,
'optional': True})
assert rr.to_list() == pytest.approx(
[None, 0.001, 0.01, 0.1, 1.0, 10.0])
def test_choice(self):
cr = ChoiceRange({'id': 'test', 'values': ['One', 'Two', 'Three'] })
cr = ChoiceRange({'id': 'test', 'values': ['One', 'Two', 'Three']})
assert cr.to_list() == ['One', 'Two', 'Three']
def test_choice_optional(self):
cr = ChoiceRange({'id': 'test', 'values': ['One', 'Two', 'Three'], 'optional': 'true' })
cr = ChoiceRange({'id': 'test', 'values': ['One', 'Two', 'Three'],
'optional': 'true'})
assert cr.to_list() == [None, 'One', 'Two', 'Three']
def test_compute_ranges(self):
md = ParamFile(os.path.dirname(os.path.abspath(__file__)) + '/test_data/test_params.yaml')
md.load()
# IMPLICIT md.compute_param_ranges()
# min: 0
# max: 32
# step: 2
assert md.vals['parameters'][0]['range'] == range(0, 32+1, 2)
# optional: true
# min: 0.1
# max: 100
# scale: 10
assert md.vals['parameters'][1]['range'] == [None, 0.1, 1.0, 10.0, 100.0]
# values:
# - step
# - sigmoid
assert md.vals['parameters'][2]['range'] == ['step', 'sigmoid']
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment