示例#1
0
 def test_no_mesh(self):
     with PARSE_UGRID_ON_LOAD.context():
         meshes = load_meshes(
             tests.get_data_path([
                 "NetCDF", "unstructured_grid", "theta_nodal_not_ugrid.nc"
             ]))
     self.assertDictEqual({}, meshes)
示例#2
0
 def test_non_nc(self):
     log_regex = r"Ignoring non-NetCDF file:.*"
     with self.assertLogs(logger, level="INFO", msg_regex=log_regex):
         with PARSE_UGRID_ON_LOAD.context():
             meshes = load_meshes(
                 tests.get_data_path(["PP", "simple_pp", "global.pp"]))
     self.assertDictEqual({}, meshes)
示例#3
0
    def test_with_data(self):
        nc_path = cdl_to_nc(self.ref_cdl)
        with PARSE_UGRID_ON_LOAD.context():
            meshes = load_meshes(nc_path)

        files = list(meshes.keys())
        self.assertEqual(1, len(files))
        file_meshes = meshes[files[0]]
        self.assertEqual(1, len(file_meshes))
        mesh = file_meshes[0]
        self.assertEqual("mesh", mesh.var_name)
示例#4
0
    def test_var_name(self):
        second_cdl, second_name = self.add_second_mesh()
        cdls = [self.ref_cdl, second_cdl]
        nc_paths = [cdl_to_nc(cdl) for cdl in cdls]
        with PARSE_UGRID_ON_LOAD.context():
            meshes = load_meshes(nc_paths, second_name)

        files = list(meshes.keys())
        self.assertEqual(1, len(files))
        file_meshes = meshes[files[0]]
        self.assertEqual(1, len(file_meshes))
        self.assertEqual(second_name, file_meshes[0].var_name)
示例#5
0
    def test_mixed_sources(self):
        url = "http://foo"
        file = TMP_DIR / f"{uuid4()}.nc"
        file.touch()
        glob = f"{TMP_DIR}/*.nc"

        with PARSE_UGRID_ON_LOAD.context():
            _ = load_meshes([url, glob])
        file_uris = [
            call[0][0] for call in self.format_agent_mock.call_args_list
        ]
        for source in (url, Path(file).name):
            self.assertIn(source, file_uris)
示例#6
0
    def test_multi_meshes(self):
        ref_cdl, second_name = self.add_second_mesh()
        nc_path = cdl_to_nc(ref_cdl)
        with PARSE_UGRID_ON_LOAD.context():
            meshes = load_meshes(nc_path)

        files = list(meshes.keys())
        self.assertEqual(1, len(files))
        file_meshes = meshes[files[0]]
        self.assertEqual(2, len(file_meshes))
        mesh_names = [mesh.var_name for mesh in file_meshes]
        self.assertIn("mesh", mesh_names)
        self.assertIn(second_name, mesh_names)
示例#7
0
    def test_no_mesh(self):
        cdl_lines = self.ref_cdl.split("\n")
        cdl_lines = filter(
            lambda line: all(
                [s not in line for s in (':mesh = "mesh"', "mesh_topology")]),
            cdl_lines,
        )
        ref_cdl = "\n".join(cdl_lines)

        nc_path = cdl_to_nc(ref_cdl)
        with PARSE_UGRID_ON_LOAD.context():
            meshes = load_meshes(nc_path)

        self.assertDictEqual({}, meshes)
示例#8
0
    def test_no_data(self):
        cdl_lines = self.ref_cdl.split("\n")
        cdl_lines = filter(lambda line: ':mesh = "mesh"' not in line,
                           cdl_lines)
        ref_cdl = "\n".join(cdl_lines)

        nc_path = cdl_to_nc(ref_cdl)
        with PARSE_UGRID_ON_LOAD.context():
            meshes = load_meshes(nc_path)

        files = list(meshes.keys())
        self.assertEqual(1, len(files))
        file_meshes = meshes[files[0]]
        self.assertEqual(1, len(file_meshes))
        mesh = file_meshes[0]
        self.assertEqual("mesh", mesh.var_name)
示例#9
0
 def test_http(self):
     url = "http://foo"
     with PARSE_UGRID_ON_LOAD.context():
         _ = load_meshes(url)
     self.format_agent_mock.assert_called_with(url, None)
示例#10
0
 def test_invalid_scheme(self):
     with self.assertRaisesRegex(ValueError,
                                 "Iris cannot handle the URI scheme:.*"):
         with PARSE_UGRID_ON_LOAD.context():
             _ = load_meshes("foo://bar")
示例#11
0
 def test_no_parsing(self):
     nc_path = cdl_to_nc(self.ref_cdl)
     with self.assertRaisesRegex(ValueError,
                                 ".*Must be True to enable mesh loading."):
         _ = load_meshes(nc_path)
示例#12
0
 def test_multi_files(self):
     files_count = 3
     nc_paths = [cdl_to_nc(self.ref_cdl) for _ in range(files_count)]
     with PARSE_UGRID_ON_LOAD.context():
         meshes = load_meshes(nc_paths)
     self.assertEqual(files_count, len(meshes))