diff options
author | Joel Wright <joel.wright@sohonet.com> | 2015-01-04 21:14:02 +0000 |
---|---|---|
committer | Joel Wright <joel.wright@sohonet.com> | 2015-01-23 11:46:13 +0000 |
commit | bd42c2b00d0e4a18d15fd494bd9b9101742c4a37 (patch) | |
tree | 13aeb9c42ef70b6cd13a9bd3fd001cb66c81e1c5 /tests/unit/utils.py | |
parent | 7709fea51e71084163cf56c4d11a280ca4388357 (diff) | |
download | python-swiftclient-bd42c2b00d0e4a18d15fd494bd9b9101742c4a37.tar.gz |
This patch fixes downloading files to stdout.
This patch fixes downloading files to stdout and modifies
_SwiftReader to operate as an iterator that performs file
checks at the end of iteration as well as a context manager.
File verification checks have been removed from __exit__
and added to __iter__.
Change-Id: I3250bdeeef8484a9122c4b5b854756a7c8f8731e
Closes-Bug: 1395922
Closes-Bug: 1387376
Diffstat (limited to 'tests/unit/utils.py')
-rw-r--r-- | tests/unit/utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/unit/utils.py b/tests/unit/utils.py index 9d8aacc..873f4c6 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -340,13 +340,41 @@ class MockHttpTest(testtools.TestCase): reload_module(c) +class CaptureStreamBuffer(object): + """ + CaptureStreamBuffer is used for testing raw byte writing for PY3. Anything + written here is decoded as utf-8 and written to the parent CaptureStream + """ + def __init__(self, captured_stream): + self._captured_stream = captured_stream + + def write(self, bytes_data): + # No encoding, just convert the raw bytes into a str for testing + # The below call also validates that we have a byte string. + self._captured_stream.write( + ''.join(map(chr, bytes_data)) + ) + + class CaptureStream(object): def __init__(self, stream): self.stream = stream self._capture = six.StringIO() + self._buffer = CaptureStreamBuffer(self) self.streams = [self.stream, self._capture] + @property + def buffer(self): + if six.PY3: + return self._buffer + else: + raise AttributeError( + 'Output stream has no attribute "buffer" in Python2') + + def flush(self): + pass + def write(self, *args, **kwargs): for stream in self.streams: stream.write(*args, **kwargs) |