示例#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