Commit 38a1dbee authored by Joseph Weston's avatar Joseph Weston
Browse files

normalise usage of 'pytest.raises'

In pytest v5 the behaviour of str(exc_info) changed. We now
use str(exc_info.value) as the canonical way of obtaining
the exception message.
parent 383f8435
......@@ -535,17 +535,17 @@ def test_hamiltonian_evaluation():
def test_raising(fsyst, hop):
a, b = hop
# exceptions are converted to kwant.UserCodeError and we add our message
with raises(kwant.UserCodeError) as ctx:
with raises(kwant.UserCodeError) as exc_info:
fsyst.hamiltonian(a, a)
msg = 'Error occurred in user-supplied value function "onsite_raises"'
assert msg in ctx.exconly()
assert msg in str(exc_info.value)
for hop in [(a, b), (b, a)]:
with raises(kwant.UserCodeError) as ctx:
with raises(kwant.UserCodeError) as exc_info:
fsyst.hamiltonian(*hop)
msg = ('Error occurred in user-supplied '
'value function "hopping_raises"')
assert msg in ctx.exconly()
assert msg in str(exc_info.value)
# test with finite system
new_hop = (fam(-1, 0), fam(0, 0))
......
......@@ -425,14 +425,14 @@ def test_arg_passing(A):
# test missing params
op = A(fsyst, onsite=lambda x, a, b: 1)
params = dict(a=1)
with raises(TypeError) as exc:
with raises(TypeError):
op(wf, params=params)
with raises(TypeError) as exc:
with raises(TypeError):
op.act(wf, params=params)
with raises(TypeError) as exc:
with raises(TypeError):
op.bind(params=params)
if hasattr(op, 'tocoo'):
with raises(TypeError) as exc:
with raises(TypeError):
op.tocoo(params=params)
......@@ -445,19 +445,19 @@ def test_arg_passing(A):
if has_tocoo:
tocoo_should_be = op.tocoo(args=canonical_args).toarray()
with raises(TypeError) as exc:
with raises(TypeError) as exc_info:
op(wf, args=canonical_args, params=params)
assert 'mutually exclusive' in str(exc)
with raises(TypeError) as exc:
assert 'mutually exclusive' in str(exc_info.value)
with raises(TypeError) as exc_info:
op.act(wf, args=canonical_args, params=params)
assert 'mutually exclusive' in str(exc)
with raises(TypeError) as exc:
assert 'mutually exclusive' in str(exc_info.value)
with raises(TypeError) as exc_info:
op.bind(args=canonical_args, params=params)
assert 'mutually exclusive' in str(exc)
assert 'mutually exclusive' in str(exc_info.value)
if has_tocoo:
with raises(TypeError) as exc:
with raises(TypeError) as exc_info:
op.tocoo(args=canonical_args, params=params)
assert 'mutually exclusive' in str(exc)
assert 'mutually exclusive' in str(exc_info.value)
np.testing.assert_array_equal(
call_should_be, op(wf, params=params))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment