* Test ids which include non-ascii unicode characters are now supported.
authorRobert Collins <robertc@robertcollins.net>
Mon, 17 Dec 2012 07:58:13 +0000 (20:58 +1300)
committerRobert Collins <robertc@robertcollins.net>
Mon, 17 Dec 2012 07:58:13 +0000 (20:58 +1300)
  (Robert Collins, #1029866)

NEWS
python/subunit/__init__.py
python/subunit/tests/test_test_protocol.py

diff --git a/NEWS b/NEWS
index 7174e1302cf5c7fc48b5792369ed8e92752c5d89..472fc62503f69f6da1b8d5da09d2af7758ed8f73 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@ BUG FIXES
 * ``python/subunit/tests/test_run.py`` and ``python/subunit/filters.py`` were
   not included in the 0.0.8 tarball. (Robert Collins)
 
+* Test ids which include non-ascii unicode characters are now supported.
+  (Robert Collins, #1029866)
+
 * The ``failfast`` option to ``subunit.run`` will now work. The dependency on
   testtools has been raised to 0.9.23 to permit this.
   (Robert Collins, #1090582)
index ebe6e8c82cbdf70e0a5045b430c3a109cfee0b1c..749eda12dfb59d8874aebd0867d03c232d84f1d8 100644 (file)
@@ -689,7 +689,7 @@ class TestProtocolClient(testresult.TestResult):
         :param error_permitted: If True then one and only one of error or
             details must be supplied. If False then error must not be supplied
             and details is still optional.  """
-        self._stream.write(_b("%s: %s" % (outcome, test.id())))
+        self._stream.write(_b("%s: " % outcome) + self._test_id(test))
         if error_permitted:
             if error is None and details is None:
                 raise ValueError
@@ -737,10 +737,16 @@ class TestProtocolClient(testresult.TestResult):
         if self.failfast:
             self.stop()
 
+    def _test_id(self, test):
+        result = test.id()
+        if type(result) is not bytes:
+            result = result.encode('utf8')
+        return result
+
     def startTest(self, test):
         """Mark a test as starting its test run."""
         super(TestProtocolClient, self).startTest(test)
-        self._stream.write(_b("test: %s\n" % test.id()))
+        self._stream.write(_b("test: ") + self._test_id(test) + _b("\n"))
         self._stream.flush()
 
     def stopTest(self, test):
index ec6830d03b82333d6a0ac4af9a068e21368d4410..7831ba16cdfd75e7ca164cb999cb19ab6e00d661 100644 (file)
@@ -18,7 +18,7 @@ import datetime
 import unittest
 import os
 
-from testtools import skipIf, TestCase, TestResult
+from testtools import PlaceHolder, skipIf, TestCase, TestResult
 from testtools.compat import _b, _u, BytesIO
 from testtools.content import Content, TracebackContent, text_content
 from testtools.content_type import ContentType
@@ -1133,6 +1133,7 @@ class TestTestProtocolClient(unittest.TestCase):
     def setUp(self):
         self.io = BytesIO()
         self.protocol = subunit.TestProtocolClient(self.io)
+        self.unicode_test = PlaceHolder(_u('\u2603'))
         self.test = TestTestProtocolClient("test_start_test")
         self.sample_details = {'something':Content(
             ContentType('text', 'plain'), lambda:[_b('serialised\nform')])}
@@ -1145,6 +1146,12 @@ class TestTestProtocolClient(unittest.TestCase):
         self.protocol.startTest(self.test)
         self.assertEqual(self.io.getvalue(), _b("test: %s\n" % self.test.id()))
 
+    def test_start_test_unicode_id(self):
+        """Test startTest on a TestProtocolClient."""
+        self.protocol.startTest(self.unicode_test)
+        expected = _b("test: ") + _u('\u2603').encode('utf8') + _b("\n")
+        self.assertEqual(expected, self.io.getvalue())
+
     def test_stop_test(self):
         # stopTest doesn't output anything.
         self.protocol.stopTest(self.test)
@@ -1156,6 +1163,12 @@ class TestTestProtocolClient(unittest.TestCase):
         self.assertEqual(
             self.io.getvalue(), _b("successful: %s\n" % self.test.id()))
 
+    def test_add_outcome_unicode_id(self):
+        """Test addSuccess on a TestProtocolClient."""
+        self.protocol.addSuccess(self.unicode_test)
+        expected = _b("successful: ") + _u('\u2603').encode('utf8') + _b("\n")
+        self.assertEqual(expected, self.io.getvalue())
+
     def test_add_success_details(self):
         """Test addSuccess on a TestProtocolClient with details."""
         self.protocol.addSuccess(self.test, details=self.sample_details)