(self)
| 1748 | engine: T_NetcdfEngine = "netcdf4" |
| 1749 | |
| 1750 | def test_open_group(self) -> None: |
| 1751 | # Create a netCDF file with a dataset stored within a group |
| 1752 | with create_tmp_file() as tmp_file: |
| 1753 | with nc4.Dataset(tmp_file, "w") as rootgrp: |
| 1754 | foogrp = rootgrp.createGroup("foo") |
| 1755 | ds = foogrp |
| 1756 | ds.createDimension("time", size=10) |
| 1757 | x = np.arange(10) |
| 1758 | ds.createVariable("x", np.int32, dimensions=("time",)) |
| 1759 | ds.variables["x"][:] = x |
| 1760 | |
| 1761 | expected = Dataset() |
| 1762 | expected["x"] = ("time", x) |
| 1763 | |
| 1764 | # check equivalent ways to specify group |
| 1765 | for group in "foo", "/foo", "foo/", "/foo/": |
| 1766 | with self.open(tmp_file, group=group) as actual: |
| 1767 | assert_equal(actual["x"], expected["x"]) |
| 1768 | |
| 1769 | # check that missing group raises appropriate exception |
| 1770 | with pytest.raises(OSError): |
| 1771 | open_dataset(tmp_file, group="bar") |
| 1772 | with pytest.raises(ValueError, match=r"must be a string"): |
| 1773 | open_dataset(tmp_file, group=(1, 2, 3)) |
| 1774 | |
| 1775 | def test_open_subgroup(self) -> None: |
| 1776 | # Create a netCDF file with a dataset stored within a group within a |
nothing calls this directly
no test coverage detected