2 from functools
import partial
4 import refractor.factory.creator
as creator
5 import refractor.factory.param
as param
6 from refractor.factory
import process_config
8 from refractor
import framework
as rf
11 class ReturnCreatorHelper(creator.base.Creator):
12 val = param_type(**kwargs)
13 def create(self, **kwargs):
14 return self.param(
"val")
16 return ReturnCreatorHelper
38 assert config_inst == 10
41 config_def[
'val'] = np.arange(1,6)
45 except param.ParamError:
60 assert config_inst ==
"10" 63 config_def[
'val'] = 10
67 except param.ParamError:
77 'val': np.arange(1,6),
82 assert np.all(config_inst == np.array([1,2,3,4,5]))
85 config_def[
'val'] = 10
89 except param.ParamError:
94 config_def[
'val'] = [1,2,3,4,5]
98 except param.ParamError:
108 'val': rf.ArrayWithUnit_double_1(np.arange(1,6),
"m"),
130 assert np.all(np.array(config_inst[
'item1']) == np.arange(1,6))
131 assert np.all(np.array(config_inst[
'item2']) == np.arange(1,6))
134 config_def[
'item1'][
'val'] = np.arange(1,6)
138 assert np.all(np.array(config_inst[
'item1']) == np.arange(1,6))
142 class TestClass(object):
153 assert isinstance(config_inst, TestClass)
156 config_def[
'val'] = 5
160 except param.ParamError:
169 'val':
lambda **kwargs: 10,
174 assert config_inst == 10
198 assert config_inst[
'item1'] == 5
199 assert config_inst[
'item2'] == 10
200 assert config_inst[
'item3'] == 15
205 'order': [
'common',
'use_common'],
207 'creator': creator.base.SaveToCommon,
212 'creator': AddCreator,
218 assert config_inst[
'use_common'] == 11
222 class ChoiceCreator(creator.base.Creator):
223 some_val = param.Choice(param.Scalar(int), param.Scalar(float))
225 def create(self, **kwargs):
226 return self.param(
"some_val")
230 'creator': ChoiceCreator,
234 'creator': ChoiceCreator,
241 assert config_inst[
'item1'] == 10
242 assert config_inst[
'item2'] == 5.0
244 config_def[
'item1'][
'some_val'] =
"ABC" 248 except param.ParamError:
255 class BoundParamCreator(creator.base.Creator):
256 some_val = param.Choice(param.Scalar(int), param.Scalar(int))
258 def create(self, **kwargs):
259 return self.some_val()
263 'creator': BoundParamCreator,
267 'creator': BoundParamCreator,
274 assert config_inst[
'item1'] == 10
275 assert config_inst[
'item2'] == 5
282 'val': rf.vector_double(),
286 'val': rf.vector_double(),
292 assert isinstance(config_inst[
'item1'], rf.vector_double)
293 assert isinstance(config_inst[
'item2'], rf.vector_double)
def test_array_with_unit_param()
def test_iterable_param()
def test_scalar_with_type()
def ParamReturnCreator(param_type, kwargs)
def test_instanceof_param()
def process_config(config_def)