Skip to content

Commit

Permalink
removed pep 8 from test
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Feb 27, 2015
1 parent bc58da5 commit 26b09ed
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 63 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[run]
concurrency = gevent
source = pulsar,examples
omit =
*pulsar/utils/system/winservice.py
Expand Down
1 change: 1 addition & 0 deletions examples/djchat/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def on_message(self, websocket, message):
return self.queue.put(message)


@test_timeout(30)
@unittest.skipUnless(execute_from_command_line, 'Requires django')
class TestDjangoChat(unittest.TestCase):
concurrency = 'thread'
Expand Down
15 changes: 0 additions & 15 deletions pulsar/apps/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ class MyTestCase(unittest.TestCase):
from .loader import *
from .utils import *
from .wsgi import *
from .pep import pep8_run
from .runner import Runner


Expand Down Expand Up @@ -423,14 +422,6 @@ class TestShowLeaks(TestOption):
"""


class TestPep8(TestOption):
name = "pep8"
flags = ['--pep8']
nargs = '*'
validator = pulsar.validate_list
desc = """Run pep8"""


class TestSuite(pulsar.Application):
'''An asynchronous test suite which works like a task queue.
Expand Down Expand Up @@ -516,12 +507,6 @@ def _tags():
stream.writeln(tag)
stream.writeln('')
return False
elif self.cfg.pep8:
msg, code = pep8_run(self.cfg.pep8)
stream.writeln(msg)
if code:
sys.exit(code)
return False

def monitor_start(self, monitor):
'''When the monitor starts load all test classes into the queue'''
Expand Down
30 changes: 0 additions & 30 deletions pulsar/apps/test/pep.py

This file was deleted.

35 changes: 19 additions & 16 deletions pulsar/apps/test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pulsar import async, is_async, HaltServer

from .utils import (TestFailure, skip_test, skip_reason,
expecting_failure, AsyncAssert)
expecting_failure, AsyncAssert, get_test_timeout)


class Runner(object):
Expand Down Expand Up @@ -63,10 +63,11 @@ def _run_all_tests(self, tests):
def _run_testcls(self, testcls, all_tests):
cfg = testcls.cfg
seq = getattr(testcls, '_sequential_execution', cfg.sequential)
test_timeout = get_test_timeout(testcls, cfg.test_timeout)
try:
if skip_test(testcls):
raise SkipTest(skip_reason(testcls))
yield from self._run(testcls.setUpClass)
yield from self._run(testcls.setUpClass, test_timeout)
yield None # release the loop
except SkipTest as exc:
reason = str(exc)
Expand All @@ -81,28 +82,28 @@ def _run_testcls(self, testcls, all_tests):
else:
if seq:
for test in all_tests:
yield from self._run_test(test)
yield from self._run_test(test, test_timeout)
else:
yield from asyncio.wait([self._run_test(test)
yield from asyncio.wait([self._run_test(test, test_timeout)
for test in all_tests],
loop=self._loop)

try:
yield from self._run(testcls.tearDownClass)
yield from self._run(testcls.tearDownClass, test_timeout)
except Exception as exc:
self.logger.exception('Failure in tearDownClass',
exc_info=True)

self.concurrent.remove(testcls)

def _run(self, method):
def _run(self, method, test_timeout):
coro = method()
# a coroutine
if coro:
timeout = self.monitor.cfg.test_timeout
yield from asyncio.wait_for(coro, timeout, loop=self._loop)
test_timeout = get_test_timeout(method, test_timeout)
yield from asyncio.wait_for(coro, test_timeout, loop=self._loop)

def _run_test(self, test):
def _run_test(self, test, test_timeout):
'''Run a ``test`` function using the following algorithm
* Run :meth:`setUp` method in :attr:`testcls`
Expand All @@ -118,25 +119,27 @@ def _run_test(self, test):
reason = skip_reason(method)
runner.addSkip(test, reason)
else:
error = yield from self._run_safe(test, 'setUp')
error = yield from self._run_safe(test, 'setUp', test_timeout)
if not error:
test = runner.before_test_function_run(test)
error = yield from self._run_safe(test, test_name)
error = yield from self._run_safe(test, 'tearDown', error)
error = yield from self._run_safe(test, test_name,
test_timeout)
error = yield from self._run_safe(test, 'tearDown',
test_timeout, error)
if not error:
runner.addSuccess(test)
runner.stopTest(test)
yield None # release the loop

def _run_safe(self, test, method_name, error=None):
def _run_safe(self, test, method_name, test_timeout, error=None):
try:
method = getattr(test, method_name)
coro = method()
# a coroutine
if is_async(coro):
timeout = getattr(method, 'timeout',
self.monitor.cfg.test_timeout)
yield from asyncio.wait_for(coro, timeout, loop=self._loop)
test_timeout = get_test_timeout(method, test_timeout)
yield from asyncio.wait_for(coro, test_timeout,
loop=self._loop)
except Exception as exc:
if not error:
error = TestFailure(exc)
Expand Down
7 changes: 6 additions & 1 deletion pulsar/apps/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ def __init__(self, timeout):
self.timeout = timeout

def __call__(self, f):
f.timeout = self.timeout
f._test_timeout = self.timeout
return f


def get_test_timeout(o, timeout):
val = getattr(o, '_test_timeout', 0)
return max(val, timeout)


class AsyncAssert(object):
'''A `descriptor`_ added by the :ref:`test-suite` to all python
:class:`~unittest.TestCase` loaded.
Expand Down
1 change: 0 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def run(**params):
# Run the test suite
if '--coverage' in args:
import coverage
print('Start coverage')
p = current_process()
p._coverage = coverage.coverage(data_suffix=True)
p._coverage.start()
Expand Down

0 comments on commit 26b09ed

Please sign in to comment.