Skip to content

add advance_time fixture and test (closes #83, #95, #96 #110) #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
add more tests to verify the advance_time fixture operations
  • Loading branch information
derekbrokeit committed May 14, 2019
commit 566af4842dc69024024017c9b3c77d65c4fba8eb
55 changes: 53 additions & 2 deletions tests/test_simple_35.py
Original file line number Diff line number Diff line change
@@ -89,9 +89,9 @@ def test_async_close_loop(event_loop):


@pytest.mark.asyncio
async def test_advance_time_fixture(advance_time):
async def test_advance_time_fixture(event_loop, advance_time):
"""
Test the `advance_time` fixture
Test the `advance_time` fixture using a sleep timer
"""
# A task is created that will sleep some number of seconds
SLEEP_TIME = 10
@@ -107,3 +107,54 @@ async def test_advance_time_fixture(advance_time):
# process the timeout
await advance_time(SLEEP_TIME)
assert task.done()


@pytest.mark.asyncio
async def test_advance_time_fixture_call_later(event_loop, advance_time):
"""
Test the `advance_time` fixture using loop.call_later
"""
# A task is created that will sleep some number of seconds
SLEEP_TIME = 10
result = []

# create a simple callback that adds a value to result
def callback():
result.append(True)

# create the task
event_loop.call_later(SLEEP_TIME, callback)

# start the task
await advance_time(0)
assert not result

# process the timeout
await advance_time(SLEEP_TIME)
assert result


@pytest.mark.asyncio
async def test_advance_time_fixture_coroutine(event_loop, advance_time):
"""
Test the `advance_time` fixture using loop.call_later
"""
# A task is created that will sleep some number of seconds
SLEEP_TIME = 10
result = []

# create a simple callback that adds a value to result
async def callback():
await asyncio.sleep(SLEEP_TIME)
result.append(True)

# create the task
task = event_loop.create_task(callback())

# start the task
await advance_time(0)
assert not task.done()

# process the timeout
await advance_time(SLEEP_TIME)
assert task.done() and result