# HG changeset patch # User RĂ©mi Cardona # Date 1431535084 -7200 # Node ID 5b0bacc7778c4fd8f0aa89eaba2f8c1c96ed391c # Parent d9d5c70c45dcf3438c6dbde0baa7c5c65af2aaf8 [devtools] qunit: refactor functions into QUnitView Related to #5533333. diff -r d9d5c70c45dc -r 5b0bacc7778c devtools/qunit.py --- a/devtools/qunit.py Wed May 13 17:13:51 2015 +0200 +++ b/devtools/qunit.py Wed May 13 18:38:04 2015 +0200 @@ -220,9 +220,87 @@ templatable = False + depends = None + test_file = None + def call(self, **kwargs): - self.w(make_qunit_html(self.test_file, self.depends, - base_url=self._cw.base_url())) + w = self.w + req = self._cw + data = { + 'jquery': req.data_url('jquery.js'), + 'web_test': req.build_url('cwsoftwareroot/devtools/data'), + } + w(u''' + + + + + + + + ''' + % data) + w(u'') + w(u'') + w(u'') + + prefix = len(cubicweb.CW_SOFTWARE_ROOT) + 1 + for dep in self.depends: + dep = req.build_url('cwsoftwareroot/') + dep[prefix:] + w(u' ' % dep) + + w(u' ') + test_url = req.build_url('cwsoftwareroot/') + self.test_file[prefix:] + w(u' ' % test_url) + w(u''' + +
+
+

QUnit example

+

+

+
    + + ''') class CWSoftwareRootStaticController(StaticFileController): @@ -237,101 +315,5 @@ STATIC_CONTROLLERS.append(CWSoftwareRootStaticController) -def cw_path(*paths): - return '/cwsoftwareroot/' + '/'.join(paths) - - -def file_path(path): - l = len(cubicweb.CW_SOFTWARE_ROOT) + 1 - return '/cwsoftwareroot/' + path[l:] - - -def build_js_script(host): - return """ - var host = '%s'; - var BASE_URL = host; - - QUnit.moduleStart = function (name) { - jQuery.ajax({ - url: host+'/qunit_result', - data: {"event": "module_start", - "name": name}, - async: false}); - } - - QUnit.testDone = function (name, failures, total) { - jQuery.ajax({ - url: host+'/qunit_result', - data: {"event": "test_done", - "name": name, - "failures": failures, - "total":total}, - async: false}); - } - - QUnit.done = function (failures, total) { - jQuery.ajax({ - url: host+'/qunit_result', - data: {"event": "done", - "failures": failures, - "total":total}, - async: false}); - window.close(); - } - - QUnit.log = function (result, message) { - jQuery.ajax({ - url: host+'/qunit_result', - data: {"event": "log", - "result": result, - "message": message}, - async: false}); - } - """ % host - - -def make_qunit_html(test_file, depends=(), base_url=None): - """""" - data = { - 'web_data': '/data', - 'web_test': cw_path('devtools', 'data'), - } - - html = [''' - - - - - - - - ''' - % data] - if base_url is not None: - html.append('') - html.append('') - html.append('') - - for dep in depends: - html.append(' ' % file_path(dep)) - - html.append(' ') - html.append(' '% (file_path(test_file),)) - html.append(''' - -
    -
    -

    QUnit example

    -

    -

    -
      - -''') - return u'\n'.join(html) - - - if __name__ == '__main__': unittest_main()