Fix up tests and coverage
This commit is contained in:
Родитель
6cba2bcaaa
Коммит
5dab933695
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
||||
|
|
|
@ -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 []
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
8
tox.ini
8
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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче