104 if not osp.isabs(path): |
104 if not osp.isabs(path): |
105 dirname = osp.dirname(__import__(self.__module__).__file__) |
105 dirname = osp.dirname(__import__(self.__module__).__file__) |
106 return osp.abspath(osp.join(dirname,path)) |
106 return osp.abspath(osp.join(dirname,path)) |
107 return path |
107 return path |
108 |
108 |
109 |
|
110 |
|
111 def test_javascripts(self): |
109 def test_javascripts(self): |
112 for args in self.all_js_tests: |
110 for args in self.all_js_tests: |
113 test_file = self.abspath(args[0]) |
111 test_file = self.abspath(args[0]) |
114 if len(args) > 1: |
112 if len(args) > 1: |
115 depends = [self.abspath(dep) for dep in args[1]] |
113 depends = [self.abspath(dep) for dep in args[1]] |
128 for dep in depends: |
126 for dep in depends: |
129 assert osp.exists(dep), dep |
127 assert osp.exists(dep), dep |
130 for data in data_files: |
128 for data in data_files: |
131 assert osp.exists(data), data |
129 assert osp.exists(data), data |
132 |
130 |
133 |
|
134 # generate html test file |
131 # generate html test file |
135 jquery_dir = 'file://' + self.config.locate_resource('jquery.js')[0] |
132 jquery_dir = 'file://' + self.config.locate_resource('jquery.js')[0] |
136 html_test_file = NamedTemporaryFile(suffix='.html') |
133 html_test_file = NamedTemporaryFile(suffix='.html') |
137 html_test_file.write(make_qunit_html(test_file, depends, |
134 html_test_file.write(make_qunit_html(test_file, depends, |
138 server_data=(self.test_host, self.test_port), |
135 base_url=self.config['base-url'], |
139 web_data_path=jquery_dir)) |
136 web_data_path=jquery_dir)) |
140 html_test_file.flush() |
137 html_test_file.flush() |
141 # copying data file |
138 # copying data file |
142 for data in data_files: |
139 for data in data_files: |
143 copyfile(data, tempfile.tempdir) |
140 copyfile(data, tempfile.tempdir) |
208 result = self._cw.form['result'] |
205 result = self._cw.form['result'] |
209 message = self._cw.form['message'] |
206 message = self._cw.form['message'] |
210 self._log_stack.append('%s: %s' % (result, message)) |
207 self._log_stack.append('%s: %s' % (result, message)) |
211 |
208 |
212 |
209 |
213 |
|
214 def cw_path(*paths): |
210 def cw_path(*paths): |
215 return file_path(osp.join(cubicweb.CW_SOFTWARE_ROOT, *paths)) |
211 return file_path(osp.join(cubicweb.CW_SOFTWARE_ROOT, *paths)) |
216 |
212 |
217 def file_path(path): |
213 def file_path(path): |
218 return 'file://' + osp.abspath(path) |
214 return 'file://' + osp.abspath(path) |
219 |
215 |
220 def build_js_script( host, port): |
216 def build_js_script(host): |
221 return """ |
217 return """ |
222 var host = '%s'; |
218 var host = '%s'; |
223 var port = '%s'; |
|
224 |
219 |
225 QUnit.moduleStart = function (name) { |
220 QUnit.moduleStart = function (name) { |
226 jQuery.ajax({ |
221 jQuery.ajax({ |
227 url: 'http://'+host+':'+port+'/qunit_result', |
222 url: host+'/qunit_result', |
228 data: {"event": "module_start", |
223 data: {"event": "module_start", |
229 "name": name}, |
224 "name": name}, |
230 async: false}); |
225 async: false}); |
231 } |
226 } |
232 |
227 |
233 QUnit.testDone = function (name, failures, total) { |
228 QUnit.testDone = function (name, failures, total) { |
234 jQuery.ajax({ |
229 jQuery.ajax({ |
235 url: 'http://'+host+':'+port+'/qunit_result', |
230 url: host+'/qunit_result', |
236 data: {"event": "test_done", |
231 data: {"event": "test_done", |
237 "name": name, |
232 "name": name, |
238 "failures": failures, |
233 "failures": failures, |
239 "total":total}, |
234 "total":total}, |
240 async: false}); |
235 async: false}); |
241 } |
236 } |
242 |
237 |
243 QUnit.done = function (failures, total) { |
238 QUnit.done = function (failures, total) { |
244 jQuery.ajax({ |
239 jQuery.ajax({ |
245 url: 'http://'+host+':'+port+'/qunit_result', |
240 url: host+'/qunit_result', |
246 data: {"event": "done", |
241 data: {"event": "done", |
247 "failures": failures, |
242 "failures": failures, |
248 "total":total}, |
243 "total":total}, |
249 async: false}); |
244 async: false}); |
250 window.close(); |
245 window.close(); |
251 } |
246 } |
252 |
247 |
253 QUnit.log = function (result, message) { |
248 QUnit.log = function (result, message) { |
254 jQuery.ajax({ |
249 jQuery.ajax({ |
255 url: 'http://'+host+':'+port+'/qunit_result', |
250 url: host+'/qunit_result', |
256 data: {"event": "log", |
251 data: {"event": "log", |
257 "result": result, |
252 "result": result, |
258 "message": message}, |
253 "message": message}, |
259 async: false}); |
254 async: false}); |
260 } |
255 } |
261 """ % (host, port) |
256 """ % host |
262 |
257 |
263 def make_qunit_html(test_file, depends=(), server_data=None, |
258 def make_qunit_html(test_file, depends=(), base_url=None, |
264 web_data_path=cw_path('web', 'data')): |
259 web_data_path=cw_path('web', 'data')): |
265 """""" |
260 """""" |
266 data = { |
261 data = { |
267 'web_data': web_data_path, |
262 'web_data': web_data_path, |
268 'web_test': cw_path('devtools', 'data'), |
263 'web_test': cw_path('devtools', 'data'), |
274 <link rel="stylesheet" type="text/css" media="all" href="%(web_test)s/qunit.css" /> |
269 <link rel="stylesheet" type="text/css" media="all" href="%(web_test)s/qunit.css" /> |
275 <script src="%(web_data)s/jquery.js" type="text/javascript"></script> |
270 <script src="%(web_data)s/jquery.js" type="text/javascript"></script> |
276 <script src="%(web_test)s/cwmock.js" type="text/javascript"></script> |
271 <script src="%(web_test)s/cwmock.js" type="text/javascript"></script> |
277 <script src="%(web_test)s/qunit.js" type="text/javascript"></script>''' |
272 <script src="%(web_test)s/qunit.js" type="text/javascript"></script>''' |
278 % data] |
273 % data] |
279 if server_data is not None: |
274 if base_url is not None: |
280 host, port = server_data |
|
281 html.append('<!-- result report tools -->') |
275 html.append('<!-- result report tools -->') |
282 html.append('<script type="text/javascript">') |
276 html.append('<script type="text/javascript">') |
283 html.append(build_js_script(host, port)) |
277 html.append(build_js_script(base_url)) |
284 html.append('</script>') |
278 html.append('</script>') |
285 html.append('<!-- Test script dependencies (tested code for example) -->') |
279 html.append('<!-- Test script dependencies (tested code for example) -->') |
286 |
280 |
287 for dep in depends: |
281 for dep in depends: |
288 html.append(' <script src="%s" type="text/javascript"></script>' % file_path(dep)) |
282 html.append(' <script src="%s" type="text/javascript"></script>' % file_path(dep)) |