summaryrefslogtreecommitdiff
path: root/testtools
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-11-29 16:57:42 -0600
committerBenjamin Peterson <benjamin@python.org>2009-11-29 16:57:42 -0600
commit4d2c8dffadf46cec0babfacec992b2546f7a1016 (patch)
treeb1425572904f105d814cdc93196f090934899204 /testtools
parent2745000bd2465c0f35175bf05dbe3bf8bcde4a31 (diff)
downloadtesttools-4d2c8dffadf46cec0babfacec992b2546f7a1016.tar.gz
add a _u function to imitate unicode literals on python3
Diffstat (limited to 'testtools')
-rw-r--r--testtools/tests/test_content.py7
-rw-r--r--testtools/tests/test_testresult.py21
-rw-r--r--testtools/utils.py12
3 files changed, 27 insertions, 13 deletions
diff --git a/testtools/tests/test_content.py b/testtools/tests/test_content.py
index e45593c..7cf92e1 100644
--- a/testtools/tests/test_content.py
+++ b/testtools/tests/test_content.py
@@ -4,6 +4,7 @@ import sys
import unittest
from testtools.content import Content, TracebackContent
from testtools.content_type import ContentType
+from testtools.utils import _u
def test_suite():
@@ -44,12 +45,12 @@ class TestContent(unittest.TestCase):
def test_iter_text_decodes(self):
content_type = ContentType("text", "strange", {"charset":"utf8"})
- content = Content(content_type, lambda:[u"bytes\xea".encode("utf8")])
- self.assertEqual([u"bytes\xea"], list(content.iter_text()))
+ content = Content(content_type, lambda:[_u("bytes\xea").encode("utf8")])
+ self.assertEqual([_u("bytes\xea")], list(content.iter_text()))
def test_iter_text_default_charset_iso_8859_1(self):
content_type = ContentType("text", "strange")
- text = u"bytes\xea"
+ text = _u("bytes\xea")
iso_version = text.encode("ISO-8859-1")
content = Content(content_type, lambda:[iso_version])
self.assertEqual([text], list(content.iter_text()))
diff --git a/testtools/tests/test_testresult.py b/testtools/tests/test_testresult.py
index 6332de9..5bb24ba 100644
--- a/testtools/tests/test_testresult.py
+++ b/testtools/tests/test_testresult.py
@@ -21,6 +21,7 @@ from testtools import (
)
from testtools.content import Content, ContentType
from testtools.matchers import DocTestMatches
+from testtools.utils import _u
from testtools.tests.helpers import (
LoggingResult,
Python26TestResult,
@@ -55,7 +56,7 @@ class TestTestResultContract(TestCase):
def test_addSkipped(self):
# Calling addSkip(test, reason) completes ok.
result = self.makeResult()
- result.addSkip(self, u"Skipped for some reason")
+ result.addSkip(self, _u("Skipped for some reason"))
def test_addSkipped_details(self):
# Calling addSkip(test, reason) completes ok.
@@ -121,15 +122,15 @@ class TestTestResult(TestCase):
# Calling addSkip on a TestResult records the test that was skipped in
# its skip_reasons dict.
result = self.makeResult()
- result.addSkip(self, u"Skipped for some reason")
- self.assertEqual({u"Skipped for some reason":[self]},
+ result.addSkip(self, _u("Skipped for some reason"))
+ self.assertEqual({_u("Skipped for some reason"):[self]},
result.skip_reasons)
- result.addSkip(self, u"Skipped for some reason")
- self.assertEqual({u"Skipped for some reason":[self, self]},
+ result.addSkip(self, _u("Skipped for some reason"))
+ self.assertEqual({_u("Skipped for some reason"):[self, self]},
result.skip_reasons)
- result.addSkip(self, u"Skipped for another reason")
- self.assertEqual({u"Skipped for some reason":[self, self],
- u"Skipped for another reason":[self]},
+ result.addSkip(self, _u("Skipped for another reason"))
+ self.assertEqual({_u("Skipped for some reason"):[self, self],
+ _u("Skipped for another reason"):[self]},
result.skip_reasons)
def test_now_datetime_now(self):
@@ -202,7 +203,7 @@ class TestMultiTestResult(TestWithFakeExceptions):
def test_addSkipped(self):
# Calling `addSkip` on a `MultiTestResult` calls addSkip on its
# results.
- reason = u"Skipped for some reason"
+ reason = _u("Skipped for some reason")
self.multiResult.addSkip(self, reason)
self.assertResultLogsEqual([('addSkip', self, reason)])
@@ -422,7 +423,7 @@ class TestThreadSafeForwardingResult(TestWithFakeExceptions):
self.result1.addError(self, exc_info1)
exc_info2 = self.makeExceptionInfo(AssertionError, 'failure')
self.result1.addFailure(self, exc_info2)
- reason = u"Skipped for some reason"
+ reason = _u("Skipped for some reason")
self.result1.addSkip(self, reason)
self.result1.addSuccess(self)
self.assertEqual([('startTest', self),
diff --git a/testtools/utils.py b/testtools/utils.py
index 2f502d0..0d9c3f4 100644
--- a/testtools/utils.py
+++ b/testtools/utils.py
@@ -2,12 +2,24 @@
"""Utilities for dealing with stuff in unittest."""
+
+import sys
+
__metaclass__ = type
__all__ = [
'iterate_tests',
]
+if sys.version_info > (3, 0):
+ def _u(s):
+ """Replacement for u'some string' in Python 3."""
+ return s
+else:
+ def _u(s):
+ return unicode(s)
+
+
def iterate_tests(test_suite_or_case):
"""Iterate through all of the test cases in `test_suite_or_case`."""
try: