cubicweb/devtools/test/unittest_qunit.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 14 Jan 2016 18:35:07 +0100
changeset 11076 403a901b6b1e
parent 11057 0b59724cb3f2
child 11898 c5d3382f14e9
permissions -rw-r--r--
[devtools] Re-implement generative tests using subtests Generative tests as implemented in logilab.common.testib are not compatible with tests runner other than lgc.pytest and this implementation differs from the standard library, which has support for subtests_ since Python 3.4. Use unittest2 to bridge the gap. Maybe it'd be good to implement this on logilab.common.testlib side at some point. Let's see how this gets received here first. .. _subtests: https://docs.python.org/3/library/unittest.html#subtests

from cubicweb.devtools import qunit


def js(name):
    return '/static/js_examples/' + name

class QUnitTestCaseTC(qunit.QUnitTestCase):

    all_js_tests = (
                    (js('test_simple_success.js'),),
                    (js('test_with_dep.js'), (js('dep_1.js'),)),
                    (js('test_with_ordered_deps.js'), (js('dep_1.js'), js('deps_2.js'),)),
                   )


    def test_simple_failure(self):
        js_tests = list(self._test_qunit(js('test_simple_failure.js')))
        self.assertEqual(len(js_tests), 3)
        test_1, test_2, test_3 = js_tests
        self.assertRaises(self.failureException, test_1[1], *test_1[2:])
        self.assertRaises(self.failureException, test_2[1], *test_2[2:])
        test_3[1](*test_3[2:])


if __name__ == '__main__':
    from unittest import main
    main()