From 26b09ed57f8379855e6e8742b102ab5389a5d915 Mon Sep 17 00:00:00 2001 From: Luca Sbardella Date: Fri, 27 Feb 2015 16:16:00 +0000 Subject: [PATCH] removed pep 8 from test --- .coveragerc | 1 + examples/djchat/test_app.py | 1 + pulsar/apps/test/__init__.py | 15 --------------- pulsar/apps/test/pep.py | 30 ------------------------------ pulsar/apps/test/runner.py | 35 +++++++++++++++++++---------------- pulsar/apps/test/utils.py | 7 ++++++- runtests.py | 1 - 7 files changed, 27 insertions(+), 63 deletions(-) delete mode 100644 pulsar/apps/test/pep.py diff --git a/.coveragerc b/.coveragerc index 8275452a..cb844711 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,5 @@ [run] +concurrency = gevent source = pulsar,examples omit = *pulsar/utils/system/winservice.py diff --git a/examples/djchat/test_app.py b/examples/djchat/test_app.py index fc606826..f1b61588 100644 --- a/examples/djchat/test_app.py +++ b/examples/djchat/test_app.py @@ -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' diff --git a/pulsar/apps/test/__init__.py b/pulsar/apps/test/__init__.py index 97fba1d8..de4b8a18 100644 --- a/pulsar/apps/test/__init__.py +++ b/pulsar/apps/test/__init__.py @@ -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 @@ -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. @@ -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''' diff --git a/pulsar/apps/test/pep.py b/pulsar/apps/test/pep.py deleted file mode 100644 index 9699cfa0..00000000 --- a/pulsar/apps/test/pep.py +++ /dev/null @@ -1,30 +0,0 @@ -import sys - -try: - import pep8 -except ImportError: - pep8 = None - - -def pep8_run(paths, config_file=None, stream=None): - '''Programmatically run ``pep8``. - - Returns a 2-elements tuple with a string message and an exit code. - ''' - if pep8: - stream = stream or sys.stderr - stream.write('Running pep8\n') - pep8style = pep8.StyleGuide(paths=paths, config_file=config_file) - options = pep8style.options - report = pep8style.check_files() - if options.statistics: - report.print_statistics() - if options.benchmark: - report.print_benchmark() - if options.testsuite and not options.quiet: - report.print_results() - if report.total_errors: - msg = str(report.total_errors) + '\n' if options.count else '' - return msg, 1 - return 'OK', 0 - return 'pep8 not installed', 1 diff --git a/pulsar/apps/test/runner.py b/pulsar/apps/test/runner.py index e75abcce..834ae97a 100644 --- a/pulsar/apps/test/runner.py +++ b/pulsar/apps/test/runner.py @@ -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): @@ -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) @@ -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` @@ -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) diff --git a/pulsar/apps/test/utils.py b/pulsar/apps/test/utils.py index 24cc881e..45f0cf2a 100644 --- a/pulsar/apps/test/utils.py +++ b/pulsar/apps/test/utils.py @@ -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. diff --git a/runtests.py b/runtests.py index 82a2bfb1..bf22e65e 100644 --- a/runtests.py +++ b/runtests.py @@ -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()