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
This commit is contained in:
James E. Blair 2018-08-17 13:12:39 -07:00
parent 3b6429938b
commit 15ba4de7e6
2 changed files with 6 additions and 5 deletions

View File

@ -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')

View File

@ -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')