From 5dab93369563c975627940bf20af3a69e3059826 Mon Sep 17 00:00:00 2001 From: Chris AtLee Date: Thu, 6 Sep 2018 18:45:23 -0400 Subject: [PATCH] Fix up tests and coverage --- .coveragerc | 7 ++++++- src/mardor/utils.py | 2 +- src/mardor/writer.py | 13 +------------ tests/test_reader.py | 15 +++++++++++++++ tox.ini | 8 ++++---- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.coveragerc b/.coveragerc index b812277..42c5490 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,12 @@ [run] branch = true source = mardor -parallel = true + +[paths] +source = + src/mardor + .tox/*/lib/python*/site-packages/mardor + .tox/pypy/site-packages/mardor [report] show_missing = true diff --git a/src/mardor/utils.py b/src/mardor/utils.py index f059934..adcd8e3 100644 --- a/src/mardor/utils.py +++ b/src/mardor/utils.py @@ -182,7 +182,7 @@ def xz_decompress_stream(src): if decoded: yield decoded - if dec.unused_data: + if dec.unused_data: # pragma: nocover; can't figure out how to test this raise IOError('Read unused data at end of compressed stream') diff --git a/src/mardor/writer.py b/src/mardor/writer.py index 1daba3b..8675284 100644 --- a/src/mardor/writer.py +++ b/src/mardor/writer.py @@ -37,7 +37,6 @@ class MarWriter(object): productversion=None, channel=None, signing_key=None, signing_algorithm=None, - signature=None, ): """Initialize a new MarWriter object. @@ -55,7 +54,6 @@ class MarWriter(object): productversion and channel must be specified together signing_key (str): PEM encoded private key used for signing signing_algorithm (str): one of None, 'sha1', 'sha384' - signature (str): precomputed signature for this file """ self.fileobj = fileobj if signing_algorithm and (fileobj.mode not in ('w+b', 'wb+', 'rb+', 'r+b')): @@ -72,7 +70,6 @@ class MarWriter(object): self.productversion = productversion self.channel = channel self.signing_key = signing_key - self.signature = signature if signing_algorithm not in (None, 'sha1', 'sha384'): raise ValueError('Unsupported signing algorithm: {}'.format(signing_algorithm)) self.signing_algorithm = signing_algorithm @@ -235,7 +232,7 @@ class MarWriter(object): if not self.signing_algorithm: return [] algo_id = {'sha1': 1, 'sha384': 2}[self.signing_algorithm] - signature = self.signature or make_dummy_signature(algo_id) + signature = make_dummy_signature(algo_id) return [(algo_id, signature)] def calculate_signatures(self): @@ -245,14 +242,6 @@ class MarWriter(object): A list of signature tuples: [(algorithm_id, signature_data), ...] """ - if self.signature: - if self.signing_algorithm == 'sha1': - assert len(self.signature) == 256 - return [(1, self.signature)] - elif self.signing_algorithm == 'sha384': - assert len(self.signature) == 512 - return [(2, self.signature)] - if not self.signing_algorithm: return [] diff --git a/tests/test_reader.py b/tests/test_reader.py index e325499..1d60547 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -182,6 +182,11 @@ def test_calculate_hashes(): assert verify_signature(pubkey, m.mardata.signatures.sigs[0].signature, hashes[0][1], 'sha1') +def test_calculate_hashes_no_sig(mar_cu): + with mar_cu.open('rb') as f, MarReader(f) as m: + assert m.calculate_hashes() == [] + + def test_check_bad_signature_algorithm(mar_sha384, tmpdir): # Make a copy of mar_sha384 tmpmar = tmpdir.join('test.mar') @@ -273,3 +278,13 @@ def test_check_bad_file_entry_size(mar_sha384, tmpdir): with MarReader(f) as m: assert m.get_errors() == ["Entry 'message.txt' ends past data block"] + + +def test_productinfo(): + with open(TEST_MAR_BZ2, 'rb') as f, MarReader(f) as m: + assert m.productinfo == ('100.0', 'thunderbird-comm-esr') + + +def test_no_productinfo(mar_cu): + with mar_cu.open('rb') as f, MarReader(f) as m: + assert m.productinfo is None diff --git a/tox.ini b/tox.ini index 3ab3d3f..73dfa53 100644 --- a/tox.ini +++ b/tox.ini @@ -5,8 +5,8 @@ envlist = clean, check, {py27,py35,py36,py37,pypy}, - report, - docs + docs, + report [testenv] basepython = @@ -25,7 +25,7 @@ usedevelop = false deps = -rtest-requirements.txt commands = - {posargs:py.test -W error --cov --cov-report=term-missing -vv --random-order-bucket=package tests} + {posargs:coverage run --parallel -m pytest -W error -vv --random-order-bucket=package tests} [testenv:spell] setenv = @@ -74,7 +74,7 @@ commands = deps = coverage==4.5.1 skip_install = true commands = - coverage combine --append + coverage combine coverage report coverage html