Skip to content

Commit

Permalink
Inline method which was used just once, and specific to the use.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed Jun 13, 2024
1 parent 5365ade commit e57c30d
Showing 1 changed file with 44 additions and 46 deletions.
90 changes: 44 additions & 46 deletions lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,50 @@ def test_connectivity_names(self):
)
self.assertEqual(expected_names, result_names, fail_msg)

def _check_two_different_meshes(self, vars):
def test_multiple_equal_mesh(self):
mesh1 = make_mesh()
mesh2 = make_mesh()

# Save and snapshot the result
tempfile_path = self.check_save_mesh([mesh1, mesh2])
dims, vars = scan_dataset(tempfile_path)

# In this case there should be only *one* mesh.
mesh_names = vars_meshnames(vars)
self.assertEqual(1, len(mesh_names))

# Check it has the correct number of coords + conns (no duplicates)
# Should have 2 each X and Y coords (face+node): _no_ edge coords.
coord_vars_x = vars_w_props(vars, standard_name="longitude")
coord_vars_y = vars_w_props(vars, standard_name="latitude")
self.assertEqual(2, len(coord_vars_x))
self.assertEqual(2, len(coord_vars_y))

# Check the connectivities are all present: _only_ 1 var of each type.
for conn in mesh1.all_connectivities:
if conn is not None:
conn_vars = vars_w_props(vars, cf_role=conn.cf_role)
self.assertEqual(1, len(conn_vars))

def test_multiple_different_meshes(self):
# Create 2 meshes with different faces, but same edges.
# N.B. they should *not* then share an edge dimension !
mesh1 = make_mesh(n_faces=3, n_edges=2)
mesh2 = make_mesh(n_faces=4, n_edges=2)

# Save and snapshot the result
tempfile_path = self.check_save_mesh([mesh1, mesh2])
dims, vars = scan_dataset(tempfile_path)

# Check the dims are as expected
self.assertEqual(dims["Mesh2d_faces"], 3)
self.assertEqual(dims["Mesh2d_faces_0"], 4)
# There are no 'second' edge and node dims
self.assertEqual(dims["Mesh2d_nodes"], 5)
self.assertEqual(dims["Mesh2d_edge"], 2)

# Check there are two independent meshes in the file...

# there are exactly 2 meshes in the file
mesh_names = vars_meshnames(vars)
self.assertEqual(sorted(mesh_names), ["Mesh2d", "Mesh2d_0"])
Expand Down Expand Up @@ -1228,51 +1271,6 @@ def _check_two_different_meshes(self, vars):
["Mesh2d_edge", "Mesh2d_0_edge_N_nodes"],
)

def test_multiple_equal_mesh(self):
mesh1 = make_mesh()
mesh2 = make_mesh()

# Save and snapshot the result
tempfile_path = self.check_save_mesh([mesh1, mesh2])
dims, vars = scan_dataset(tempfile_path)

# In this case there should be only *one* mesh.
mesh_names = vars_meshnames(vars)
self.assertEqual(1, len(mesh_names))

# Check it has the correct number of coords + conns (no duplicates)
# Should have 2 each X and Y coords (face+node): _no_ edge coords.
coord_vars_x = vars_w_props(vars, standard_name="longitude")
coord_vars_y = vars_w_props(vars, standard_name="latitude")
self.assertEqual(2, len(coord_vars_x))
self.assertEqual(2, len(coord_vars_y))

# Check the connectivities are all present: _only_ 1 var of each type.
for conn in mesh1.all_connectivities:
if conn is not None:
conn_vars = vars_w_props(vars, cf_role=conn.cf_role)
self.assertEqual(1, len(conn_vars))

def test_multiple_different_meshes(self):
# Create 2 meshes with different faces, but same edges.
# N.B. they should *not* then share an edge dimension !
mesh1 = make_mesh(n_faces=3, n_edges=2)
mesh2 = make_mesh(n_faces=4, n_edges=2)

# Save and snapshot the result
tempfile_path = self.check_save_mesh([mesh1, mesh2])
dims, vars = scan_dataset(tempfile_path)

# Check there are two independent meshes
self._check_two_different_meshes(vars)

# Check the dims are as expected
self.assertEqual(dims["Mesh2d_faces"], 3)
self.assertEqual(dims["Mesh2d_faces_0"], 4)
# There are no 'second' edge and node dims
self.assertEqual(dims["Mesh2d_nodes"], 5)
self.assertEqual(dims["Mesh2d_edge"], 2)


# WHEN MODIFYING THIS MODULE, CHECK IF ANY CORRESPONDING CHANGES ARE NEEDED IN
# :mod:`iris.tests.unit.fileformats.netcdf.test_Saver__lazy.`
Expand Down

0 comments on commit e57c30d

Please sign in to comment.