Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucretiel committed Aug 8, 2015
1 parent 41bb27f commit 4e26f05
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
12 changes: 6 additions & 6 deletions test/test_autoasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ def async_main(loop):

def test_run_forever(context_loop):
@asyncio.coroutine
def stop_loop_after_1_tenth_second():
yield from asyncio.sleep(0.1)
def stop_loop_after(t):
yield from asyncio.sleep(t)
context_loop.stop()

retrieved_value = False

@asyncio.coroutine
def set_value_after_half_tenth_second():
def set_value_after(t):
nonlocal retrieved_value
yield from asyncio.sleep(0.05)
yield from asyncio.sleep(t)
retrieved_value = True

@autoasync(forever=True)
@asyncio.coroutine
def async_main():
asyncio.async(stop_loop_after_1_tenth_second())
asyncio.async(set_value_after_half_tenth_second())
asyncio.async(set_value_after(0.1))
asyncio.async(stop_loop_after(0.2))
yield

async_main()
Expand Down
Empty file removed test/test_autocommand
Empty file.
15 changes: 7 additions & 8 deletions test/test_autocommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
from unittest.mock import patch, sentinel
from autocommand import autocommand

from test_markers import uses_async


@pytest.fixture(scope='module')
def autocommand_module():
return sys.modules['autocommand.autocommand']
autocommand_module = sys.modules['autocommand.autocommand']
uses_async = pytest.mark.skipif(
sys.version_info < (3, 4),
reason="async tests require python 3.4+")


@pytest.yield_fixture
def patched_autoparse(autocommand_module):
def patched_autoparse():
with patch.object(
autocommand_module,
'autoparse',
Expand All @@ -21,7 +20,7 @@ def patched_autoparse(autocommand_module):


@pytest.yield_fixture
def patched_autoasync(autocommand_module):
def patched_autoasync():
with patch.object(
autocommand_module,
'autoasync',
Expand All @@ -33,7 +32,7 @@ def patched_autoasync(autocommand_module):


@pytest.yield_fixture
def patched_automain(autocommand_module):
def patched_automain():
with patch.object(
autocommand_module,
'automain',
Expand Down
25 changes: 16 additions & 9 deletions test/test_automain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,25 @@ def main():


def test_args():
with pytest.raises(SystemExit) as exc_info:
@automain(True, args=[1, 2, 3])
def main(a, b, c):
main_called = False
with pytest.raises(SystemExit):
@automain(True, args=[1, 2])
def main(a, b):
nonlocal main_called
main_called = True
assert a == 1
assert b == 2
assert c == 3
assert main_called


def test_kwargs():
with pytest.raises(SystemExit) as exc_info:
@automain(True, kwargs={'a': 1, 'b': 2, 'c': 3})
def main(a, b, c):
def test_args_and_kwargs():
main_called = False
with pytest.raises(SystemExit):
@automain(True, args=[1], kwargs={'b': 2})
def main(a, b):
nonlocal main_called
main_called = True
assert a == 1
assert b == 2
assert c == 3

assert main_called

0 comments on commit 4e26f05

Please sign in to comment.