Exemple #1
0
    def test_formatter_already_set(self):
        obj = elements.Binding('ident')
        obj._formatter = 'spam'

        with pytest.raises(ValueError):
            obj.formatter('func')
        assert obj._formatter == 'spam'
Exemple #2
0
    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')
Exemple #3
0
    def test_formatter_base(self):
        obj = elements.Binding('ident')

        result = obj.formatter('func')

        assert result == 'func'
        assert obj._formatter == 'func'
Exemple #4
0
    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)
Exemple #5
0
    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()
Exemple #6
0
    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')
Exemple #7
0
    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')
Exemple #8
0
    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')
Exemple #9
0
    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()
Exemple #10
0
    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')
Exemple #11
0
    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)
Exemple #12
0
    def test_format_unset(self):
        obj = elements.Binding('ident')

        result = obj.format('controller', 1234)

        assert result == '1234'