devtools/test/unittest_qunit.py
author Rémi Cardona <remi.cardona@logilab.fr>
Wed, 02 Sep 2015 12:08:31 +0200
changeset 10887 a0315e9f4c20
parent 8930 6a02be304486
child 10935 049209b9e9d6
permissions -rw-r--r--
[tests] Don't import QUnitTestCase into tests' global namespace Unittest's test loader will try to execute QUnitTestCase's test_javascripts method. However this class is intended to be subclassed, not to be executed directly. This change has the following consequences: * slightly faster test execution * almost all rtags warnings are gone
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
JSTESTDIR = osp.abspath(osp.join(osp.dirname(__file__), 'data', 'js_examples'))
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
def js(name):
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
    return osp.join(JSTESTDIR, name)
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
10887
a0315e9f4c20 [tests] Don't import QUnitTestCase into tests' global namespace
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8930
diff changeset
    12
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
    13
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
    all_js_tests = (
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
                    (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
    16
                    (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
    17
                    (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
    18
                   )
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    20
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    21
    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
    22
        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
    23
        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
    24
        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
    25
        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
    26
        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
    27
        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
    28
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    29
74c19dac29cf Add a QUnitTestCase class to run qunit test case.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    30
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
    31
    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
    32
    main()