Beispiel #1
0
    def test_len(self, mocker):
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialSet(env, 'var')

        assert len(obj) == 2
Beispiel #2
0
    def test_contains(self, mocker):
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialSet(env, 'var')

        assert 'val' in obj
        assert 'lue' not in obj
Beispiel #3
0
    def test_iter(self, mocker):
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialSet(env, 'var')

        result = set(obj)

        assert result == set(['val', 'ue'])
Beispiel #4
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.SpecialSet(env, 'var')

        obj._update()

        mock_set.assert_called_once_with('ue:val')
Beispiel #5
0
    def test_discard(self, mocker):
        mock_update = mocker.patch.object(
            specials.SpecialSet, '_update',
        )
        env = mocker.Mock(**{
            'get_raw.return_value': 'va:ue:l',
        })
        obj = specials.SpecialSet(env, 'var')

        obj.discard('l')

        assert obj._value == set(['va', 'ue'])
        mock_update.assert_called_once_with()
Beispiel #6
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.SpecialSet(env, 'var')

        obj.delete()

        assert obj._value == set()
        mock_delete.assert_called_once_with()
Beispiel #7
0
    def test_set_iterable(self, mocker):
        mock_update = mocker.patch.object(
            specials.SpecialSet, '_update',
        )
        env = mocker.Mock(**{
            'get_raw.return_value': 'val:ue',
        })
        obj = specials.SpecialSet(env, 'var')

        obj.set(('ue', 'va', 'l'))

        assert obj._value.__class__ == set
        assert obj._value == set(['ue', 'va', 'l'])
        mock_update.assert_called_once_with()
Beispiel #8
0
    def test_init_alt(self, mocker):
        mock_init = mocker.patch.object(
            specials.Special, '__init__',
            return_value=None,
        )
        mocker.patch.object(
            specials.SpecialSet, 'raw', 'val|ue',
        )

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

        assert result._sep == '|'
        assert result._value == set(['val', 'ue'])
        mock_init.assert_called_once_with('env', 'var')
Beispiel #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.SpecialSet, 'raw', raw,
        )

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

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