def test_index(self): instance = QSO("foo=bar&baz=diz") assert instance.index('foo=bar') == 0 assert instance.index('baz=diz') == 1 with pytest.raises(ValueError): instance.index('diz')
def test_clear(self): instance = QSO("key=value1&key=value2&bar=baz") assert len(instance) == 3 instance.clear() assert len(instance) == 0 assert not instance assert not instance.groups
def test_length(self, string, args, kw): instance = QSO(string) if len(instance) != (len(args) + len(kw)): __import__('pudb').set_trace() instance = QSO(string) assert len(instance) == (len(args) + len(kw))
def test_update_keywords(self): instance = QSO("key=value1&key=value2&bar=baz") instance.update(bar="diz") assert str(instance) == "key=value1&key=value2&bar=diz" instance.update(diz="doz") assert str(instance) == "key=value1&key=value2&bar=diz&diz=doz" instance.update(key="value3") assert str(instance) == "bar=diz&diz=doz&key=value3"
def test_multiple_values(self, string, values): instance = QSO(string) for key in values: if not isinstance(values[key], list): continue result = list(instance[key]) assert result == values[key]
def test_insert(self): instance = QSO("foo&bar&baz") instance.insert(0, "diz") assert str(instance) == "diz&foo&bar&baz" instance.insert(-1, "doz") assert str(instance) == "diz&foo&bar&doz&baz" assert len(instance.groups[None]) == 5 instance.insert(99, "twentyseven") assert str(instance) == "diz&foo&bar&doz&baz&twentyseven"
def test_numeric_deletion(self): instance = QSO('key=value1&key=value2&bar=baz') assert len(instance) == 3 assert len(instance.groups['key']) == 2 del instance[0] assert len(instance) == 2 assert len(instance.groups['key']) == 1 assert str(instance) == 'key=value2&bar=baz'
def test_count(self): instance = QSO("") assert instance.count('foo') == 0 instance = QSO("foo&bar=value1&baz=diz&bar=value2") assert instance.count('foo') == 1 assert instance.count('bar') == 2 assert instance.count('baz') == 1
def test_pop_failures(self, key): instance = QSO() with pytest.raises(KeyError): instance.pop(key)
def test_get(self): instance = QSO("key=value1&key=value2&bar=baz") assert tuple(instance.get('key')) == ('value1', 'value2') assert instance.get('bar') == 'baz' assert instance.get('baz') is None
def test_numeric_indexing(self, string, args, kw): instance = QSO(string) for i, arg in enumerate(args): assert instance[i] == arg
def test_grouped_replacement(self, string, args, kw): instance = QSO(string) instance['foo'] = 'doz' assert 'foo=doz' in str(instance)
def test_contains(self, string, args, kw): instance = QSO(string) for key in kw: assert key in instance
def test_named_assignment(self, string, args, kw): instance = QSO(string) instance['doz'] = '27' assert str(instance).endswith(('&' if (args or kw) else '') + 'doz=27')
def test_inline_add(self, src, change, expect): instance = QSO(src) instance += change assert str(instance) == expect
def test_repr(self, string, args, kw): instance = QSO(string) assert repr(instance) == 'QSO("' + string + '")'
def test_pop_examples(self, src, key, expect, value): instance = QSO(src) result = instance.pop(key) assert str(instance) == expect assert result == value
def test_comparison(self, src, value): instance = QSO(src) assert instance == value assert not (instance != value)
def test_str(self, string, args, kw): instance = QSO(string) assert str(instance) == string
def test_pop_defaults(self): instance = QSO() assert instance.pop(default=None) is None assert instance.pop(0, None) is None assert instance.pop('named', None) is None
def test_contains(self, string, args, kw): instance = QSO(string) for i in range(len(args) + len(kw)): assert i in instance
def test_pop_failure(self): instance = QSO() with pytest.raises(KeyError): instance.pop('key')
def test_iteration_view(self, string, args, kw): instance = QSO(string) for bucket, arg in zip(instance, args): assert bucket.value == arg
def test_reverse(self): instance = QSO("key=value1&key=value2&bar=baz") instance.reverse() assert str(instance) == "bar=baz&key=value2&key=value1" assert tuple(instance['key']) == ("value2", "value1")
def test_grouped_indexing(self, string, args, kw): instance = QSO(string) for key, value in kw.items(): assert instance[key] == value
def test_keys(self): instance = QSO("key=value1&key=value2&bar=baz") assert tuple(instance.keys()) == ('key', 'key', 'bar')
def test_reversing(self, string, args, kw): instance = QSO(string) result = list(reversed(instance)) assert len(result) == len(args) assert tuple(i.value for i in result) == args[::-1]
def test_items(self): instance = QSO("key=value1&key=value2&bar=baz") assert tuple(instance.items()) == (('key', 'value1'), ('key', 'value2'), ('bar', 'baz'))
def test_indexed_replacement(self, string, args, kw): instance = QSO(string) instance[1] = 'doz' assert '&doz'
def test_values(self): instance = QSO("key=value1&key=value2&bar=baz") assert tuple(instance.values()) == ('value1', 'value2', 'baz')