def test_formatter_already_set(self): obj = elements.Binding('ident') obj._formatter = 'spam' with pytest.raises(ValueError): obj.formatter('func') assert obj._formatter == 'spam'
def test_set_ident_no_parent(self, mocker): mock_set_ident = mocker.patch.object(elements.Element, 'set_ident') obj = elements.Binding(None) obj.set_ident('ident') mock_set_ident.assert_called_once_with('ident')
def test_formatter_base(self): obj = elements.Binding('ident') result = obj.formatter('func') assert result == 'func' assert obj._formatter == 'func'
def test_format_set(self, mocker): obj = elements.Binding('ident') obj._formatter = mocker.Mock(return_value='string') result = obj.format('controller', 1234) assert result == 'string' obj._formatter.assert_called_once_with('controller', 1234)
def test_validate_unset(self, mocker): inj = mocker.Mock() obj = elements.Binding('ident') result = obj.validate('controller', inj, 'value') assert result == 'value' inj.assert_not_called()
def test_validate_set(self, mocker): inj = mocker.Mock() obj = elements.Binding('ident') obj._validator = 'validator' result = obj.validate('controller', inj, 'value') assert result == inj.return_value inj.assert_called_once_with('validator', 'controller', value='value')
def test_set_ident_conflict(self, mocker): mock_set_ident = mocker.patch.object(elements.Element, 'set_ident') obj = elements.Binding(None) obj.parent = mocker.Mock(bindings='conflict') with pytest.raises(ValueError): obj.set_ident('ident') assert obj.parent.bindings == 'conflict' mock_set_ident.assert_called_once_with('ident')
def test_set_ident_with_parent(self, mocker): mock_set_ident = mocker.patch.object(elements.Element, 'set_ident') obj = elements.Binding(None) obj.parent = mocker.Mock(bindings=None) obj.set_ident('ident') assert obj.parent.bindings == obj mock_set_ident.assert_called_once_with('ident')
def test_validator_already_set(self, mocker): mock_from_func = mocker.patch.object( elements.injector.WantSignature, 'from_func', ) obj = elements.Binding('ident') obj._validator = 'spam' with pytest.raises(ValueError): obj.validator('func') assert obj._validator == 'spam' mock_from_func.assert_not_called()
def test_validator_base(self, mocker): mock_from_func = mocker.patch.object( elements.injector.WantSignature, 'from_func', ) obj = elements.Binding('ident') result = obj.validator('func') assert result == 'func' assert obj._validator == 'func' mock_from_func.assert_called_once_with('func')
def test_init_base(self, mocker): mock_init = mocker.patch.object( elements.Element, '__init__', return_value=None, ) result = elements.Binding('ident') assert result._validator is None assert result._formatter is None mock_init.assert_called_once_with('ident', None)
def test_format_unset(self): obj = elements.Binding('ident') result = obj.format('controller', 1234) assert result == '1234'