Exemplo n.º 1
0
    def test_len(self, mocker):
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialList(env, 'var')

        assert len(obj) == 2
Exemplo n.º 2
0
    def test_getitem(self, mocker):
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialList(env, 'var')

        assert obj[0] == 'val'
        assert obj[1] == 'ue'
Exemplo n.º 3
0
    def test_update(self, mocker):
        mock_set = mocker.patch.object(
            specials.Special, 'set',
        )
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialList(env, 'var')

        obj._update()

        mock_set.assert_called_once_with('val:ue')
Exemplo n.º 4
0
    def test_insert(self, mocker):
        mock_update = mocker.patch.object(
            specials.SpecialList, '_update',
        )
        env = mocker.Mock(**{
            'get_raw.return_value': 'va:ue',
        })
        obj = specials.SpecialList(env, 'var')

        obj.insert(1, 'l')

        assert obj._value == ['va', 'l', 'ue']
        mock_update.assert_called_once_with()
Exemplo n.º 5
0
    def test_delete(self, mocker):
        mock_delete = mocker.patch.object(
            specials.Special, 'delete',
        )
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialList(env, 'var')

        obj.delete()

        assert obj._value == []
        mock_delete.assert_called_once_with()
Exemplo n.º 6
0
    def test_init_alt(self, mocker):
        mock_init = mocker.patch.object(
            specials.Special, '__init__',
            return_value=None,
        )
        mocker.patch.object(
            specials.SpecialList, 'raw', 'val|ue',
        )

        result = specials.SpecialList('env', 'var', '|')

        assert result._sep == '|'
        assert result._value == ['val', 'ue']
        mock_init.assert_called_once_with('env', 'var')
Exemplo n.º 7
0
    def test_set_iterable(self, mocker):
        mock_update = mocker.patch.object(
            specials.SpecialList, '_update',
        )
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialList(env, 'var')

        obj.set(('ue', 'val'))

        assert obj._value.__class__ == list
        assert obj._value == ['ue', 'val']
        mock_update.assert_called_once_with()
Exemplo n.º 8
0
    def test_setitem(self, mocker):
        mock_update = mocker.patch.object(
            specials.SpecialList, '_update',
        )
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialList(env, 'var')

        obj[0] = 'ue'
        obj[1] = 'val'

        assert obj._value == ['ue', 'val']
        mock_update.assert_has_calls([mocker.call(), mocker.call()])
        assert mock_update.call_count == 2
Exemplo n.º 9
0
    def test_init_keyerror(self, mocker):
        @property
        def raw(self):
            raise KeyError('var')
        mock_init = mocker.patch.object(
            specials.Special, '__init__',
            return_value=None,
        )
        mocker.patch.object(
            specials.SpecialList, 'raw', raw,
        )

        result = specials.SpecialList('env', 'var')

        assert result._sep == os.pathsep
        assert result._value == []
        mock_init.assert_called_once_with('env', 'var')