def test_write_deflate_file_empty(self): sink = TextSink( self.path, compression_type=CompressionTypes.DEFLATE) self._write_lines(sink, []) with open(self.path, 'rb') as f: self.assertEqual(zlib.decompress(f.read()).splitlines(), [])
def test_write_text_file_empty_with_header(self): header = b'header1\nheader2' sink = TextSink(self.path, header=header) self._write_lines(sink, []) with open(self.path, 'rb') as f: self.assertEqual(f.read().splitlines(), header.splitlines())
def test_write_gzip_file_empty(self): sink = TextSink( self.path, compression_type=CompressionTypes.GZIP) self._write_lines(sink, []) with gzip.GzipFile(self.path, 'rb') as f: self.assertEqual(f.read().splitlines(), [])
def test_write_deflate_file_auto(self): self.path = self._create_temp_file(suffix='.deflate') sink = TextSink(self.path) self._write_lines(sink, self.lines) with open(self.path, 'rb') as f: self.assertEqual(zlib.decompress(f.read()).splitlines(), self.lines)
def test_write_bzip2_file_auto(self): self.path = self._create_temp_file(suffix='.bz2') sink = TextSink(self.path) self._write_lines(sink, self.lines) with bz2.BZ2File(self.path, 'rb') as f: self.assertEqual(f.read().splitlines(), self.lines)
def test_write_gzip_file_auto(self): self.path = self._create_temp_file(suffix='.gz') sink = TextSink(self.path) self._write_lines(sink, self.lines) with gzip.GzipFile(self.path, 'rb') as f: self.assertEqual(f.read().splitlines(), self.lines)
def test_write_bzip2_file(self): sink = TextSink( self.path, compression_type=CompressionTypes.BZIP2) self._write_lines(sink, self.lines) with bz2.BZ2File(self.path, 'rb') as f: self.assertEqual(f.read().splitlines(), self.lines)
def test_write_gzip_file_auto(self): self.path = tempfile.NamedTemporaryFile(suffix='.gz').name sink = TextSink(self.path) self._write_lines(sink, self.lines) with gzip.GzipFile(self.path, 'r') as f: self.assertEqual(f.read().splitlines(), self.lines)
def test_write_text_file_with_footer(self): footer = b'footer1\nfooter2' sink = TextSink(self.path, footer=footer) self._write_lines(sink, self.lines) with open(self.path, 'rb') as f: self.assertEqual(f.read().splitlines(), self.lines + footer.splitlines())
def test_write_text_file_empty(self): sink = TextSink(self.path) self._write_lines(sink, []) with open(self.path, 'rb') as f: self.assertEqual(f.read().splitlines(), [])
def test_write_text_file(self): sink = TextSink(self.path) self._write_lines(sink, self.lines) with open(self.path, 'r') as f: self.assertEqual(f.read().splitlines(), self.lines)