+ # -------------------------------------------------------------------------
+ def test_reading(self):
+
+ from trace_maillog import any_uncompress_file
+ from trace_maillog.any_uncompress_file import AnyUncompressFile
+ from trace_maillog.any_uncompress_file import InvalidCompressionError
+
+ LOG.info("Testing reading of usable files...")
+
+ src_file = os.path.join(self.testdata_dir, 'lorem-ipsum.txt')
+ src_content = ''
+ open_args = {}
+ if six.PY3:
+ open_args = {
+ 'encoding': 'utf-8',
+ 'errors': 'surrogateescape',
+ }
+ LOG.debug("Reading source file {!r} ...".format(src_file))
+ with open(src_file, 'r', **open_args) as fh:
+ src_content = fh.read()
+
+ for fname in self.usable_files:
+ LOG.debug("Testing {!r} ...".format(fname))
+ afile = None
+ if fname.endswith('.zip'):
+ afile = os.path.basename(fname).replace('.zip', '')
+ tgt_content = ''
+ with any_uncompress_file.open(fname, afile, text=True) as fh:
+ tgt_content = fh.read()
+ if not isinstance(tgt_content, str) and six.PY3:
+ tgt_content = tgt_content.decode(**open_args)
+ self.assertEqual(tgt_content, src_content)
+
+ # -------------------------------------------------------------------------
+ def test_reading_binary(self):
+
+ from trace_maillog import any_uncompress_file
+ from trace_maillog.any_uncompress_file import AnyUncompressFile
+ from trace_maillog.any_uncompress_file import InvalidCompressionError
+
+ LOG.info("Testing reading of binary usable files...")
+
+ src_file = os.path.join(self.testdata_dir, 'lorem-ipsum.txt')
+ src_content = ''
+ open_args = {}
+ LOG.debug("Reading source file {!r} ...".format(src_file))
+ with open(src_file, 'rb') as fh:
+ src_content = fh.read()
+
+ for fname in self.usable_files:
+ LOG.debug("Testing {!r} ...".format(fname))
+ afile = None
+ if fname.endswith('.zip'):
+ afile = os.path.basename(fname).replace('.zip', '')
+ tgt_content = ''
+ with any_uncompress_file.open(fname, afile, text=False) as fh:
+ tgt_content = fh.read()
+ self.assertEqual(tgt_content, src_content)
+