def test_use_or_create_async_context__when_missing_with_name(self): # -- CASE: AsynContext attribute is created with own name loop0 = Mock() context = self.make_context() async_context = use_or_create_async_context(context, "acontext", loop=loop0) assert isinstance(async_context, AsyncContext) assert async_context.name == "acontext" assert getattr(context, "acontext", None) is async_context assert async_context.loop is loop0
def test_use_or_create_async_context__when_exists(self): # -- CASE: AsynContext attribute exists with default_name context = self.make_context() async_context0 = context.async_context = AsyncContext() assert context.async_context.name == "async_context" assert hasattr(context, AsyncContext.default_name) async_context = use_or_create_async_context(context) assert isinstance(async_context, AsyncContext) assert async_context.name == "async_context" assert getattr(context, "async_context", None) is async_context assert async_context is async_context0
def test_use_or_create_async_context__when_missing(self): # -- CASE: AsynContext attribute is created with default_name context = self.make_context() context._push() async_context = use_or_create_async_context(context) assert isinstance(async_context, AsyncContext) assert async_context.name == "async_context" assert getattr(context, "async_context", None) is async_context context._pop() assert getattr(context, "async_context", None) is None
def test_use_or_create_async_context__when_exists_with_name(self): # -- CASE: AsynContext attribute exists with own name loop0 = Mock() context = self.make_context() async_context0 = context.acontext = AsyncContext(name="acontext", loop=loop0) assert context.acontext.name == "acontext" loop1 = Mock() async_context = use_or_create_async_context(context, "acontext", loop=loop1) assert isinstance(async_context, AsyncContext) assert async_context is async_context0 assert getattr(context, "acontext", None) is async_context assert async_context.loop is loop0
def step_dispatch_async_call(context, param): async_context = use_or_create_async_context(context, "async_context1") task = async_context.loop.create_task(async_func(param)) async_context.tasks.append(task)
def before_scenario(context, scenario): context.async_loop = use_or_create_async_context(context, "async_context1").loop context.port_seq = 5000 context.node = {} context.block_new = {}