from browser import console
import asyncio

from async_manager import AsyncTestManager

aio = AsyncTestManager()

async def wait_secs(s, result):
    await asyncio.sleep(s)
    console.log("Returning result", result)
    return result


@aio.async_test(0.5)
def test_simple_coroutine():
    console.log("coro_wait_secs")
    coro_wait_secs = wait_secs(0.1, 10)
    console.log("ensuring future")
    fut = asyncio.ensure_future(coro_wait_secs)

    console.log("asserting")
    assert asyncio.iscoroutine(coro_wait_secs), "Result of running a coroutine function should be a coroutine object"
    assert asyncio.iscoroutinefunction(wait_secs), "asyncio.coroutine decorator should return a coroutine function"
    assert isinstance(fut, asyncio.Future), "ensure_future should return a future"

    console.log("yielding")
    result = yield from fut

    console.log("asserting")
    assert fut.result() == result, "yield from future should return its result"
    assert result == 10, "Future result different from expected"

from browser import console, aio

async def wait_secs(s, result):
    await aio.sleep(s)
    console.log("Returning result", result)
    return result

async def test_simple_coroutine():
    console.log("coro_wait_secs")
    coro_wait_secs = wait_secs(0.1, 10)
    console.log("ensuring future")
    fut = await coro_wait_secs

    console.log("asserting")
    assert aio.iscoroutine(coro_wait_secs), "Result of running a coroutine function should be a coroutine object"
    assert aio.iscoroutinefunction(wait_secs), "asyncio.coroutine decorator should return a coroutine function"
    console.log("asserts ok")
    assert fut == 10, "Future result different from expected"

aio.run(test_simple_coroutine())
Replace asyncio tests by browser.aio tests
Replace asyncio tests by browser.aio tests

- from browser import console
+ from browser import console, aio
- import asyncio
- 
- from async_manager import AsyncTestManager
- 
- aio = AsyncTestManager()
  
  async def wait_secs(s, result):
-     await asyncio.sleep(s)
+     await aio.sleep(s)
      console.log("Returning result", result)
      return result
  
- 
- @aio.async_test(0.5)
- def test_simple_coroutine():
+ async def test_simple_coroutine():
      console.log("coro_wait_secs")
      coro_wait_secs = wait_secs(0.1, 10)
      console.log("ensuring future")
-     fut = asyncio.ensure_future(coro_wait_secs)
+     fut = await coro_wait_secs
  
      console.log("asserting")
-     assert asyncio.iscoroutine(coro_wait_secs), "Result of running a coroutine function should be a coroutine object"
+     assert aio.iscoroutine(coro_wait_secs), "Result of running a coroutine function should be a coroutine object"
-     assert asyncio.iscoroutinefunction(wait_secs), "asyncio.coroutine decorator should return a coroutine function"
+     assert aio.iscoroutinefunction(wait_secs), "asyncio.coroutine decorator should return a coroutine function"
-     assert isinstance(fut, asyncio.Future), "ensure_future should return a future"
+     console.log("asserts ok")
+     assert fut == 10, "Future result different from expected"
  
+ aio.run(test_simple_coroutine())
-     console.log("yielding")
-     result = yield from fut
- 
-     console.log("asserting")
-     assert fut.result() == result, "yield from future should return its result"
-     assert result == 10, "Future result different from expected"
- 
Replace asyncio tests by browser.aio tests
## Code Before:
from browser import console
import asyncio

from async_manager import AsyncTestManager

aio = AsyncTestManager()

async def wait_secs(s, result):
    await asyncio.sleep(s)
    console.log("Returning result", result)
    return result


@aio.async_test(0.5)
def test_simple_coroutine():
    console.log("coro_wait_secs")
    coro_wait_secs = wait_secs(0.1, 10)
    console.log("ensuring future")
    fut = asyncio.ensure_future(coro_wait_secs)

    console.log("asserting")
    assert asyncio.iscoroutine(coro_wait_secs), "Result of running a coroutine function should be a coroutine object"
    assert asyncio.iscoroutinefunction(wait_secs), "asyncio.coroutine decorator should return a coroutine function"
    assert isinstance(fut, asyncio.Future), "ensure_future should return a future"

    console.log("yielding")
    result = yield from fut

    console.log("asserting")
    assert fut.result() == result, "yield from future should return its result"
    assert result == 10, "Future result different from expected"

## Instruction:
Replace asyncio tests by browser.aio tests
## Code After:
from browser import console, aio

async def wait_secs(s, result):
    await aio.sleep(s)
    console.log("Returning result", result)
    return result

async def test_simple_coroutine():
    console.log("coro_wait_secs")
    coro_wait_secs = wait_secs(0.1, 10)
    console.log("ensuring future")
    fut = await coro_wait_secs

    console.log("asserting")
    assert aio.iscoroutine(coro_wait_secs), "Result of running a coroutine function should be a coroutine object"
    assert aio.iscoroutinefunction(wait_secs), "asyncio.coroutine decorator should return a coroutine function"
    console.log("asserts ok")
    assert fut == 10, "Future result different from expected"

aio.run(test_simple_coroutine())