Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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))
Ejemplo n.º 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"
Ejemplo n.º 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]
Ejemplo n.º 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"
Ejemplo n.º 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'
Ejemplo n.º 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
Ejemplo n.º 9
0
    def test_pop_failures(self, key):
        instance = QSO()

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

        for i, arg in enumerate(args):
            assert instance[i] == arg
Ejemplo n.º 12
0
    def test_grouped_replacement(self, string, args, kw):
        instance = QSO(string)

        instance['foo'] = 'doz'

        assert 'foo=doz' in str(instance)
Ejemplo n.º 13
0
    def test_contains(self, string, args, kw):
        instance = QSO(string)

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

        for i in range(len(args) + len(kw)):
            assert i in instance
Ejemplo n.º 22
0
    def test_pop_failure(self):
        instance = QSO()

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

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

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