author | Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr> |
Mon, 19 Oct 2015 23:39:30 +0200 | |
changeset 10948 | 3ffacbdf7e9c |
parent 10946 | f7179ecfbae0 |
permissions | -rw-r--r-- |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
1 |
# copyright 2010-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
3 |
# |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
4 |
# This file is part of CubicWeb. |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
5 |
# |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
9 |
# any later version. |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
10 |
# |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
14 |
# details. |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
15 |
# |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
18 |
from __future__ import absolute_import |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7363
diff
changeset
|
19 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
20 |
import os, os.path as osp |
10886
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
21 |
import errno |
10885
b3a192804b63
[devtools/qunit] Remove unused code
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10608
diff
changeset
|
22 |
from tempfile import mkdtemp |
10886
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
23 |
from subprocess import Popen, PIPE, STDOUT |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
24 |
|
10608
7fc548d9dd8e
[py3k] import queue using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10583
diff
changeset
|
25 |
from six.moves.queue import Queue, Empty |
7fc548d9dd8e
[py3k] import queue using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10583
diff
changeset
|
26 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
27 |
# imported by default to simplify further import statements |
7051
34d8b36480a9
[devtools/qunit] had "qunit" test for tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6535
diff
changeset
|
28 |
from logilab.common.testlib import unittest_main, with_tempdir, InnerTest, Tags |
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
29 |
import webtest.http |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
30 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
31 |
import cubicweb |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
32 |
from cubicweb.view import View |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
33 |
from cubicweb.web.controller import Controller |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
34 |
from cubicweb.web.views.staticcontrollers import StaticFileController, STATIC_CONTROLLERS |
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
35 |
from cubicweb.devtools import webtest as cwwebtest |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
36 |
|
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
37 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
38 |
class FirefoxHelper(object): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
39 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
40 |
def __init__(self, url=None): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
41 |
self._process = None |
9992
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
42 |
self._profile_dir = mkdtemp(prefix='cwtest-ffxprof-') |
8226
a3d3bdd46463
[devtools] Use Xvfb to run firefox in js tests on posix platforms
Julien Cristau <julien.cristau@logilab.fr>
parents:
7879
diff
changeset
|
43 |
self.firefox_cmd = ['firefox', '-no-remote'] |
a3d3bdd46463
[devtools] Use Xvfb to run firefox in js tests on posix platforms
Julien Cristau <julien.cristau@logilab.fr>
parents:
7879
diff
changeset
|
44 |
if os.name == 'posix': |
8886
bff36e86f74a
[devtools] prevent Xvfb resets
Julien Cristau <julien.cristau@logilab.fr>
parents:
8757
diff
changeset
|
45 |
self.firefox_cmd = [osp.join(osp.dirname(__file__), 'data', 'xvfb-run.sh'), |
10421
9bbb35f52d4b
[devtools] qunit: increase resolution and depth of Xvfb screen
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10413
diff
changeset
|
46 |
'-a', '-s', '-noreset -screen 0 800x600x24'] + self.firefox_cmd |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
47 |
|
10886
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
48 |
def test(self): |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
49 |
try: |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
50 |
proc = Popen(['firefox', '--help'], stdout=PIPE, stderr=STDOUT) |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
51 |
stdout, _ = proc.communicate() |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
52 |
return proc.returncode == 0, stdout |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
53 |
except OSError as exc: |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
54 |
if exc.errno == errno.ENOENT: |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
55 |
msg = '[%s] %s' % (errno.errorcode[exc.errno], exc.strerror) |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
56 |
return False, msg |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
57 |
raise |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
58 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
59 |
def start(self, url): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
60 |
self.stop() |
9992
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
61 |
cmd = self.firefox_cmd + ['-silent', '--profile', self._profile_dir, |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
62 |
'-url', url] |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
63 |
with open(os.devnull, 'w') as fnull: |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
64 |
self._process = Popen(cmd, stdout=fnull, stderr=fnull) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
65 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
66 |
def stop(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
67 |
if self._process is not None: |
5780
07c1d64dff34
[qunit] check that the browser has not died by himself before we asked him to stop.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5779
diff
changeset
|
68 |
assert self._process.returncode is None, self._process.returncode |
8757
375acf527559
[devtools/qunit] don't open-code subprocess.Popen.terminate
Julien Cristau <julien.cristau@logilab.fr>
parents:
8756
diff
changeset
|
69 |
self._process.terminate() |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
70 |
self._process.wait() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
71 |
self._process = None |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
72 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
73 |
def __del__(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
74 |
self.stop() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
75 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
76 |
|
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
77 |
class QUnitTestCase(cwwebtest.CubicWebTestTC): |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
78 |
|
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
79 |
tags = cwwebtest.CubicWebTestTC.tags | Tags(('qunit',)) |
7051
34d8b36480a9
[devtools/qunit] had "qunit" test for tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6535
diff
changeset
|
80 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
81 |
# testfile, (dep_a, dep_b) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
82 |
all_js_tests = () |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
83 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
84 |
def setUp(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
85 |
super(QUnitTestCase, self).setUp() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
86 |
self.test_queue = Queue() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
87 |
class MyQUnitResultController(QUnitResultController): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
88 |
tc = self |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
89 |
test_queue = self.test_queue |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
90 |
self._qunit_controller = MyQUnitResultController |
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
91 |
self.webapp.app.appli.vreg.register(MyQUnitResultController) |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
92 |
self.webapp.app.appli.vreg.register(QUnitView) |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
93 |
self.webapp.app.appli.vreg.register(CWDevtoolsStaticController) |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
94 |
self.server = webtest.http.StopableWSGIServer.create(self.webapp.app) |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
95 |
self.config.global_set_option('base-url', self.server.application_url) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
96 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
97 |
def tearDown(self): |
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
98 |
self.server.shutdown() |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
99 |
self.webapp.app.appli.vreg.unregister(self._qunit_controller) |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
100 |
self.webapp.app.appli.vreg.unregister(QUnitView) |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
101 |
self.webapp.app.appli.vreg.unregister(CWDevtoolsStaticController) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
102 |
super(QUnitTestCase, self).tearDown() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
103 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
104 |
def test_javascripts(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
105 |
for args in self.all_js_tests: |
10583
97c88aa7c779
[qunit] remove unused 'data_files' parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10432
diff
changeset
|
106 |
self.assertIn(len(args), (1, 2)) |
10935
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
107 |
test_file = args[0] |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
108 |
if len(args) > 1: |
10935
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
109 |
depends = args[1] |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
110 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
111 |
depends = () |
10583
97c88aa7c779
[qunit] remove unused 'data_files' parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10432
diff
changeset
|
112 |
for js_test in self._test_qunit(test_file, depends): |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
113 |
yield js_test |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
114 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
115 |
@with_tempdir |
10583
97c88aa7c779
[qunit] remove unused 'data_files' parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10432
diff
changeset
|
116 |
def _test_qunit(self, test_file, depends=(), timeout=10): |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
117 |
QUnitView.test_file = test_file |
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
118 |
QUnitView.depends = depends |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
119 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
120 |
while not self.test_queue.empty(): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
121 |
self.test_queue.get(False) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
122 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
123 |
browser = FirefoxHelper() |
10886
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
124 |
isavailable, reason = browser.test() |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
125 |
if not isavailable: |
941e3d15c338
[devtools/qunit] Fail quickly if firefox is not installed
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10885
diff
changeset
|
126 |
self.fail('firefox not available or not working properly (%s)' % reason) |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
127 |
browser.start(self.config['base-url'] + "?vid=qunit") |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
128 |
test_count = 0 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
129 |
error = False |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
130 |
def raise_exception(cls, *data): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
131 |
raise cls(*data) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
132 |
while not error: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
133 |
try: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
134 |
result, test_name, msg = self.test_queue.get(timeout=timeout) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
135 |
test_name = '%s (%s)' % (test_name, test_file) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
136 |
self.set_description(test_name) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
137 |
if result is None: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
138 |
break |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
139 |
test_count += 1 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
140 |
if result: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
141 |
yield InnerTest(test_name, lambda : 1) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
142 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
143 |
yield InnerTest(test_name, self.fail, msg) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
144 |
except Empty: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
145 |
error = True |
8692
40d4ba3589be
devtools: improve qunit timeout message
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8261
diff
changeset
|
146 |
msg = '%s inactivity timeout (%is). %i test results received' |
40d4ba3589be
devtools: improve qunit timeout message
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8261
diff
changeset
|
147 |
yield InnerTest(test_file, raise_exception, RuntimeError, |
40d4ba3589be
devtools: improve qunit timeout message
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8261
diff
changeset
|
148 |
msg % (test_file, timeout, test_count)) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
149 |
browser.stop() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
150 |
if test_count <= 0 and not error: |
8692
40d4ba3589be
devtools: improve qunit timeout message
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8261
diff
changeset
|
151 |
yield InnerTest(test_name, raise_exception, RuntimeError, |
40d4ba3589be
devtools: improve qunit timeout message
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8261
diff
changeset
|
152 |
'No test yielded by qunit for %s' % test_file) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
153 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
154 |
class QUnitResultController(Controller): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
155 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
156 |
__regid__ = 'qunit_result' |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
157 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
158 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
159 |
# Class variables to circumvent the instantiation of a new Controller for each request. |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
160 |
_log_stack = [] # store QUnit log messages |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
161 |
_current_module_name = '' # store the current QUnit module name |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
162 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
163 |
def publish(self, rset=None): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
164 |
event = self._cw.form['event'] |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
165 |
getattr(self, 'handle_%s' % event)() |
10934
3f18ec9d96dd
[devtools] fix QUnitResultController
Julien Cristau <julien.cristau@logilab.fr>
parents:
10886
diff
changeset
|
166 |
return b'' |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
167 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
168 |
def handle_module_start(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
169 |
self.__class__._current_module_name = self._cw.form.get('name', '') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
170 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
171 |
def handle_test_done(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
172 |
name = '%s // %s' % (self._current_module_name, self._cw.form.get('name', '')) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
173 |
failures = int(self._cw.form.get('failures', 0)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
174 |
total = int(self._cw.form.get('total', 0)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
175 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
176 |
self._log_stack.append('%i/%i assertions failed' % (failures, total)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
177 |
msg = '\n'.join(self._log_stack) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
178 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
179 |
if failures: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
180 |
self.tc.test_queue.put((False, name, msg)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
181 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
182 |
self.tc.test_queue.put((True, name, msg)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
183 |
self._log_stack[:] = [] |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
184 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
185 |
def handle_done(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
186 |
self.tc.test_queue.put((None, None, None)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
187 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
188 |
def handle_log(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
189 |
result = self._cw.form['result'] |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
190 |
message = self._cw.form.get('message', '<no message>') |
10432
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
191 |
actual = self._cw.form.get('actual') |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
192 |
expected = self._cw.form.get('expected') |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
193 |
source = self._cw.form.get('source') |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
194 |
log = '%s: %s' % (result, message) |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
195 |
if result == 'false' and actual is not None and expected is not None: |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
196 |
log += ' (got: %s, expected: %s)' % (actual, expected) |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
197 |
if source is not None: |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
198 |
log += '\n' + source |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
199 |
self._log_stack.append(log) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
200 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
201 |
|
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
202 |
class QUnitView(View): |
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
203 |
__regid__ = 'qunit' |
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
204 |
|
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
205 |
templatable = False |
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
206 |
|
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
207 |
depends = None |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
208 |
test_file = None |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
209 |
|
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
210 |
def call(self, **kwargs): |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
211 |
w = self.w |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
212 |
req = self._cw |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
213 |
w(u'''<!DOCTYPE html> |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
214 |
<html> |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
215 |
<head> |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
216 |
<meta http-equiv="content-type" content="application/html; charset=UTF-8"/> |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
217 |
<!-- JS lib used as testing framework --> |
10946
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
218 |
<link rel="stylesheet" type="text/css" media="all" href="/devtools/qunit.css" /> |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
219 |
<script src="/data/jquery.js" type="text/javascript"></script> |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
220 |
<script src="/devtools/cwmock.js" type="text/javascript"></script> |
f7179ecfbae0
[qunit] move from CubicWebServerTC to CubicWebTestTC
Julien Cristau <julien.cristau@logilab.fr>
parents:
10945
diff
changeset
|
221 |
<script src="/devtools/qunit.js" type="text/javascript"></script>''') |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
222 |
w(u'<!-- result report tools -->') |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
223 |
w(u'<script type="text/javascript">') |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
224 |
w(u"var BASE_URL = '%s';" % req.base_url()) |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
225 |
w(u''' |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
226 |
QUnit.moduleStart(function (details) { |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
227 |
jQuery.ajax({ |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
228 |
url: BASE_URL + 'qunit_result', |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
229 |
data: {"event": "module_start", |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
230 |
"name": details.name}, |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
231 |
async: false}); |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
232 |
}); |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
233 |
|
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
234 |
QUnit.testDone(function (details) { |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
235 |
jQuery.ajax({ |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
236 |
url: BASE_URL + 'qunit_result', |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
237 |
data: {"event": "test_done", |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
238 |
"name": details.name, |
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
239 |
"failures": details.failed, |
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
240 |
"total": details.total}, |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
241 |
async: false}); |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
242 |
}); |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
243 |
|
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
244 |
QUnit.done(function (details) { |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
245 |
jQuery.ajax({ |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
246 |
url: BASE_URL + 'qunit_result', |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
247 |
data: {"event": "done", |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
248 |
"failures": details.failed, |
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
249 |
"total": details.total}, |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
250 |
async: false}); |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
251 |
}); |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
252 |
|
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
253 |
QUnit.log(function (details) { |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
254 |
jQuery.ajax({ |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
255 |
url: BASE_URL + 'qunit_result', |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
256 |
data: {"event": "log", |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
257 |
"result": details.result, |
10432
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
258 |
"actual": details.actual, |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
259 |
"expected": details.expected, |
f5ec46a6867a
[devtools] qunit: show helpful data when an assertion fails
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
260 |
"source": details.source, |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
261 |
"message": details.message}, |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
262 |
async: false}); |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
263 |
});''') |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
264 |
w(u'</script>') |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
265 |
w(u'<!-- Test script dependencies (tested code for example) -->') |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
266 |
|
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
267 |
for dep in self.depends: |
10935
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
268 |
w(u' <script src="%s" type="text/javascript"></script>\n' % dep) |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
269 |
|
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
270 |
w(u' <!-- Test script itself -->') |
10935
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
271 |
w(u' <script src="%s" type="text/javascript"></script>' % self.test_file) |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
272 |
w(u''' </head> |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
273 |
<body> |
10427
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
274 |
<div id="qunit-fixture"></div> |
7677c0401864
[devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10425
diff
changeset
|
275 |
<div id="qunit"></div> |
10424
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
276 |
</body> |
5b0bacc7778c
[devtools] qunit: refactor functions into QUnitView
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10423
diff
changeset
|
277 |
</html>''') |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
278 |
|
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
279 |
|
10935
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
280 |
class CWDevtoolsStaticController(StaticFileController): |
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
281 |
__regid__ = 'devtools' |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
282 |
|
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
283 |
def publish(self, rset=None): |
10935
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
284 |
staticdir = osp.join(osp.dirname(__file__), 'data') |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
285 |
relpath = self.relpath[len(self.__regid__) + 1:] |
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
286 |
return self.static_file(osp.join(staticdir, relpath)) |
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
287 |
|
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
288 |
|
10935
049209b9e9d6
[qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents:
10934
diff
changeset
|
289 |
STATIC_CONTROLLERS.append(CWDevtoolsStaticController) |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
290 |
|
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9994
diff
changeset
|
291 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
292 |
if __name__ == '__main__': |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
293 |
unittest_main() |