From 8eb109578e86a1e432b4a29081c610cfdbac4b82 Mon Sep 17 00:00:00 2001 From: Thomi Richards Date: Tue, 19 Nov 2013 15:28:28 +1300 Subject: Python 3 compatibility fixes. --- python/subunit/_output.py | 10 +++++----- python/subunit/tests/test_output_filter.py | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'python') diff --git a/python/subunit/_output.py b/python/subunit/_output.py index b3ab675..dd81b87 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -17,7 +17,7 @@ from argparse import ArgumentParser import datetime from functools import partial from sys import stdout -from string import split +from testtools.compat import _b from subunit.v2 import StreamResultToBytes @@ -55,7 +55,7 @@ def parse_arguments(args=None, ParserClass=ArgumentParser): ) common_args.add_argument( "--attach-file", - type=file, + type=open, help="Attach a file to the result stream for this test." ) common_args.add_argument( @@ -68,7 +68,7 @@ def parse_arguments(args=None, ParserClass=ArgumentParser): common_args.add_argument( "--tags", help="A comma-separated list of tags to associate with this test.", - type=partial(split, sep=','), + type=lambda s: s.split(','), default=None ) sub_parsers = parser.add_subparsers( @@ -165,7 +165,7 @@ def generate_bytestream(args, output_writer): def write_chunked_file(file_obj, test_id, output_writer, chunk_size=1024, mime_type=None): reader = partial(file_obj.read, chunk_size) - for chunk in iter(reader, ''): + for chunk in iter(reader, _b('')): output_writer.status( test_id=test_id, file_name=file_obj.name, @@ -176,7 +176,7 @@ def write_chunked_file(file_obj, test_id, output_writer, chunk_size=1024, output_writer.status( test_id=test_id, file_name=file_obj.name, - file_bytes='', + file_bytes=_b(''), mime_type=mime_type, eof=True, ) diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index fac47ff..be42ea6 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -21,6 +21,7 @@ from functools import partial from io import BytesIO from tempfile import NamedTemporaryFile from testtools import TestCase +from testtools.compat import _b from testtools.matchers import ( Equals, IsInstance, @@ -102,7 +103,6 @@ class OutputFilterArgumentParserTests(TestCase): args = safe_parse_arguments( args=[command, 'foo', '--attach-file', tmp_file.name] ) - self.assertThat(args.attach_file, IsInstance(file)) self.assertThat(args.attach_file.name, Equals(tmp_file.name)) def test_all_commands_accept_mimetype_argument(self): @@ -298,26 +298,26 @@ class FileChunkingTests(TestCase): return result def test_file_chunk_size_is_honored(self): - result = self._write_chunk_file("Hello", 1) + result = self._write_chunk_file(_b("Hello"), 1) self.assertThat( result._events, MatchesListwise([ - MatchesCall(call='status', file_bytes='H', mime_type=None, eof=False), - MatchesCall(call='status', file_bytes='e', mime_type=None, eof=False), - MatchesCall(call='status', file_bytes='l', mime_type=None, eof=False), - MatchesCall(call='status', file_bytes='l', mime_type=None, eof=False), - MatchesCall(call='status', file_bytes='o', mime_type=None, eof=False), - MatchesCall(call='status', file_bytes='', mime_type=None, eof=True), + MatchesCall(call='status', file_bytes=_b('H'), mime_type=None, eof=False), + MatchesCall(call='status', file_bytes=_b('e'), mime_type=None, eof=False), + MatchesCall(call='status', file_bytes=_b('l'), mime_type=None, eof=False), + MatchesCall(call='status', file_bytes=_b('l'), mime_type=None, eof=False), + MatchesCall(call='status', file_bytes=_b('o'), mime_type=None, eof=False), + MatchesCall(call='status', file_bytes=_b(''), mime_type=None, eof=True), ]) ) def test_file_mimetype_is_honored(self): - result = self._write_chunk_file("SomeData", 1024, "text/plain") + result = self._write_chunk_file(_b("SomeData"), 1024, "text/plain") self.assertThat( result._events, MatchesListwise([ - MatchesCall(call='status', file_bytes='SomeData', mime_type="text/plain"), - MatchesCall(call='status', file_bytes='', mime_type="text/plain"), + MatchesCall(call='status', file_bytes=_b('SomeData'), mime_type="text/plain"), + MatchesCall(call='status', file_bytes=_b(''), mime_type="text/plain"), ]) ) @@ -339,10 +339,10 @@ class MatchesCall(Matcher): } def __init__(self, **kwargs): - unknown_kwargs = filter( + unknown_kwargs = list(filter( lambda k: k not in self._position_lookup, kwargs - ) + )) if unknown_kwargs: raise ValueError("Unknown keywords: %s" % ','.join(unknown_kwargs)) self._filters = kwargs -- cgit v1.2.1