示例#1
0
文件: test_qso.py 项目: jhirniak/uri
    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')
示例#2
0
文件: test_qso.py 项目: jhirniak/uri
 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
示例#3
0
文件: test_qso.py 项目: jhirniak/uri
    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))
示例#4
0
文件: test_qso.py 项目: jhirniak/uri
 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"
示例#5
0
文件: test_qso.py 项目: jhirniak/uri
    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]
示例#6
0
文件: test_qso.py 项目: jhirniak/uri
 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"
示例#7
0
文件: test_qso.py 项目: jhirniak/uri
 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'
示例#8
0
文件: test_qso.py 项目: jhirniak/uri
    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
示例#9
0
文件: test_qso.py 项目: jhirniak/uri
    def test_pop_failures(self, key):
        instance = QSO()

        with pytest.raises(KeyError):
            instance.pop(key)
示例#10
0
文件: test_qso.py 项目: jhirniak/uri
 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
示例#11
0
文件: test_qso.py 项目: jhirniak/uri
    def test_numeric_indexing(self, string, args, kw):
        instance = QSO(string)

        for i, arg in enumerate(args):
            assert instance[i] == arg
示例#12
0
文件: test_qso.py 项目: jhirniak/uri
    def test_grouped_replacement(self, string, args, kw):
        instance = QSO(string)

        instance['foo'] = 'doz'

        assert 'foo=doz' in str(instance)
示例#13
0
文件: test_qso.py 项目: jhirniak/uri
    def test_contains(self, string, args, kw):
        instance = QSO(string)

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

        for i in range(len(args) + len(kw)):
            assert i in instance
示例#22
0
文件: test_qso.py 项目: jhirniak/uri
    def test_pop_failure(self):
        instance = QSO()

        with pytest.raises(KeyError):
            instance.pop('key')
示例#23
0
文件: test_qso.py 项目: jhirniak/uri
    def test_iteration_view(self, string, args, kw):
        instance = QSO(string)

        for bucket, arg in zip(instance, args):
            assert bucket.value == arg
示例#24
0
文件: test_qso.py 项目: jhirniak/uri
 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")
示例#25
0
文件: test_qso.py 项目: jhirniak/uri
    def test_grouped_indexing(self, string, args, kw):
        instance = QSO(string)

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