Rev 5834: Properly override test symbols in the imported test module so they are restored after the tests are run. in file:///home/vila/src/bzr/reviews/i18n-utextwrap/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu May 5 09:57:18 UTC 2011
At file:///home/vila/src/bzr/reviews/i18n-utextwrap/
------------------------------------------------------------
revno: 5834
revision-id: v.ladeuil+lp at free.fr-20110505095718-6j404mnfvn1i34tf
parent: v.ladeuil+lp at free.fr-20110505073410-e3fq4p5jo7b03k6k
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: i18n-utextwrap
timestamp: Thu 2011-05-05 11:57:18 +0200
message:
Properly override test symbols in the imported test module so they are restored after the tests are run.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_utextwrap.py'
--- a/bzrlib/tests/test_utextwrap.py 2011-05-05 07:34:10 +0000
+++ b/bzrlib/tests/test_utextwrap.py 2011-05-05 09:57:18 +0000
@@ -139,19 +139,39 @@
# Note that some distribution including Ubuntu doesn't install
# Python's test suite.
try:
- import test.test_textwrap as _test_textwrap
-
- # replace test_textwrap's TextWrapper with UTextWrapper
- _test_textwrap.TextWrapper = utextwrap.UTextWrapper
- _test_textwrap.wrap = utextwrap.wrap
- _test_textwrap.fill = utextwrap.fill
-
- class TestWrap(_test_textwrap.WrapTestCase):
- pass
- class TestLongWord(_test_textwrap.LongWordTestCase):
- pass
- class TestIndent(_test_textwrap.IndentTestCases):
- pass
+ from test import test_textwrap
+
+ def override_textwrap_symbols(testcase):
+ # Override the symbols imported by test_textwrap so it uses our own
+ # replacements.
+ testcase.overrideAttr(test_textwrap, 'TextWrapper',
+ utextwrap.UTextWrapper)
+ testcase.overrideAttr(test_textwrap, 'wrap', utextwrap.wrap)
+ testcase.overrideAttr(test_textwrap, 'fill', utextwrap.fill)
+
+
+ def setup_both(testcase, base_class, reused_class):
+ super(base_class, testcase).setUp()
+ override_textwrap_symbols(testcase)
+ reused_class.setUp(testcase)
+
+
+ class TestWrap(tests.TestCase, test_textwrap.WrapTestCase):
+
+ def setUp(self):
+ setup_both(self, TestWrap, test_textwrap.WrapTestCase)
+
+
+ class TestLongWord(tests.TestCase, test_textwrap.LongWordTestCase):
+
+ def setUp(self):
+ setup_both(self, TestLongWord, test_textwrap.LongWordTestCase)
+
+
+ class TestIndent(tests.TestCase, test_textwrap.IndentTestCases):
+
+ def setUp(self):
+ setup_both(self, TestIndent, test_textwrap.IndentTestCases)
+
except ImportError:
pass
-
More information about the bazaar-commits
mailing list