Пример #1
0
 def test_smoke_write(self):
     stream = io.StringIO()
     writer = IOLogRecordWriter(stream)
     writer.write_record(self._RECORD)
     self.assertEqual(stream.getvalue(), self._TEXT)
     writer.close()
     with self.assertRaises(ValueError):
         stream.getvalue()
Пример #2
0
 def test_smoke_write(self):
     stream = io.StringIO()
     writer = IOLogRecordWriter(stream)
     writer.write_record(self._RECORD)
     self.assertEqual(stream.getvalue(), self._TEXT)
     writer.close()
     with self.assertRaises(ValueError):
         stream.getvalue()
Пример #3
0
def make_io_log(io_log, io_log_dir):
    """
    Make the io logs serialization to json and return the saved file pathname
    WARNING: The caller has to remove the file once done with it!
    """
    with NamedTemporaryFile(
        delete=False, suffix='.record.gz', dir=io_log_dir) as byte_stream, \
            GzipFile(fileobj=byte_stream, mode='wb') as gzip_stream, \
            TextIOWrapper(gzip_stream, encoding='UTF-8') as text_stream:
        writer = IOLogRecordWriter(text_stream)
        for record in io_log:
            writer.write_record(record)
    return byte_stream.name
Пример #4
0
def make_io_log(io_log, io_log_dir):
    """
    Make the io logs serialization to json and return the saved file pathname
    WARNING: The caller has to remove the file once done with it!
    """
    with NamedTemporaryFile(
        delete=False, suffix='.record.gz', dir=io_log_dir) as byte_stream, \
            GzipFile(fileobj=byte_stream, mode='wb') as gzip_stream, \
            TextIOWrapper(gzip_stream, encoding='UTF-8') as text_stream:
        writer = IOLogRecordWriter(text_stream)
        for record in io_log:
            writer.write_record(record)
    return byte_stream.name