cubicweb/devtools/qunit.py
branch3.24
changeset 11923 acfb9aa4845e
parent 11746 7cf5a915e2e9
child 12567 26744ad37953
equal deleted inserted replaced
11922:5f886dc718ab 11923:acfb9aa4845e
    98 
    98 
    99     tags = cwwebtest.CubicWebTestTC.tags | Tags(('qunit',))
    99     tags = cwwebtest.CubicWebTestTC.tags | Tags(('qunit',))
   100 
   100 
   101     # testfile, (dep_a, dep_b)
   101     # testfile, (dep_a, dep_b)
   102     all_js_tests = ()
   102     all_js_tests = ()
       
   103     timeout_error = RuntimeError
   103 
   104 
   104     def setUp(self):
   105     def setUp(self):
   105         super(QUnitTestCase, self).setUp()
   106         super(QUnitTestCase, self).setUp()
   106         self.test_queue = Queue()
   107         self.test_queue = Queue()
   107         class MyQUnitResultController(QUnitResultController):
   108         class MyQUnitResultController(QUnitResultController):
   147 
   148 
   148             def runtime_error(*data):
   149             def runtime_error(*data):
   149                 with open(browser.log_file) as logf:
   150                 with open(browser.log_file) as logf:
   150                     print(logf.read())
   151                     print(logf.read())
   151                 raise RuntimeError(*data)
   152                 raise RuntimeError(*data)
       
   153 
       
   154             def timeout_failure(test_file, timeout, test_count):
       
   155                 with open(browser.log_file) as logf:
       
   156                     print(logf.read())
       
   157                 msg = '%s inactivity timeout (%is). %i test results received' % (
       
   158                     test_file, timeout, test_count)
       
   159                 raise self.timeout_error(msg)
   152 
   160 
   153             while not error:
   161             while not error:
   154                 try:
   162                 try:
   155                     result, test_name, msg = self.test_queue.get(timeout=timeout)
   163                     result, test_name, msg = self.test_queue.get(timeout=timeout)
   156                     test_name = '%s (%s)' % (test_name, test_file)
   164                     test_name = '%s (%s)' % (test_name, test_file)
   161                         yield test_name, lambda *args: 1, ()
   169                         yield test_name, lambda *args: 1, ()
   162                     else:
   170                     else:
   163                         yield test_name, self.fail, (msg, )
   171                         yield test_name, self.fail, (msg, )
   164                 except Empty:
   172                 except Empty:
   165                     error = True
   173                     error = True
   166                     msg = '%s inactivity timeout (%is). %i test results received'
   174                     yield test_file, timeout_failure, (test_file, timeout, test_count)
   167                     yield test_file, runtime_error, (msg % (test_file, timeout, test_count), )
       
   168 
   175 
   169         if test_count <= 0 and not error:
   176         if test_count <= 0 and not error:
   170             yield test_name, runtime_error, ('No test yielded by qunit for %s' % test_file, )
   177             yield test_name, runtime_error, ('No test yielded by qunit for %s' % test_file, )
   171 
   178 
   172 
   179