Skip to content
Snippets Groups Projects
Commit e87d0f68 authored by Martin Bauer's avatar Martin Bauer
Browse files

pytest.raises: checking for exception error message fixed

- str(e) did work in previous pytest version
- but the correct usage is str(e.value)
- in newer pytest version the string for the e object is changed so
  the tests did not work any more
parent 7cf5b5bf
Branches
Tags
No related merge requests found
......@@ -16,7 +16,7 @@ def test_dtype_check_wrong_type():
with pytest.raises(ValueError) as e:
kernel(x=array, y=output)
assert 'Wrong data type' in str(e)
assert 'Wrong data type' in str(e.value)
def test_dtype_check_correct_type():
......
......@@ -31,4 +31,4 @@ def test_linear_equation_system():
with pytest.raises(ValueError) as e:
m.add_equation(x**2 - 1)
assert 'Not a linear equation' in str(e)
assert 'Not a linear equation' in str(e.value)
......@@ -40,56 +40,56 @@ def test_error_handling():
Field.create_generic('f', spatial_dimensions=2, index_dimensions=0, dtype=struct_dtype)
with pytest.raises(ValueError) as e:
Field.create_generic('f', spatial_dimensions=2, index_dimensions=1, dtype=struct_dtype)
assert 'index dimension' in str(e)
assert 'index dimension' in str(e.value)
arr = np.array([[1, 2.0, 3], [1, 2.0, 3]], dtype=struct_dtype)
Field.create_from_numpy_array('f', arr, index_dimensions=0)
with pytest.raises(ValueError) as e:
Field.create_from_numpy_array('f', arr, index_dimensions=1)
assert 'Structured arrays' in str(e)
assert 'Structured arrays' in str(e.value)
arr = np.zeros([3, 3, 3])
Field.create_from_numpy_array('f', arr, index_dimensions=2)
with pytest.raises(ValueError) as e:
Field.create_from_numpy_array('f', arr, index_dimensions=3)
assert 'Too many' in str(e)
assert 'Too many' in str(e.value)
Field.create_fixed_size('f', (3, 2, 4), index_dimensions=0, dtype=struct_dtype, layout='reverse_numpy')
with pytest.raises(ValueError) as e:
Field.create_fixed_size('f', (3, 2, 4), index_dimensions=1, dtype=struct_dtype, layout='reverse_numpy')
assert 'Structured arrays' in str(e)
assert 'Structured arrays' in str(e.value)
f = Field.create_fixed_size('f', (10, 10))
with pytest.raises(ValueError) as e:
f[1]
assert 'Wrong number of spatial indices' in str(e)
assert 'Wrong number of spatial indices' in str(e.value)
f = Field.create_generic('f', spatial_dimensions=2, index_shape=(3,))
with pytest.raises(ValueError) as e:
f(3)
assert 'out of bounds' in str(e)
assert 'out of bounds' in str(e.value)
f = Field.create_fixed_size('f', (10, 10, 3, 4), index_dimensions=2)
with pytest.raises(ValueError) as e:
f(3, 0)
assert 'out of bounds' in str(e)
assert 'out of bounds' in str(e.value)
with pytest.raises(ValueError) as e:
f(1, 0)(1, 0)
assert 'Indexing an already indexed' in str(e)
assert 'Indexing an already indexed' in str(e.value)
with pytest.raises(ValueError) as e:
f(1)
assert 'Wrong number of indices' in str(e)
assert 'Wrong number of indices' in str(e.value)
with pytest.raises(ValueError) as e:
Field.create_generic('f', spatial_dimensions=2, layout='wrong')
assert 'Unknown layout descriptor' in str(e)
assert 'Unknown layout descriptor' in str(e.value)
assert layout_string_to_tuple('fzyx', dim=4) == (3, 2, 1, 0)
with pytest.raises(ValueError) as e:
layout_string_to_tuple('wrong', dim=4)
assert 'Unknown layout descriptor' in str(e)
assert 'Unknown layout descriptor' in str(e.value)
def test_decorator_scoping():
......
......@@ -23,7 +23,7 @@ def test_size_check():
with pytest.raises(ValueError) as e:
func(src=src, dst=dst)
assert 'Wrong shape' in str(e)
assert 'Wrong shape' in str(e.value)
def test_fixed_size_mismatch_check():
......@@ -38,7 +38,7 @@ def test_fixed_size_mismatch_check():
with pytest.raises(ValueError) as e:
create_kernel([update_rule])
assert 'Differently sized field accesses' in str(e)
assert 'Differently sized field accesses' in str(e.value)
def test_fixed_and_variable_field_check():
......@@ -53,7 +53,7 @@ def test_fixed_and_variable_field_check():
with pytest.raises(ValueError) as e:
create_kernel(update_rule)
assert 'Mixing fixed-shaped and variable-shape fields' in str(e)
assert 'Mixing fixed-shaped and variable-shape fields' in str(e.value)
def test_two_variable_shaped_fields():
......@@ -70,7 +70,7 @@ def test_two_variable_shaped_fields():
with pytest.raises(TypeError) as e:
func(src=src, dst=dst)
assert 'must have same' in str(e)
assert 'must have same' in str(e.value)
def test_ssa_checks():
......@@ -81,18 +81,18 @@ def test_ssa_checks():
create_kernel([Assignment(c, f[0, 1]),
Assignment(c, f[1, 0]),
Assignment(g[0, 0], c)])
assert 'Assignments not in SSA form' in str(e)
assert 'Assignments not in SSA form' in str(e.value)
with pytest.raises(ValueError) as e:
create_kernel([Assignment(c, a + 3),
Assignment(a, 42),
Assignment(g[0, 0], c)])
assert 'Symbol a is written, after it has been read' in str(e)
assert 'Symbol a is written, after it has been read' in str(e.value)
with pytest.raises(ValueError) as e:
create_kernel([Assignment(c, c + 1),
Assignment(g[0, 0], c)])
assert 'Symbol c is written, after it has been read' in str(e)
assert 'Symbol c is written, after it has been read' in str(e.value)
def test_loop_independence_checks():
......@@ -102,7 +102,7 @@ def test_loop_independence_checks():
with pytest.raises(ValueError) as e:
create_kernel([Assignment(g[0, 1], f[0, 1]),
Assignment(g[0, 0], f[1, 0])])
assert 'Field g is written at two different locations' in str(e)
assert 'Field g is written at two different locations' in str(e.value)
# This is allowed - because only one element of g is accessed
create_kernel([Assignment(g[0, 2], f[0, 1]),
......@@ -115,4 +115,4 @@ def test_loop_independence_checks():
with pytest.raises(ValueError) as e:
create_kernel([Assignment(g[0, 1], 3),
Assignment(f[0, 1], 2 * g[0, 2])])
assert 'Field g is read at (0, 2) and written at (0, 1)' in str(e)
assert 'Field g is read at (0, 2) and written at (0, 1)' in str(e.value)
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