def test_len(self, mocker): env = mocker.Mock(**{ 'get_raw.return_value': 'k1=v1:k2=v2', }) obj = specials.SpecialOrderedDict(env, 'var') assert len(obj) == 2
def test_getitem(self, mocker): env = mocker.Mock(**{ 'get_raw.return_value': 'k1=v1:k2=v2', }) obj = specials.SpecialOrderedDict(env, 'var') assert obj['k1'] == 'v1' assert obj['k2'] == 'v2'
def test_iter(self, mocker): env = mocker.Mock(**{ 'get_raw.return_value': 'k1=v1:k2=v2', }) obj = specials.SpecialOrderedDict(env, 'var') result = set(obj) assert result == set(['k1', 'k2'])
def test_update(self, mocker): mock_set = mocker.patch.object( specials.Special, 'set', ) env = mocker.Mock(**{ 'get_raw.return_value': 'k3=v3:k2:k1=v1', }) obj = specials.SpecialOrderedDict(env, 'var') obj._update() mock_set.assert_called_once_with('k3=v3:k2:k1=v1')
def test_split(self, mocker): @property def raw(self): raise KeyError('var') mocker.patch.object( specials.SpecialOrderedDict, 'raw', raw, ) obj = specials.SpecialOrderedDict('env', 'var') result = obj._split('k1=v1:k2:k3=v3') assert result.__class__ == collections.OrderedDict assert result == {'k1': 'v1', 'k2': None, 'k3': 'v3'}
def test_delitem(self, mocker): mock_update = mocker.patch.object( specials.SpecialOrderedDict, '_update', ) env = mocker.Mock(**{ 'get_raw.return_value': 'k1=v1:k2=v2:k3=v3', }) obj = specials.SpecialOrderedDict(env, 'var') del obj['k2'] assert obj._value == {'k1': 'v1', 'k3': 'v3'} mock_update.assert_called_once_with()
def test_delete(self, mocker): mock_delete = mocker.patch.object( specials.Special, 'delete', ) env = mocker.Mock(**{ 'get_raw.return_value': 'val:ue', }) obj = specials.SpecialOrderedDict(env, 'var') obj.delete() assert obj._value.__class__ == collections.OrderedDict assert obj._value == {} mock_delete.assert_called_once_with()
def test_set_iterable(self, mocker): mock_update = mocker.patch.object( specials.SpecialOrderedDict, '_update', ) env = mocker.Mock(**{ 'get_raw.return_value': 'k1=v1:k2=v2', }) obj = specials.SpecialOrderedDict(env, 'var') obj.set([('k3', 'v3'), ('k4', 'v4')]) assert obj._value.__class__ == collections.OrderedDict assert obj._value == {'k3': 'v3', 'k4': 'v4'} mock_update.assert_called_once_with()
def test_setitem(self, mocker): mock_update = mocker.patch.object( specials.SpecialOrderedDict, '_update', ) env = mocker.Mock(**{ 'get_raw.return_value': 'k1=v1:k2=v2', }) obj = specials.SpecialOrderedDict(env, 'var') obj['k2'] = 'v3' obj['k3'] = 'v4' assert obj._value == {'k1': 'v1', 'k2': 'v3', 'k3': 'v4'} mock_update.assert_has_calls([mocker.call(), mocker.call()]) assert mock_update.call_count == 2
def test_init_alt(self, mocker): mock_init = mocker.patch.object( specials.Special, '__init__', return_value=None, ) mocker.patch.object( specials.SpecialOrderedDict, 'raw', 'k1/v1|k2/v2', ) result = specials.SpecialOrderedDict('env', 'var', '|', '/') assert result._item_sep == '|' assert result._key_sep == '/' assert result._value == {'k1': 'v1', 'k2': 'v2'} mock_init.assert_called_once_with('env', 'var')
def test_init_base(self, mocker): mock_init = mocker.patch.object( specials.Special, '__init__', return_value=None, ) mocker.patch.object( specials.SpecialOrderedDict, 'raw', 'k1=v1:k2=v2', ) result = specials.SpecialOrderedDict('env', 'var') assert result._item_sep == os.pathsep assert result._key_sep == '=' assert result._value == {'k1': 'v1', 'k2': 'v2'} mock_init.assert_called_once_with('env', 'var')
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.SpecialOrderedDict, 'raw', raw, ) result = specials.SpecialOrderedDict('env', 'var') assert result._item_sep == os.pathsep assert result._key_sep == '=' assert result._value.__class__ == collections.OrderedDict assert result._value == {} mock_init.assert_called_once_with('env', 'var')