# HG changeset patch # User Julien Cristau # Date 1455784258 -3600 # Node ID 2a7fb3422ae1a0312336384d760b135bc5f7593e # Parent c2a8317d4eecd9f955e562dad3e646b7f0301100 [devtools] stop using lgc.testlib.TestCase It's become incompatible with unittest(2).TestCase due to generative tests. Just keep the datadir/datapath and assertCountEqual bits in our BaseTestCase. diff -r c2a8317d4eec -r 2a7fb3422ae1 cubicweb/devtools/testlib.py --- a/cubicweb/devtools/testlib.py Thu Mar 03 10:25:32 2016 +0100 +++ b/cubicweb/devtools/testlib.py Thu Feb 18 09:30:58 2016 +0100 @@ -31,8 +31,8 @@ import yams.schema -from logilab.common.testlib import TestCase, Tags from logilab.common.pytest import nocoverage +from logilab.common.testlib import Tags from logilab.common.debugger import Debugger from logilab.common.umessage import message_from_string from logilab.common.decorators import cached, classproperty, clear_cache, iclassmethod @@ -52,13 +52,35 @@ if sys.version_info[:2] < (3, 4): - import unittest2 - if not hasattr(unittest2.TestCase, 'subTest'): + from unittest2 import TestCase + if not hasattr(TestCase, 'subTest'): raise ImportError('no subTest support in available unittest2') - class BaseTestCase(unittest2.TestCase, TestCase): - """Mix of logilab.common.testlib.TestCase and unittest2.TestCase""" else: - BaseTestCase = TestCase + from unittest import TestCase + + +# provide a data directory for the test class ################################## + +class BaseTestCase(TestCase): + + @classproperty + @cached + def datadir(cls): # pylint: disable=E0213 + """helper attribute holding the standard test's data directory + """ + mod = sys.modules[cls.__module__] + return join(dirname(abspath(mod.__file__)), 'data') + # cache it (use a class method to cache on class since TestCase is + # instantiated for each test run) + + @classmethod + def datapath(cls, *fname): + """joins the object's datadir and `fname`""" + return join(cls.datadir, *fname) + + +if hasattr(BaseTestCase, 'assertItemsEqual'): + BaseTestCase.assertCountEqual = BaseTestCase.assertItemsEqual # low-level utilities ########################################################## @@ -283,7 +305,7 @@ appid = 'data' configcls = devtools.ApptestConfiguration requestcls = fake.FakeRequest - tags = TestCase.tags | Tags('cubicweb', 'cw_repo') + tags = Tags('cubicweb', 'cw_repo') test_db_id = DEFAULT_EMPTY_DB_ID # anonymous is logged by default in cubicweb test cases