def test_from_stream_with_simple_seek(self): data = BytesIO(_b('some data')) content = content_from_stream(data, UTF8_TEXT, chunk_size=50, seek_offset=5) self.assertThat(list(content.iter_bytes()), Equals([_b('data')]))
def test_from_stream_eager_loading(self): fd, path = tempfile.mkstemp() self.addCleanup(os.remove, path) os.write(fd, _b("some data")) stream = open(path, "rb") content = content_from_stream(stream, UTF8_TEXT, buffer_now=True) os.write(fd, _b("more data")) os.close(fd) self.assertThat("".join(content.iter_text()), Equals("some data"))
def test_from_stream_eager_loading(self): fd, path = tempfile.mkstemp() self.addCleanup(os.remove, path) self.addCleanup(os.close, fd) os.write(fd, _b('some data')) stream = open(path, 'rb') self.addCleanup(stream.close) content = content_from_stream(stream, UTF8_TEXT, buffer_now=True) os.write(fd, _b('more data')) self.assertThat(''.join(content.iter_text()), Equals('some data'))
def test_from_stream_eager_loading(self): fd, path = tempfile.mkstemp() self.addCleanup(os.remove, path) os.write(fd, 'some data') stream = open(path, 'rb') content = content_from_stream(stream, UTF8_TEXT, buffer_now=True) os.write(fd, 'more data') os.close(fd) self.assertThat( _b('').join(content.iter_bytes()), Equals('some data'))
def make_content(): content_obj = content_from_stream( stream, ContentType('text', 'plain', {'charset': 'iso8859-1'}), buffer_now=True) # Work around a bug in older testtools where an empty file would result # in None being decoded and exploding. # See: https://bugs.launchpad.net/autopilot/+bug/1517289 if list(content_obj.iter_text()) == []: _logger.warning('Followed stream is empty.') content_obj = safe_text_content('Unable to read file data.') test_case.addDetail(content_name, content_obj)
def test_from_stream(self): data = StringIO("some data") content = content_from_stream(data, UTF8_TEXT, chunk_size=2) self.assertThat(list(content.iter_bytes()), Equals(["so", "me", " d", "at", "a"]))
def test_from_stream_default_type(self): data = StringIO("some data") content = content_from_stream(data) self.assertThat(content.content_type, Equals(UTF8_TEXT))
def test_from_stream_with_whence_seek(self): data = BytesIO(_b('some data')) content = content_from_stream( data, UTF8_TEXT, chunk_size=50, seek_offset=-4, seek_whence=2) self.assertThat( list(content.iter_bytes()), Equals([_b('data')]))
def test_from_stream(self): data = StringIO('some data') content = content_from_stream(data, UTF8_TEXT, chunk_size=2) self.assertThat( list(content.iter_bytes()), Equals(['so', 'me', ' d', 'at', 'a']))
def test_from_stream_default_type(self): data = StringIO('some data') content = content_from_stream(data) self.assertThat(content.content_type, Equals(UTF8_TEXT))
def test_from_stream(self): data = StringIO('some data') content = content_from_stream(data, UTF8_TEXT, chunk_size=2) self.assertThat(list(content.iter_bytes()), Equals(['so', 'me', ' d', 'at', 'a']))