diff options
| author | Robert Collins <robertc@robertcollins.net> | 2011-04-25 11:09:54 +1200 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2011-04-25 11:09:54 +1200 |
| commit | 86cff2f184f6bbd34fd330bae739a29a34a78d2a (patch) | |
| tree | f12e16329989ee0ea9e20b2e49e20f1f46516d74 /python | |
| parent | b21965301c3ab72e5e19848d1019ca2d8e83da50 (diff) | |
| download | subunit-git-86cff2f184f6bbd34fd330bae739a29a34a78d2a.tar.gz | |
Progress.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/__init__.py | 9 | ||||
| -rw-r--r-- | python/subunit/details.py | 11 | ||||
| -rw-r--r-- | python/subunit/tests/test_details.py | 28 | ||||
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 14 |
4 files changed, 34 insertions, 28 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 281c3dd..6a46a40 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -185,6 +185,7 @@ class _ParserState(object): def __init__(self, parser): self.parser = parser + self._test_sym = (_b('test'), _b('testing')) def addError(self, offset, line): """An 'error:' directive has been read.""" @@ -213,7 +214,7 @@ class _ParserState(object): cmd, rest = parts offset = len(cmd) + 1 cmd = cmd.rstrip(_b(':')) - if cmd in ('test', 'testing'): + if cmd in self._test_sym: self.startTest(offset, line) elif cmd == 'error': self.addError(offset, line) @@ -332,8 +333,9 @@ class _OutSideTest(_ParserState): def startTest(self, offset, line): """A test start command received.""" self.parser._state = self.parser._in_test - self.parser._current_test = RemotedTestCase(line[offset:-1]) - self.parser.current_test_description = line[offset:-1] + test_name = line[offset:-1].decode('utf8') + self.parser._current_test = RemotedTestCase(test_name) + self.parser.current_test_description = test_name self.parser.client.startTest(self.parser._current_test) self.parser.subunitLineReceived(line) @@ -1138,6 +1140,7 @@ def get_default_formatter(): def _make_stream_binary(stream): """Ensure that a stream will be binary safe. See _make_binary_on_windows.""" if getattr(stream, 'fileno', None) is not None: + print (stream, type(stream)) _make_binary_on_windows(stream.fileno()) def _make_binary_on_windows(fileno): diff --git a/python/subunit/details.py b/python/subunit/details.py index 36c9974..9790543 100644 --- a/python/subunit/details.py +++ b/python/subunit/details.py @@ -17,10 +17,13 @@ """Handlers for outcome details.""" from testtools import content, content_type -from testtools.compat import StringIO +from testtools.compat import _b, StringIO from subunit import chunked +end_marker = _b("]\n") +quoted_marker = _b(" ]") + class DetailsParser(object): """Base class/API reference for details parsing.""" @@ -30,14 +33,14 @@ class SimpleDetailsParser(DetailsParser): """Parser for single-part [] delimited details.""" def __init__(self, state): - self._message = "" + self._message = _b("") self._state = state def lineReceived(self, line): - if line == "]\n": + if line == end_marker: self._state.endDetails() return - if line[0:2] == " ]": + if line[0:2] == quoted_marker: # quoted ] start self._message += line[1:] else: diff --git a/python/subunit/tests/test_details.py b/python/subunit/tests/test_details.py index 06eb430..49010d2 100644 --- a/python/subunit/tests/test_details.py +++ b/python/subunit/tests/test_details.py @@ -16,7 +16,7 @@ import unittest -from testtools.compat import StringIO +from testtools.compat import _b, StringIO import subunit.tests from subunit import content, content_type, details @@ -32,20 +32,20 @@ class TestSimpleDetails(unittest.TestCase): def test_lineReceived(self): parser = details.SimpleDetailsParser(None) - parser.lineReceived("foo\n") - parser.lineReceived("bar\n") - self.assertEqual("foo\nbar\n", parser._message) + parser.lineReceived(_b("foo\n")) + parser.lineReceived(_b("bar\n")) + self.assertEqual(_b("foo\nbar\n"), parser._message) def test_lineReceived_escaped_bracket(self): parser = details.SimpleDetailsParser(None) - parser.lineReceived("foo\n") - parser.lineReceived(" ]are\n") - parser.lineReceived("bar\n") - self.assertEqual("foo\n]are\nbar\n", parser._message) + parser.lineReceived(_b("foo\n")) + parser.lineReceived(_b(" ]are\n")) + parser.lineReceived(_b("bar\n")) + self.assertEqual(_b("foo\n]are\nbar\n"), parser._message) def test_get_message(self): parser = details.SimpleDetailsParser(None) - self.assertEqual("", parser.get_message()) + self.assertEqual(_b(""), parser.get_message()) def test_get_details(self): parser = details.SimpleDetailsParser(None) @@ -54,13 +54,13 @@ class TestSimpleDetails(unittest.TestCase): expected['traceback'] = content.Content( content_type.ContentType("text", "x-traceback", {'charset': 'utf8'}), - lambda:[""]) + lambda:[_b("")]) found = parser.get_details() self.assertEqual(expected.keys(), found.keys()) self.assertEqual(expected['traceback'].content_type, found['traceback'].content_type) - self.assertEqual(''.join(expected['traceback'].iter_bytes()), - ''.join(found['traceback'].iter_bytes())) + self.assertEqual(_b('').join(expected['traceback'].iter_bytes()), + _b('').join(found['traceback'].iter_bytes())) def test_get_details_skip(self): parser = details.SimpleDetailsParser(None) @@ -68,7 +68,7 @@ class TestSimpleDetails(unittest.TestCase): expected = {} expected['reason'] = content.Content( content_type.ContentType("text", "plain"), - lambda:[""]) + lambda:[_b("")]) found = parser.get_details("skip") self.assertEqual(expected, found) @@ -78,7 +78,7 @@ class TestSimpleDetails(unittest.TestCase): expected = {} expected['message'] = content.Content( content_type.ContentType("text", "plain"), - lambda:[""]) + lambda:[_b("")]) found = parser.get_details("success") self.assertEqual(expected, found) diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 8171696..5541653 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -18,7 +18,7 @@ import datetime import unittest import os -from testtools.compat import _u, StringIO +from testtools.compat import _b, _u, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType from testtools.tests.helpers import ( @@ -372,8 +372,8 @@ class TestInTestMultipart(unittest.TestCase): def setUp(self): self.client = ExtendedTestResult() self.protocol = subunit.TestProtocolServer(self.client) - self.protocol.lineReceived("test mcdonalds farm\n") - self.test = subunit.RemotedTestCase("mcdonalds farm") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) + self.test = subunit.RemotedTestCase(_u("mcdonalds farm")) def test__outcome_sets_details_parser(self): self.protocol._reading_success_details.details_parser = None @@ -770,13 +770,13 @@ class TestTestProtocolServerStreamTags(unittest.TestCase): ], self.client._events) def test_tags_do_not_get_set_on_test(self): - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) test = self.client._events[0][-1] self.assertEqual(None, getattr(test, 'tags', None)) def test_tags_do_not_get_set_on_global_tags(self): - self.protocol.lineReceived("tags: foo bar\n") - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("tags: foo bar\n")) + self.protocol.lineReceived(_b("test mcdonalds farm\n")) test = self.client._events[-1][-1] self.assertEqual(None, getattr(test, 'tags', None)) @@ -884,7 +884,7 @@ class TestExecTestCase(unittest.TestCase): bing = subunit.RemotedTestCase("bing crosby") bing_details = {} bing_details['traceback'] = Content(ContentType("text", "x-traceback", - {'charset': 'utf8'}), lambda:["foo.c:53:ERROR invalid state\n"]) + {'charset': 'utf8'}), lambda:[_b("foo.c:53:ERROR invalid state\n")]) an_error = subunit.RemotedTestCase("an error") error_details = {} self.assertEqual([ |
