def test_raw_value(self): param = Parameter(name='test', default=[1, 2, 3, 4]) # Normal case assert (param._raw_value == param.value).all() # Bad setter param._setter = True param._internal_value = 4 assert param._raw_value == 4
def test_model(self): param = Parameter(name='test', default=[1, 2, 3, 4]) assert param.model == None == param._model assert param._model_required == False assert (param._value == [1, 2, 3, 4]).all() setter = mk.MagicMock() getter = mk.MagicMock() param._setter = setter param._getter = getter # No Model Required param._value = [5, 6, 7, 8] model0 = mk.MagicMock() setter0 = mk.MagicMock() getter0 = mk.MagicMock() with mk.patch.object(Parameter, '_create_value_wrapper', side_effect=[setter0, getter0]) as mkCreate: param.model = model0 assert param.model == model0 == param._model assert param._setter == setter0 assert param._getter == getter0 assert mkCreate.call_args_list == [ mk.call(setter, model0), mk.call(getter, model0) ] assert param._value == [5, 6, 7, 8] param._setter = setter param._getter = getter # Model required param._model_required = True model1 = mk.MagicMock() setter1 = mk.MagicMock() getter1 = mk.MagicMock() setter1.return_value = [9, 10, 11, 12] getter1.return_value = [9, 10, 11, 12] with mk.patch.object(Parameter, '_create_value_wrapper', side_effect=[setter1, getter1]) as mkCreate: param.model = model1 assert param.model == model1 == param._model assert param._setter == setter1 assert param._getter == getter1 assert mkCreate.call_args_list == [ mk.call(setter, model1), mk.call(getter, model1) ] assert (param.value == [9, 10, 11, 12]).all() param._setter = setter param._getter = getter param._default = None with mk.patch.object(Parameter, '_create_value_wrapper', side_effect=[setter1, getter1]) as mkCreate: param.model = model1 assert param.model == model1 == param._model assert param._setter == setter1 assert param._getter == getter1 assert mkCreate.call_args_list == [ mk.call(setter, model1), mk.call(getter, model1) ] assert param._value is None