Ejemplo n.º 1
0
def test_put_and_swap_types(cls, has_return_owner):
    name = cls.__name__
    if has_return_owner:
        extra = ', return_owner=False'
    else:
        extra = ''
    x1 = cls('foo', value=b'bar')
    assert repr(x1) == ("%s('foo', value=%s, owner=no_change%s)" %
                        (name, repr(b'bar'), extra))
    x2 = cls('foo', owner='container_1')
    assert repr(x2) == ("%s('foo', value=no_change, owner='container_1'%s)" %
                        (name, extra))
    x3 = cls('foo', owner=None)
    assert repr(x3) == ("%s('foo', value=no_change, owner=None%s)" %
                        (name, extra))
    for x in [x1, x2, x3]:
        assert x == copy.deepcopy(x)
    assert x1 != x2

    assert kv.is_operation(x1)

    with pytest.raises(AttributeError):
        x1.foobar = 1

    with pytest.raises(ValueError):
        cls('foo', owner='invalid')

    with pytest.raises(TypeError):
        cls(1, value=b'bar')

    with pytest.raises(TypeError):
        cls('foo', owner=1)

    with pytest.raises(ValueError):
        cls('foo')
Ejemplo n.º 2
0
def test_discard_type():
    x = kv.discard('foo')
    assert repr(x) == "discard('foo')"
    assert x == copy.deepcopy(x)
    assert x != kv.discard('bar')

    assert kv.is_operation(x)

    with pytest.raises(AttributeError):
        x.foobar = 1

    with pytest.raises(TypeError):
        kv.discard(1)
Ejemplo n.º 3
0
def test_exists_and_missing_types(cls):
    x = cls('foo')
    assert repr(x) == ("%s('foo')" % cls.__name__)
    assert x == copy.deepcopy(x)
    assert x != cls('bar')

    assert kv.is_condition(x)
    assert kv.is_operation(x)

    with pytest.raises(AttributeError):
        x.foobar = 1

    with pytest.raises(TypeError):
        cls(1)
Ejemplo n.º 4
0
def test_range_types(cls, kw):
    name = cls.__name__
    x1 = cls()
    assert repr(x1) == ("%s(start=None, end=None, %s=False)" % (name, kw))
    x2 = cls(start='key', end='bar', **{kw: True})
    assert repr(x2) == ("%s(start='key', end='bar', %s=True)" % (name, kw))
    for x in [x1, x2]:
        assert x == copy.deepcopy(x)
    assert x1 != x2

    assert kv.is_operation(x1)

    with pytest.raises(AttributeError):
        x1.foobar = 1

    for k in ['start', 'end', kw]:
        with pytest.raises(TypeError):
            cls(**{k: 1})
Ejemplo n.º 5
0
def test_prefix_types(cls, kw):
    name = cls.__name__
    x1 = cls('key')
    assert repr(x1) == ("%s('key', %s=False)" % (name, kw))
    x2 = cls('key', **{kw: True})
    assert repr(x2) == ("%s('key', %s=True)" % (name, kw))
    for x in [x1, x2]:
        assert x == copy.deepcopy(x)
    assert x1 != x2

    assert kv.is_operation(x1)

    with pytest.raises(AttributeError):
        x1.foobar = 1

    with pytest.raises(TypeError):
        cls(1)

    with pytest.raises(TypeError):
        cls('foo', **{kw: None})
Ejemplo n.º 6
0
def test_count_and_list_keys_types(cls):
    x1 = cls()
    assert repr(x1) == ("%s(start=None, end=None)" % cls.__name__)
    x2 = cls(prefix='foo')
    assert repr(x2) == ("%s(prefix='foo')" % cls.__name__)
    x3 = cls(start='foo')
    assert repr(x3) == ("%s(start='foo', end=None)" % cls.__name__)
    for x in [x1, x2, x3]:
        assert x == copy.deepcopy(x)
    assert x1 != x2

    assert kv.is_operation(x1)

    with pytest.raises(AttributeError):
        x1.foobar = 1

    with pytest.raises(ValueError):
        cls(prefix='foo', start='bar')

    for k in ['prefix', 'start', 'end']:
        with pytest.raises(TypeError):
            cls(**{k: 1})
Ejemplo n.º 7
0
def test_get_and_pop_types(cls):
    name = cls.__name__
    x1 = cls('key')
    assert repr(x1) == ("%s('key', default=None, return_owner=False)" % name)
    x2 = cls('key', default=b'bar', return_owner=True)
    assert repr(x2) == ("%s('key', default=%s, return_owner=True)" % (name, repr(b'bar')))
    for x in [x1, x2]:
        assert x == copy.deepcopy(x)
    assert x1 != x2

    assert kv.is_operation(x1)

    with pytest.raises(AttributeError):
        x1.foobar = 1

    with pytest.raises(TypeError):
        cls('foo', default=1)

    with pytest.raises(TypeError):
        cls('foo', return_owner=None)

    with pytest.raises(TypeError):
        cls(1)