From cb03b384b0b00e60bb40058dd4ef9aff07caf05f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 18 Feb 2014 14:34:45 +0100 Subject: [PATCH] [IMP] phantomjs runner * use Skip exception to skip tests in case phantomjs binary not found * remove spurious logging, move some to debug when debatable * use testing assertions for correct reporting * allow failure message * use mutable buffer to accumulate stdout data bzr revid: xmo@openerp.com-20140218133445-e5l155j10i934o88 --- openerp/tests/common.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/openerp/tests/common.py b/openerp/tests/common.py index aac93ea1f7b..e4183ed0392 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -190,38 +190,37 @@ class HttpCase(TransactionCase): """ t0 = time.time() - buf = '' + buf = bytearray() while 1: # timeout - if time.time() > t0 + timeout: - raise Exception("phantomjs test timeout (%ss)" % timeout) + self.assertLess(time.time(), t0 + timeout, + "PhantomJS tests should take less than %s seconds" % timeout) # read a byte ready, _, _ = select.select([phantom.stdout], [], [], 0.5) if ready: s = phantom.stdout.read(1) if s: - buf += s + buf.append(s) else: break # process lines if '\n' in buf: line, buf = buf.split('\n', 1) - _logger.info("phantomjs: %s", line) if line == "ok": - _logger.info("phantomjs test successful") return - if line == "error": - raise Exception("phantomjs test failed") + if line.startswith("error"): + # 'error $message' or use generic message + self.fail(line[6:] or "phantomjs test failed") + _logger.info("phantomjs: %s", line) def phantom_run(self, cmd, timeout): - _logger.info('executing %s', cmd) + _logger.debug('executing `%s`', ' '.join(cmd)) try: phantom = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) except OSError: - _logger.info("phantomjs not found, test skipped") - return + raise unittest2.SkipTest("PhantomJS not found") try: self.phantom_poll(phantom, timeout) finally: