async def test_state_transitions_multiple_async_ops(): """test state transitions with multiple asynchronous operations The methods finish() and close() can be called multiple times asynchronously. However, each state transition should occur once. """ nclients = 3 nextline = Nextline(SOURCE) event_initialized = asyncio.Event() task_monitor_state = asyncio.create_task( monitor_state(nextline, event_initialized)) await event_initialized.wait() nextline.run() tasks_finish_and_close = [] for _ in range(nclients): task = asyncio.create_task(finish_and_close(nextline)) tasks_finish_and_close.append(task) aws = [task_monitor_state, *tasks_finish_and_close] results = await asyncio.gather(*aws) states, *_ = results expectecd = ["initialized", "running", "exited", "finished", "closed"] assert expectecd == states
async def test_reset_with_statement(): nextline = Nextline(SOURCE) assert SOURCE.split("\n") == nextline.get_source() nextline.run() await nextline.finish() nextline.reset(statement=SOURCE_TWO) assert SOURCE_TWO.split("\n") == nextline.get_source() nextline.run() await nextline.finish() await nextline.close()
async def test_run(): nextline = Nextline(statement) assert nextline.global_state == "initialized" nextline.run() async for global_state in nextline.subscribe_global_state(): if global_state == "running": break async for thread_asynctask_ids in nextline.subscribe_thread_asynctask_ids( ): if thread_asynctask_ids: thread_asynctask_id = thread_asynctask_ids[0] break async for state in nextline.subscribe_thread_asynctask_state( thread_asynctask_id): if state["prompting"]: break nextline.send_pdb_command(thread_asynctask_id, "continue") await nextline.finish() assert nextline.global_state == "finished" await nextline.close() assert nextline.global_state == "closed"
async def test_reset(): nextline = Nextline(SOURCE) nextline.run() await nextline.finish() nextline.reset() nextline.run() await nextline.finish() await nextline.close()
async def test_run(): nextline = Nextline(statement) assert nextline.global_state == "initialized" task_monitor_global_state = asyncio.create_task( monitor_global_state(nextline)) # await asyncio.sleep(0) task_control_execution = asyncio.create_task(control_execution(nextline)) nextline.run() await nextline.finish() assert nextline.global_state == "finished" await nextline.close() assert nextline.global_state == "closed"
async def test_state_transitions_single_op(): nextline = Nextline(SOURCE) event_initialized = asyncio.Event() task_monitor_state = asyncio.create_task( monitor_state(nextline, event_initialized)) await event_initialized.wait() nextline.run() await nextline.finish() await nextline.close() aws = [task_monitor_state] results = await asyncio.gather(*aws) states, *_ = results expectecd = ["initialized", "running", "exited", "finished", "closed"] assert expectecd == states
async def test_run(): nextline = Nextline(statement) assert nextline.global_state == "initialized" task_monitor_global_state = asyncio.create_task( monitor_global_state(nextline)) task_control_execution = asyncio.create_task(control_execution(nextline)) task_run = asyncio.create_task(run(nextline)) aws = [task_run, task_monitor_global_state, task_control_execution] await asyncio.gather(*aws) assert nextline.global_state == "closed"
async def test_repr(): nextline = Nextline(SOURCE) repr(nextline)