author | Rémi Cardona <remi.cardona@logilab.fr> |
Wed, 28 Jan 2015 11:51:16 +0100 | |
changeset 10164 | 2094262d6553 |
parent 9994 | 12a97d1c6015 |
child 10413 | 22a89d0f4143 |
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/>. |
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
|
18 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
19 |
import os, os.path as osp |
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
20 |
from tempfile import mkdtemp, NamedTemporaryFile, TemporaryFile |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
21 |
import tempfile |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
22 |
from Queue import Queue, Empty |
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
23 |
from subprocess import Popen, check_call, CalledProcessError |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
24 |
from shutil import rmtree, copy as copyfile |
7363
2293c49b290a
don't let windmill/qunit test break apycot warning for all web/test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7051
diff
changeset
|
25 |
from uuid import uuid4 |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
26 |
|
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 |
6535
972bd504daf6
[devtools] Clean up import of f328ec853e18 and use lgc's getlogin.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6514
diff
changeset
|
29 |
from logilab.common.shellutils import getlogin |
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 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
32 |
from cubicweb.web.controller import Controller |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
33 |
from cubicweb.devtools.httptest import CubicWebServerTC |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
34 |
|
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
35 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
36 |
class VerboseCalledProcessError(CalledProcessError): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
37 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
38 |
def __init__(self, returncode, command, stdout, stderr): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
39 |
super(VerboseCalledProcessError, self).__init__(returncode, command) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
40 |
self.stdout = stdout |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
41 |
self.stderr = stderr |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
42 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
43 |
def __str__(self): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
44 |
str = [ super(VerboseCalledProcessError, self).__str__()] |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
45 |
if self.stdout.strip(): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
46 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
47 |
str.append('* process stdout *') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
48 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
49 |
str.append(self.stdout) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
50 |
if self.stderr.strip(): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
51 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
52 |
str.append('* process stderr *') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
53 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
54 |
str.append(self.stderr) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
55 |
return '\n'.join(str) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
56 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
57 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
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 |
class FirefoxHelper(object): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
60 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
61 |
profile_name_mask = 'PYTEST_PROFILE_%(uid)s' |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
62 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
63 |
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
|
64 |
self._process = None |
9992
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
if os.name == 'posix': |
8886
bff36e86f74a
[devtools] prevent Xvfb resets
Julien Cristau <julien.cristau@logilab.fr>
parents:
8757
diff
changeset
|
68 |
self.firefox_cmd = [osp.join(osp.dirname(__file__), 'data', 'xvfb-run.sh'), |
bff36e86f74a
[devtools] prevent Xvfb resets
Julien Cristau <julien.cristau@logilab.fr>
parents:
8757
diff
changeset
|
69 |
'-a', '-s', '-noreset -screen 0 640x480x8'] + 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
|
70 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
71 |
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
|
72 |
self.stop() |
9992
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
73 |
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
|
74 |
'-url', url] |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
78 |
def stop(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
self._process.wait() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
83 |
self._process = None |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
84 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
85 |
def __del__(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
86 |
self.stop() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
87 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
88 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
89 |
class QUnitTestCase(CubicWebServerTC): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
90 |
|
7051
34d8b36480a9
[devtools/qunit] had "qunit" test for tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6535
diff
changeset
|
91 |
tags = CubicWebServerTC.tags | Tags(('qunit',)) |
34d8b36480a9
[devtools/qunit] had "qunit" test for tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6535
diff
changeset
|
92 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
93 |
# 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
|
94 |
all_js_tests = () |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
95 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
96 |
def setUp(self): |
9991
3e7f1e9f3adc
[devtools] allow cross-origin requests for qunit
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8930
diff
changeset
|
97 |
self.config.global_set_option('access-control-allow-origin', '*') |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
class MyQUnitResultController(QUnitResultController): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
101 |
tc = self |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
102 |
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
|
103 |
self._qunit_controller = MyQUnitResultController |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
104 |
self.vreg.register(MyQUnitResultController) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
105 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
106 |
def tearDown(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
107 |
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
|
108 |
self.vreg.unregister(self._qunit_controller) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
109 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
110 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
111 |
def abspath(self, path): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
112 |
"""use self.__module__ to build absolute path if necessary""" |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
113 |
if not osp.isabs(path): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
114 |
dirname = osp.dirname(__import__(self.__module__).__file__) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
115 |
return osp.abspath(osp.join(dirname,path)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
116 |
return path |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
117 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
118 |
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
|
119 |
for args in self.all_js_tests: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
120 |
test_file = self.abspath(args[0]) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
121 |
if len(args) > 1: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
122 |
depends = [self.abspath(dep) for dep in args[1]] |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
123 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
124 |
depends = () |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
125 |
if len(args) > 2: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
126 |
data = [self.abspath(data) for data in args[2]] |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
127 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
128 |
data = () |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
129 |
for js_test in self._test_qunit(test_file, depends, data): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
130 |
yield js_test |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
131 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
132 |
@with_tempdir |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
133 |
def _test_qunit(self, test_file, depends=(), data_files=(), timeout=30): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
134 |
assert osp.exists(test_file), test_file |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
135 |
for dep in depends: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
136 |
assert osp.exists(dep), dep |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
137 |
for data in data_files: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
138 |
assert osp.exists(data), data |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
139 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
140 |
# generate html test file |
5907
5eba1248e12b
[web config] fix old css compat code: we have to modify locate_resource prototype so it return (potentially hacked) file name as well. Should only impact the file cube which has to be released anyway.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5795
diff
changeset
|
141 |
jquery_dir = 'file://' + self.config.locate_resource('jquery.js')[0] |
9993
1ced03652d5e
[devtools] "Keep" some temporary files/dirs around to help with debugging
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9992
diff
changeset
|
142 |
html_test_file = NamedTemporaryFile(suffix='.html', delete=False) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
143 |
html_test_file.write(make_qunit_html(test_file, depends, |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
144 |
base_url=self.config['base-url'], |
5794
a6b81d106775
[devtools/qunit] Locate jquery through cubicwew config to handle installed setup
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5790
diff
changeset
|
145 |
web_data_path=jquery_dir)) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
146 |
html_test_file.flush() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
147 |
# copying data file |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
148 |
for data in data_files: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
149 |
copyfile(data, tempfile.tempdir) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
150 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
154 |
browser = FirefoxHelper() |
9992
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
155 |
# start firefox once to let it init the profile (and run system-wide |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
156 |
# add-ons post setup, blegh), and then kill it ... |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
157 |
browser.start('about:blank') |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
158 |
import time; time.sleep(5) |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
159 |
browser.stop() |
3905682ece11
[devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9991
diff
changeset
|
160 |
# ... then actually run the test file |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
161 |
browser.start(html_test_file.name) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
162 |
test_count = 0 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
163 |
error = False |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
164 |
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
|
165 |
raise cls(*data) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
166 |
while not error: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
167 |
try: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
break |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
173 |
test_count += 1 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
174 |
if result: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
175 |
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
|
176 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
177 |
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
|
178 |
except Empty: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
179 |
error = True |
8692
40d4ba3589be
devtools: improve qunit timeout message
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8261
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
browser.stop() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
'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
|
187 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
188 |
class QUnitResultController(Controller): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
189 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
190 |
__regid__ = 'qunit_result' |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
191 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
192 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
193 |
# 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
|
194 |
_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
|
195 |
_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
|
196 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
197 |
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
|
198 |
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
|
199 |
getattr(self, 'handle_%s' % event)() |
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 |
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
|
202 |
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
|
203 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
212 |
if failures: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
213 |
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
|
214 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
215 |
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
|
216 |
self._log_stack[:] = [] |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
217 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
221 |
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
|
222 |
result = self._cw.form['result'] |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
223 |
message = self._cw.form['message'] |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
224 |
self._log_stack.append('%s: %s' % (result, message)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
225 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
226 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
227 |
def cw_path(*paths): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
228 |
return file_path(osp.join(cubicweb.CW_SOFTWARE_ROOT, *paths)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
229 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
230 |
def file_path(path): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
231 |
return 'file://' + osp.abspath(path) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
232 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
233 |
def build_js_script(host): |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
234 |
return """ |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
235 |
var host = '%s'; |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
236 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
237 |
QUnit.moduleStart = function (name) { |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
238 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
239 |
url: host+'/qunit_result', |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
240 |
data: {"event": "module_start", |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
241 |
"name": name}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
242 |
async: false}); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
243 |
} |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
244 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
245 |
QUnit.testDone = function (name, failures, total) { |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
246 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
247 |
url: host+'/qunit_result', |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
248 |
data: {"event": "test_done", |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
249 |
"name": name, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
250 |
"failures": failures, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
251 |
"total":total}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
252 |
async: false}); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
253 |
} |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
254 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
255 |
QUnit.done = function (failures, total) { |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
256 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
257 |
url: host+'/qunit_result', |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
258 |
data: {"event": "done", |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
259 |
"failures": failures, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
260 |
"total":total}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
261 |
async: false}); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
262 |
window.close(); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
263 |
} |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
264 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
265 |
QUnit.log = function (result, message) { |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
266 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
267 |
url: host+'/qunit_result', |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
268 |
data: {"event": "log", |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
269 |
"result": result, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
270 |
"message": message}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
271 |
async: false}); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
272 |
} |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
273 |
""" % host |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
274 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
275 |
def make_qunit_html(test_file, depends=(), base_url=None, |
5794
a6b81d106775
[devtools/qunit] Locate jquery through cubicwew config to handle installed setup
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5790
diff
changeset
|
276 |
web_data_path=cw_path('web', 'data')): |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
277 |
"""""" |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
278 |
data = { |
5794
a6b81d106775
[devtools/qunit] Locate jquery through cubicwew config to handle installed setup
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5790
diff
changeset
|
279 |
'web_data': web_data_path, |
5787
20377d2fcc70
[qunit] Move qunit.js and qunit.css in devtools/datadirectory
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5780
diff
changeset
|
280 |
'web_test': cw_path('devtools', 'data'), |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
281 |
} |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
282 |
|
9994
12a97d1c6015
[devtools] Fix JS tests' HTML code
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9993
diff
changeset
|
283 |
html = ['''<!DOCTYPE html> |
12a97d1c6015
[devtools] Fix JS tests' HTML code
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9993
diff
changeset
|
284 |
<html> |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
285 |
<head> |
9994
12a97d1c6015
[devtools] Fix JS tests' HTML code
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9993
diff
changeset
|
286 |
<meta http-equiv="content-type" content="application/html; charset=UTF-8"/> |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
287 |
<!-- JS lib used as testing framework --> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
288 |
<link rel="stylesheet" type="text/css" media="all" href="%(web_test)s/qunit.css" /> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
289 |
<script src="%(web_data)s/jquery.js" type="text/javascript"></script> |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5907
diff
changeset
|
290 |
<script src="%(web_test)s/cwmock.js" type="text/javascript"></script> |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
291 |
<script src="%(web_test)s/qunit.js" type="text/javascript"></script>''' |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
292 |
% data] |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
293 |
if base_url is not None: |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
294 |
html.append('<!-- result report tools -->') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
295 |
html.append('<script type="text/javascript">') |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
296 |
html.append(build_js_script(base_url)) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
297 |
html.append('</script>') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
298 |
html.append('<!-- Test script dependencies (tested code for example) -->') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
299 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
300 |
for dep in depends: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
301 |
html.append(' <script src="%s" type="text/javascript"></script>' % file_path(dep)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
302 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
303 |
html.append(' <!-- Test script itself -->') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
304 |
html.append(' <script src="%s" type="text/javascript"></script>'% (file_path(test_file),)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
305 |
html.append(''' </head> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
306 |
<body> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
307 |
<div id="main"> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
308 |
</div> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
309 |
<h1 id="qunit-header">QUnit example</h1> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
310 |
<h2 id="qunit-banner"></h2> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
311 |
<h2 id="qunit-userAgent"></h2> |
9994
12a97d1c6015
[devtools] Fix JS tests' HTML code
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9993
diff
changeset
|
312 |
<ol id="qunit-tests"></ol> |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
313 |
</body> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
314 |
</html>''') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
315 |
return u'\n'.join(html) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
316 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
317 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
318 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
319 |
if __name__ == '__main__': |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
320 |
unittest_main() |