devtools/test/unittest_qunit.py
author Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
Thu, 26 Nov 2015 11:30:54 +0100
changeset 10935 049209b9e9d6
parent 10887 a0315e9f4c20
child 10940 343a43503018
permissions -rw-r--r--
[qunit] stop dealing with filesystem paths qunit tests need a few things served by cubicweb: - qunit itself, which is now handled by CWDevtoolsStaticController (serving files in cubicweb/devtools/data) - standard cubicweb or cubes data files, handled by the DataController - the tests themselves and their dependencies. These can live in <apphome>/data or <apphome>/static and be served by one of the STATIC_CONTROLLERS This avoids having to guess in CWSoftwareRootStaticController where to serve things from (some files may be installed, others are in the source tree), and should hopefully make it possible to have these tests pass when using tox, and to write qunit tests for cubes, outside of cubicweb itself. This requires modifying the tests to only declare URL paths instead of filesystem paths, and moving support files below test/data/static.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10887
a0315e9f4c20 [tests] Don't import QUnitTestCase into tests' global namespace
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8930
diff changeset
     1
from os import path as osp
5742
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
10887
a0315e9f4c20 [tests] Don't import QUnitTestCase into tests' global namespace
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8930
diff changeset
     3
from cubicweb.devtools import qunit
a0315e9f4c20 [tests] Don't import QUnitTestCase into tests' global namespace
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8930
diff changeset
     4
5742
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
def js(name):
10935
049209b9e9d6 [qunit] stop dealing with filesystem paths
Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
parents: 10887
diff changeset
     7
    return '/static/js_examples/' + name
5742
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
10887
a0315e9f4c20 [tests] Don't import QUnitTestCase into tests' global namespace
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8930
diff changeset
     9
class QUnitTestCaseTC(qunit.QUnitTestCase):
5742
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
    all_js_tests = (
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    12
                    (js('test_simple_success.js'),),
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
                    (js('test_with_dep.js'), (js('dep_1.js'),)),
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
                    (js('test_with_ordered_deps.js'), (js('dep_1.js'), js('deps_2.js'),)),
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
                   )
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    16
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    17
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    18
    def test_simple_failure(self):
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
        js_tests = list(self._test_qunit(js('test_simple_failure.js')))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5742
diff changeset
    20
        self.assertEqual(len(js_tests), 3)
5742
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    21
        test_1, test_2, test_3 = js_tests
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    22
        self.assertRaises(self.failureException, test_1[0], *test_1[1:])
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    23
        self.assertRaises(self.failureException, test_2[0], *test_2[1:])
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    24
        test_3[0](*test_3[1:])
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    25
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
if __name__ == '__main__':
10887
a0315e9f4c20 [tests] Don't import QUnitTestCase into tests' global namespace
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8930
diff changeset
    28
    from unittest import main
a0315e9f4c20 [tests] Don't import QUnitTestCase into tests' global namespace
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8930
diff changeset
    29
    main()