CsvResult cannot handle characters beyond ascii in test ids

Reported by Jonathan Lange on 2012-07-27
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
subunit
Wishlist
Unassigned

Bug Description

jml@grace:~/src/subunit$ PYTHONPATH=python:$PYTHONPATH python2
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from testtools import PlaceHolder
>>> from subunit import TestProtocolClient
>>> from subunit.filters import run_tests_from_stream
>>> from subunit.test_results import CsvResult
>>> test = PlaceHolder(u'☃'.encode('utf8'))
>>> test.id()
'\xe2\x98\x83'
>>> subunit_file = open('test.subunit', 'wb')
>>> client = TestProtocolClient(subunit_file)
>>> client.startTest(test)
>>> client.addSuccess(test)
>>> client.stopTest(test)
>>> subunit_file.flush()
>>> subunit_file.close()
>>> with open('test.subunit', 'rb') as f:
... print f.read()
...
test: ☃
successful: ☃

>>> with open('test.subunit', 'r') as f:
... print f.read()
...
test: ☃
successful: ☃

>>> from StringIO import StringIO
>>> output = StringIO()
>>> csv_result = CsvResult(output)
>>> with open('test.subunit', 'rb') as f:
... run_tests_from_stream(f, csv_result)
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/jml/src/subunit/python/subunit/filters.py", line 55, in run_tests_from_stream
    test.run(result)
  File "/home/jml/src/subunit/python/subunit/__init__.py", line 1171, in run
    protocol.lineReceived(line)
  File "/home/jml/src/subunit/python/subunit/__init__.py", line 560, in lineReceived
    self._state.lineReceived(line)
  File "/home/jml/src/subunit/python/subunit/__init__.py", line 258, in lineReceived
    self.addSuccess(offset, line)
  File "/home/jml/src/subunit/python/subunit/__init__.py", line 362, in addSuccess
    self.parser._reading_success_details)
  File "/home/jml/src/subunit/python/subunit/__init__.py", line 298, in _outcome
    self.parser.client.stopTest(self.parser._current_test)
  File "/usr/local/lib/python2.7/dist-packages/testtools/testresult/real.py", line 643, in stopTest
    return self.decorated.stopTest(test)
  File "/home/jml/src/subunit/python/subunit/test_results.py", line 617, in stopTest
    details=self._details)
  File "/home/jml/src/subunit/python/subunit/test_results.py", line 668, in _on_test
    self._write_row([encoded_id, status, start_time, stop_time])
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2603' in position 0: ordinal not in range(128)
>>> output.getvalue()
'test,status,start_time,stop_time\r\n'

Robert Collins (lifeless) wrote :

Looks like its decoding correctly, failing on encode to csv.

Changed in subunit:
status: New → Triaged
summary: - CsvResult cannot handle UTF-8 input in subunit stream
+ CsvResult cannot handle characters beyond ascii in test ids
Changed in subunit:
importance: Undecided → Wishlist
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers