Пример #1
0
def test_read_write_unknown():
    ctx = Context()

    needle = u'xyzzy'
    assert needle not in _default_context.keys()
    assert needle not in ctx
    assert_raises(KeyError, lambda: ctx[needle])
    assert_raises(KeyError, ctx.__setitem__, needle, Nothing)
Пример #2
0
def test_read_write_known():
    ctx = Context()

    needle = _default_context.keys()[0]
    assert needle in ctx
    assert ctx[needle] is not Nothing
    ctx[needle] = Nothing
    assert ctx[needle] is Nothing
Пример #3
0
def test_read_write_known():
    ctx = Context()

    needle = _default_context.keys()[0]
    assert needle in ctx
    assert ctx[needle] is not Nothing
    ctx[needle] = Nothing
    assert ctx[needle] is Nothing
Пример #4
0
def test_push_unknown():
    ctx = Context()

    needle = 'xyzzy'
    assert needle not in _default_context.keys()

    assert_raises(KeyError, ctx.push, **{needle: Nothing})
    assert_raises(RuntimeError, ctx.pop)
Пример #5
0
def test_read_write_unknown():
    ctx = Context()

    needle = 'xyzzy'
    assert needle not in _default_context.keys()
    assert needle not in ctx
    assert_raises(KeyError, lambda: ctx[needle])
    assert_raises(KeyError, ctx.__setitem__, needle, Nothing)
Пример #6
0
def test_update_unknown():
    ctx = Context()
    assert u'xyzzy' not in _default_context.keys()

    with pytest.raises(KeyError):

        ctx.update(xyzzy=123)
    assert u'xyzzy' not in ctx
Пример #7
0
def test_push_unknown():
    ctx = Context()

    needle = u'xyzzy'
    needle_attribute = 'xyzzy'  # native text type
    assert needle not in _default_context.keys()

    assert_raises(KeyError, ctx.push, **{needle_attribute: Nothing})
    assert_raises(RuntimeError, ctx.pop)
Пример #8
0
def test_read_write_unknown():
    ctx = Context()

    needle = 'xyzzy'
    assert needle not in _default_context.keys()
    assert needle not in ctx
    with pytest.raises(KeyError):
        ctx[needle]()
    with pytest.raises(KeyError):
        ctx.__setitem__(needle, Nothing)
Пример #9
0
def test_push_unknown():
    ctx = Context()

    needle = 'xyzzy'
    assert needle not in _default_context.keys()

    with pytest.raises(KeyError):

        ctx.push(**{needle: Nothing})
    with pytest.raises(RuntimeError):
        ctx.pop()
Пример #10
0
def test_push_known():
    ctx = Context()

    needle = _default_context.keys()[0]
    assert needle in ctx
    assert ctx[needle] is not Nothing

    ctx.push(**{needle.encode('ascii'): Nothing})
    assert ctx[needle] is Nothing

    ctx.pop()
    assert ctx[needle] is not Nothing
Пример #11
0
def test_push_known():
    ctx = Context()

    needle = list(_default_context.keys())[0]
    assert needle in ctx
    assert ctx[needle] is not Nothing

    ctx.push(**{needle: Nothing})
    assert ctx[needle] is Nothing

    ctx.pop()
    assert ctx[needle] is not Nothing
Пример #12
0
def test_push_known():
    ctx = Context()

    needle = _default_context.keys()[0]
    assert needle in ctx
    assert ctx[needle] is not Nothing

    ctx.push(**{needle.encode('ascii'): Nothing})
    assert ctx[needle] is Nothing

    ctx.pop()
    assert ctx[needle] is not Nothing
Пример #13
0
def test_push_known():
    ctx = Context()

    needle = list(_default_context.keys())[0]
    assert needle in ctx
    assert ctx[needle] is not Nothing

    ctx.push(**{needle: Nothing})
    assert ctx[needle] is Nothing

    ctx.pop()
    assert ctx[needle] is not Nothing
Пример #14
0
def test_update_known():
    ctx = Context()
    known = _default_context.keys()
    sentinels = [object(), object()]

    iterable = [(known[0], sentinels[0])]
    kwargs = {known[1].encode('ascii'): sentinels[1]}

    ctx.update(iterable, **kwargs)

    assert ctx[known[0]] is sentinels[0]
    assert ctx[known[1]] is sentinels[1]

    ctx = Context()
    ctx.update(iterable)
    assert ctx[known[0]] is sentinels[0]

    ctx = Context()
    ctx.update(**kwargs)
    assert ctx[known[1]] is sentinels[1]
Пример #15
0
def test_update_known():
    ctx = Context()
    known = _default_context.keys()
    sentinels = [object(), object()]

    iterable = [(known[0], sentinels[0])]
    kwargs = {known[1].encode('ascii'): sentinels[1]}

    ctx.update(iterable, **kwargs)

    assert ctx[known[0]] is sentinels[0]
    assert ctx[known[1]] is sentinels[1]

    ctx = Context()
    ctx.update(iterable)
    assert ctx[known[0]] is sentinels[0]

    ctx = Context()
    ctx.update(**kwargs)
    assert ctx[known[1]] is sentinels[1]
Пример #16
0
def test_update_unknown():
    ctx = Context()
    assert u'xyzzy' not in _default_context.keys()

    assert_raises(KeyError, ctx.update, xyzzy=123)
    assert u'xyzzy' not in ctx
Пример #17
0
def test_update_unknown():
    ctx = Context()
    assert u'xyzzy' not in _default_context.keys()

    assert_raises(KeyError, ctx.update, xyzzy=123)
    assert u'xyzzy' not in ctx