Example #1
0
    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')
Example #2
0
 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
Example #3
0
    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))
Example #4
0
 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"
Example #5
0
    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]
Example #6
0
 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"
Example #7
0
 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'
Example #8
0
    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
Example #9
0
    def test_pop_failures(self, key):
        instance = QSO()

        with pytest.raises(KeyError):
            instance.pop(key)
Example #10
0
 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
Example #11
0
    def test_numeric_indexing(self, string, args, kw):
        instance = QSO(string)

        for i, arg in enumerate(args):
            assert instance[i] == arg
Example #12
0
    def test_grouped_replacement(self, string, args, kw):
        instance = QSO(string)

        instance['foo'] = 'doz'

        assert 'foo=doz' in str(instance)
Example #13
0
    def test_contains(self, string, args, kw):
        instance = QSO(string)

        for key in kw:
            assert key in instance
Example #14
0
    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')
Example #15
0
 def test_inline_add(self, src, change, expect):
     instance = QSO(src)
     instance += change
     assert str(instance) == expect
Example #16
0
 def test_repr(self, string, args, kw):
     instance = QSO(string)
     assert repr(instance) == 'QSO("' + string + '")'
Example #17
0
 def test_pop_examples(self, src, key, expect, value):
     instance = QSO(src)
     result = instance.pop(key)
     assert str(instance) == expect
     assert result == value
Example #18
0
 def test_comparison(self, src, value):
     instance = QSO(src)
     assert instance == value
     assert not (instance != value)
Example #19
0
 def test_str(self, string, args, kw):
     instance = QSO(string)
     assert str(instance) == string
Example #20
0
    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
Example #21
0
    def test_contains(self, string, args, kw):
        instance = QSO(string)

        for i in range(len(args) + len(kw)):
            assert i in instance
Example #22
0
    def test_pop_failure(self):
        instance = QSO()

        with pytest.raises(KeyError):
            instance.pop('key')
Example #23
0
    def test_iteration_view(self, string, args, kw):
        instance = QSO(string)

        for bucket, arg in zip(instance, args):
            assert bucket.value == arg
Example #24
0
 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")
Example #25
0
    def test_grouped_indexing(self, string, args, kw):
        instance = QSO(string)

        for key, value in kw.items():
            assert instance[key] == value
Example #26
0
 def test_keys(self):
     instance = QSO("key=value1&key=value2&bar=baz")
     assert tuple(instance.keys()) == ('key', 'key', 'bar')
Example #27
0
    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]
Example #28
0
 def test_items(self):
     instance = QSO("key=value1&key=value2&bar=baz")
     assert tuple(instance.items()) == (('key', 'value1'),
                                        ('key', 'value2'), ('bar', 'baz'))
Example #29
0
 def test_indexed_replacement(self, string, args, kw):
     instance = QSO(string)
     instance[1] = 'doz'
     assert '&doz'
Example #30
0
 def test_values(self):
     instance = QSO("key=value1&key=value2&bar=baz")
     assert tuple(instance.values()) == ('value1', 'value2', 'baz')