class_docstr: Test case for CF writer.
docstr: Test creating a file with groups.
docstr_tok: ["Test","creating","a","file","with","groups","."]
code: def test_groups(self):
      """Test creating a file with groups."""
      tstart = datetime(2019, 4, 1, 12, 0)
      tend = datetime(2019, 4, 1, 12, 15)
  
      data_visir = [[1, 2], [3, 4]]
      y_visir = [1, 2]
      x_visir = [1, 2]
      time_vis006 = [1, 2]
      time_ir_108 = [3, 4]
  
      data_hrv = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
      y_hrv = [1, 2, 3]
      x_hrv = [1, 2, 3]
      time_hrv = [1, 2, 3]
  
      scn = Scene()
      scn["VIS006"] = xr.DataArray(
          data_visir,
          dims=("y", "x"),
          coords={
              "y": y_visir,
              "x": x_visir,
              "acq_time": ("y", time_vis006),
          },
          attrs={
              "name": "VIS006",
              "start_time": tstart,
              "end_time": tend,
          },
      )
      scn["IR_108"] = xr.DataArray(
          data_visir,
          dims=("y", "x"),
          coords={
              "y": y_visir,
              "x": x_visir,
              "acq_time": ("y", time_ir_108),
          },
          attrs={
              "name": "IR_108",
              "start_time": tstart,
              "end_time": tend,
          },
      )
      scn["HRV"] = xr.DataArray(
          data_hrv,
          dims=("y", "x"),
          coords={"y": y_hrv, "x": x_hrv, "acq_time": ("y", time_hrv)},
          attrs={"name": "HRV", "start_time": tstart, "end_time": tend},
      )
  
      with TempFile() as filename:
          with pytest.warns(UserWarning, match=r"Cannot pretty-format"):
              scn.save_datasets(
                  filename=filename,
                  writer="cf",
                  groups={
                      "visir": ["IR_108", "VIS006"],
                      "hrv": ["HRV"],
                  },
                  pretty=True,
              )
  
          nc_root = xr.open_dataset(filename)
          assert "history" in nc_root.attrs
          assert set(nc_root.variables.keys()) == set()
  
          nc_visir = xr.open_dataset(filename, group="visir")
          nc_hrv = xr.open_dataset(filename, group="hrv")
          assert set(nc_visir.variables.keys()) == {
              "VIS006",
              "IR_108",
              "y",
              "x",
              "VIS006_acq_time",
              "IR_108_acq_time",
          }
          assert set(nc_hrv.variables.keys()) == {
              "HRV",
              "y",
              "x",
              "acq_time",
          }
          for tst, ref in zip(
              [nc_visir["VIS006"], nc_visir["IR_108"], nc_hrv["HRV"]],
              [scn["VIS006"], scn["IR_108"], scn["HRV"]],
          ):
              np.testing.assert_array_equal(tst.data, ref.data)
          nc_root.close()
          nc_visir.close()
          nc_hrv.close()
  
      # Different projection coordinates in one group are not supported
      with TempFile() as filename:
          with pytest.raises(
              ValueError,
              match="Datasets .* must have identical projection coordinates..*",
          ):
              scn.save_datasets(
                  datasets=["VIS006", "HRV"],
                  filename=filename,
                  writer="cf",
              )
  
imports: import os
  import tempfile
  import warnings
  from datetime import datetime
  import numpy
  import pytest
  import xarray
  from packaging.version import Version
  from satpy import Scene
  from satpy.tests.utils import make_dsq
  from satpy.writers.cf_writer import _get_backend_versions
label_desc: Use image node_id 9 for calling the TestCFWriter obj's underlying member method code with example usage: obj.test_groups() without return types