mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
used escape chars to match regex
This commit is contained in:
parent
cc667cc11a
commit
922a5fcf5a
2 changed files with 10 additions and 5 deletions
|
|
@ -231,8 +231,8 @@ class StructuredMesh(MeshBase):
|
|||
# check that the data sets are appropriately sized
|
||||
for label, dataset in datasets.items():
|
||||
errmsg = (
|
||||
f"The size of the dataset '{label}' ({dataset.size}) "
|
||||
f"should be equal to the number of mesh cells ({self.num_mesh_cells})"
|
||||
f"The size of the dataset '{label}' ({dataset.size}) should be"
|
||||
f" equal to the number of mesh cells ({self.num_mesh_cells})"
|
||||
)
|
||||
if isinstance(dataset, np.ndarray):
|
||||
if not dataset.size == self.num_mesh_cells:
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ spherical_mesh.r_grid = np.linspace(1, 2, num=30)
|
|||
spherical_mesh.phi_grid = np.linspace(0, np.pi, num=50)
|
||||
spherical_mesh.theta_grid = np.linspace(0, np.pi / 2, num=30)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mesh", [cylinder_mesh, regular_mesh, rectilinear_mesh, spherical_mesh])
|
||||
def test_write_data_to_vtk(mesh, tmpdir):
|
||||
# BUILD
|
||||
|
|
@ -43,7 +44,7 @@ def test_write_data_to_vtk(mesh, tmpdir):
|
|||
|
||||
# read file
|
||||
reader = vtk.vtkStructuredGridReader()
|
||||
reader.SetFileName(filename)
|
||||
reader.SetFileName(str(filename))
|
||||
reader.Update()
|
||||
|
||||
# check name of datasets
|
||||
|
|
@ -58,6 +59,7 @@ def test_write_data_to_vtk(mesh, tmpdir):
|
|||
assert nps.vtk_to_numpy(array1).size == data.size
|
||||
assert nps.vtk_to_numpy(array2).size == data.size
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mesh", [cylinder_mesh, regular_mesh, rectilinear_mesh, spherical_mesh])
|
||||
def test_write_data_to_vtk_size_mismatch(mesh):
|
||||
"""Checks that an error is raised when the size of the dataset
|
||||
|
|
@ -71,9 +73,12 @@ def test_write_data_to_vtk_size_mismatch(mesh):
|
|||
right_size = mesh.num_mesh_cells
|
||||
data = np.random.random(right_size + 1)
|
||||
|
||||
# Error message has \ in to escape characters that are otherwise recognized
|
||||
# by regex. These are needed to make the test string match the error message
|
||||
# string when using the match argument as that uses regular expression
|
||||
expected_error_msg = (
|
||||
f"The size of the dataset 'label' ({len(data)}) should be equal to "
|
||||
f"the number of mesh cells ({mesh.num_mesh_cells})"
|
||||
f"The size of the dataset 'label' \({len(data)}\) should be equal to "
|
||||
f"the number of mesh cells \({mesh.num_mesh_cells}\)"
|
||||
)
|
||||
with pytest.raises(RuntimeError, match=expected_error_msg):
|
||||
mesh.write_data_to_vtk(filename="out.vtk", datasets={"label": data})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue