author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 11 Oct 2010 14:45:25 +0200 | |
changeset 6442 | ac7126d2cd73 |
parent 6424 | f443a2b8a5c7 |
child 6514 | f328ec853e18 |
permissions | -rw-r--r-- |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
1 |
import os, os.path as osp |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
2 |
import signal |
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
3 |
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
|
4 |
import tempfile |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
5 |
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
|
6 |
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
|
7 |
from shutil import rmtree, copy as copyfile |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
8 |
from uuid import uuid4 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
9 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
10 |
# imported by default to simplify further import statements |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
11 |
from logilab.common.testlib import unittest_main, with_tempdir, InnerTest |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
12 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
13 |
import os |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
14 |
import cubicweb |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
15 |
from cubicweb.view import StartupView |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
16 |
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
|
17 |
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
|
18 |
|
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
19 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
20 |
class VerboseCalledProcessError(CalledProcessError): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
21 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
22 |
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
|
23 |
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
|
24 |
self.stdout = stdout |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
25 |
self.stderr = stderr |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
26 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
27 |
def __str__(self): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
28 |
str = [ super(VerboseCalledProcessError, self).__str__()] |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
29 |
if self.stdout.strip(): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
30 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
31 |
str.append('* process stdout *') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
32 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
33 |
str.append(self.stdout) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
34 |
if self.stderr.strip(): |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
35 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
36 |
str.append('* process stderr *') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
37 |
str.append('******************') |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
38 |
str.append(self.stderr) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
39 |
return '\n'.join(str) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
40 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
41 |
|
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
42 |
|
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
43 |
class FirefoxHelper(object): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
44 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
45 |
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
|
46 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
47 |
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
|
48 |
self._process = None |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
49 |
self._tmp_dir = mkdtemp() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
50 |
self._profile_data = {'uid': uuid4()} |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
51 |
self._profile_name = self.profile_name_mask % self._profile_data |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
52 |
fnull = open(os.devnull, 'w') |
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
53 |
stdout = TemporaryFile() |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
54 |
stderr = TemporaryFile() |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
55 |
try: |
5790
26680cbc507b
[devtools/qunit] in safe mode, ffox launches a stupid popup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5788
diff
changeset
|
56 |
check_call(['firefox', '-no-remote', '-CreateProfile', |
5779
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
57 |
'%s %s' % (self._profile_name, self._tmp_dir)], |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
58 |
stdout=stdout, stderr=stderr) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
59 |
except CalledProcessError, cpe: |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
60 |
stdout.seek(0) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
61 |
stderr.seek(0) |
916ddfd72ac2
[qunit] improve output of suprocess error
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5742
diff
changeset
|
62 |
raise VerboseCalledProcessError(cpe.returncode, cpe.cmd, stdout.read(), stderr.read()) |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
63 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
64 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
65 |
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
|
66 |
self.stop() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
67 |
fnull = open(os.devnull, 'w') |
5790
26680cbc507b
[devtools/qunit] in safe mode, ffox launches a stupid popup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5788
diff
changeset
|
68 |
self._process = Popen(['firefox', '-no-remote', '-P', self._profile_name, url], |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
69 |
stdout=fnull, stderr=fnull) |
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 stop(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
72 |
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
|
73 |
assert self._process.returncode is None, self._process.returncode |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
74 |
os.kill(self._process.pid, signal.SIGTERM) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
75 |
self._process.wait() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
76 |
self._process = None |
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 __del__(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
79 |
self.stop() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
80 |
rmtree(self._tmp_dir) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
81 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
82 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
83 |
class QUnitTestCase(CubicWebServerTC): |
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 |
# 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
|
86 |
all_js_tests = () |
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 |
def setUp(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
class MyQUnitResultController(QUnitResultController): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
92 |
tc = self |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
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
|
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): |
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).tearDown() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
99 |
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
|
100 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
101 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
102 |
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
|
103 |
"""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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
return path |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
108 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
115 |
depends = () |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
119 |
data = () |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
120 |
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
|
121 |
yield js_test |
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 |
@with_tempdir |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
131 |
# 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
|
132 |
jquery_dir = 'file://' + self.config.locate_resource('jquery.js')[0] |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
133 |
html_test_file = NamedTemporaryFile(suffix='.html') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
# copying data file |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
145 |
browser = FirefoxHelper() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
146 |
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
|
147 |
test_count = 0 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
148 |
error = False |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
149 |
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
|
150 |
raise cls(*data) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
151 |
while not error: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
152 |
try: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
break |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
158 |
test_count += 1 |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
159 |
if result: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
160 |
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
|
161 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
162 |
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
|
163 |
except Empty: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
164 |
error = True |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
165 |
yield InnerTest(test_file, raise_exception, RuntimeError, "%s did not report execution end. %i test processed so far." % (test_file, test_count)) |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
166 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
167 |
browser.stop() |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
168 |
if test_count <= 0 and not error: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
169 |
yield InnerTest(test_name, raise_exception, RuntimeError, 'No test yielded by qunit for %s' % test_file) |
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 |
class QUnitResultController(Controller): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
172 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
173 |
__regid__ = 'qunit_result' |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
174 |
|
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 |
# 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
|
177 |
_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
|
178 |
_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
|
179 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
192 |
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
|
193 |
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
|
194 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
195 |
if failures: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
196 |
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
|
197 |
else: |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
198 |
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
|
199 |
self._log_stack[:] = [] |
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_done(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
202 |
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
|
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_log(self): |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
209 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
210 |
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
|
211 |
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
|
212 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
213 |
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
|
214 |
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
|
215 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
216 |
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
|
217 |
return """ |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
218 |
var host = '%s'; |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
219 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
220 |
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
|
221 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
222 |
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
|
223 |
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
|
224 |
"name": name}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
225 |
async: false}); |
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 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
228 |
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
|
229 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
230 |
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
|
231 |
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
|
232 |
"name": name, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
233 |
"failures": failures, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
234 |
"total":total}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
235 |
async: false}); |
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 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
238 |
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
|
239 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
240 |
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
|
241 |
data: {"event": "done", |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
242 |
"failures": failures, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
243 |
"total":total}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
244 |
async: false}); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
245 |
window.close(); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
246 |
} |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
247 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
248 |
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
|
249 |
jQuery.ajax({ |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
250 |
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
|
251 |
data: {"event": "log", |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
252 |
"result": result, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
253 |
"message": message}, |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
254 |
async: false}); |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
255 |
} |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
256 |
""" % host |
5742
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
257 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
258 |
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
|
259 |
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
|
260 |
"""""" |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
261 |
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
|
262 |
'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
|
263 |
'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
|
264 |
} |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
265 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
266 |
html = ['''<html> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
267 |
<head> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
268 |
<!-- 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
|
269 |
<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
|
270 |
<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
|
271 |
<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
|
272 |
<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
|
273 |
% data] |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5950
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
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
|
278 |
html.append('</script>') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
279 |
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
|
280 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
html.append(''' </head> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
287 |
<body> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
288 |
<div id="main"> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
289 |
</div> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
290 |
<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
|
291 |
<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
|
292 |
<h2 id="qunit-userAgent"></h2> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
293 |
<ol id="qunit-tests"> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
294 |
</body> |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
295 |
</html>''') |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
296 |
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
|
297 |
|
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
298 |
|
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 |
if __name__ == '__main__': |
74c19dac29cf
Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
301 |
unittest_main() |