From 15ba4de7e648d4a6ec06532f33e07b46ebd6711a Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 17 Aug 2018 13:12:39 -0700 Subject: [PATCH] htmlify: fix py3 gzip issue Actually test the gzip path, and correct a bytes/str issue under python3 (the file should be opened as text). Change-Id: Icc5362d3d020761e07e60fb8ee296c98a8fe3ac4 --- roles/htmlify-logs/library/htmlify.py | 4 ++-- roles/htmlify-logs/library/test_htmlify.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/roles/htmlify-logs/library/htmlify.py b/roles/htmlify-logs/library/htmlify.py index a97b9b94d..2b02f0c3a 100644 --- a/roles/htmlify-logs/library/htmlify.py +++ b/roles/htmlify-logs/library/htmlify.py @@ -85,8 +85,8 @@ highlight_by_hash(); def run(inpath, outpath): if inpath.endswith('.gz'): - infile = gzip.open(inpath, 'r') - outfile = gzip.open(outpath, 'w') + infile = gzip.open(inpath, 'rt') + outfile = gzip.open(outpath, 'wt') else: infile = open(inpath, 'r') outfile = open(outpath, 'w') diff --git a/roles/htmlify-logs/library/test_htmlify.py b/roles/htmlify-logs/library/test_htmlify.py index a9abebc60..16aef34cf 100644 --- a/roles/htmlify-logs/library/test_htmlify.py +++ b/roles/htmlify-logs/library/test_htmlify.py @@ -28,9 +28,9 @@ FIXTURE_DIR = os.path.join(os.path.dirname(__file__), class TestHTMLify(testtools.TestCase): - def _test_file(self, fn): + def _test_file(self, fn, ref_fn): in_path = os.path.join(FIXTURE_DIR, 'in', fn) - ref_path = os.path.join(FIXTURE_DIR, 'reference', fn) + ref_path = os.path.join(FIXTURE_DIR, 'reference', ref_fn) out_root = self.useFixture(fixtures.TempDir()).path out_path = os.path.join(out_root, fn) run(in_path, out_path) @@ -45,4 +45,5 @@ class TestHTMLify(testtools.TestCase): self.assertEqual(reference_data, generated_data) def test_htmlify(self): - self._test_file('job-output.txt') + self._test_file('job-output.txt', 'job-output.txt') + self._test_file('job-output.txt.gz', 'job-output.txt')