Commit 27f91b78 authored by Kirill Smelkov's avatar Kirill Smelkov

context: tests: Factor out common bits from test_context

In the next patch we'll be adding deadlines support with another test.
Move common infrastructure that will be used in all context tests to be
test-module global.
parent e5687f2f
...@@ -23,24 +23,25 @@ from __future__ import print_function, absolute_import ...@@ -23,24 +23,25 @@ from __future__ import print_function, absolute_import
from golang import context, nilchan from golang import context, nilchan
from golang.context import _ready as ready from golang.context import _ready as ready
def test_context(): # assertCtx asserts on state of _BaseCtx*
bg = context.background() def assertCtx(ctx, children, err=None, done=False):
assert bg.err() is None
assert bg.done() is nilchan
assert not ready(bg.done())
assert bg.value("hello") is None
# assertCtx asserts on state of _BaseCtx*
def assertCtx(ctx, children, err=None, done=False):
assert isinstance(ctx, context._BaseCtx) assert isinstance(ctx, context._BaseCtx)
assert ctx.err() is err assert ctx.err() is err
assert ready(ctx.done()) == done assert ready(ctx.done()) == done
assert ctx._children == children assert ctx._children == children
Z = set() # empty set Z = set() # empty set
C = context.canceled C = context.canceled
D = context.deadlineExceeded D = context.deadlineExceeded
Y = True Y = True
bg = context.background()
def test_context():
assert bg.err() is None
assert bg.done() is nilchan
assert not ready(bg.done())
assert bg.value("hello") is None
ctx1, cancel1 = context.with_cancel(bg) ctx1, cancel1 = context.with_cancel(bg)
assert ctx1.done() is not bg.done() assert ctx1.done() is not bg.done()
...@@ -69,6 +70,7 @@ def test_context(): ...@@ -69,6 +70,7 @@ def test_context():
assertCtx(ctx111, {ctx1111}) assertCtx(ctx111, {ctx1111})
assertCtx(ctx1111, Z) assertCtx(ctx1111, Z)
ctx12 = context.with_value(ctx1, "hello", "world") ctx12 = context.with_value(ctx1, "hello", "world")
assert ctx12.done() is ctx1.done() assert ctx12.done() is ctx1.done()
assert ctx12.value("hello") == "world" assert ctx12.value("hello") == "world"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment