class_docstr: Test case for CF writer.
docstr: Test setting time bounds.
docstr_tok: ["Test","setting","time","bounds","."]
code: def test_bounds(self):
      """Test setting time bounds."""
      scn = Scene()
      start_time = datetime(2018, 5, 30, 10, 0)
      end_time = datetime(2018, 5, 30, 10, 15)
      test_array = np.array([[1, 2], [3, 4]]).reshape(2, 2, 1)
      scn["test-array"] = xr.DataArray(
          test_array,
          dims=["x", "y", "time"],
          coords={"time": [np.datetime64("2018-05-30T10:05:00", "ns")]},
          attrs=dict(start_time=start_time, end_time=end_time),
      )
      with TempFile() as filename:
          with warnings.catch_warnings():
              # The purpose is to use the default time encoding, silence the warning
              warnings.filterwarnings(
                  "ignore",
                  category=UserWarning,
                  message=r"Times can't be serialized faithfully to int64 with requested units",
              )
              scn.save_datasets(filename=filename, writer="cf")
          # Check decoded time coordinates & bounds
          with xr.open_dataset(filename, decode_cf=True) as f:
              bounds_exp = np.array(
                  [[start_time, end_time]], dtype="datetime64[m]"
              )
              np.testing.assert_array_equal(f["time_bnds"], bounds_exp)
              assert f["time"].attrs["bounds"] == "time_bnds"
  
          # Check raw time coordinates & bounds
          with xr.open_dataset(filename, decode_cf=False) as f:
              np.testing.assert_almost_equal(
                  f["time_bnds"], [[-0.0034722, 0.0069444]]
              )
  
      # User-specified time encoding should have preference
      with TempFile() as filename:
          time_units = "seconds since 2018-01-01"
          scn.save_datasets(
              filename=filename,
              encoding={"time": {"units": time_units}},
              writer="cf",
          )
          with xr.open_dataset(filename, decode_cf=False) as f:
              np.testing.assert_array_equal(
                  f["time_bnds"], [[12909600, 12910500]]
              )
  
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 12 for calling the TestCFWriter obj's underlying member method code with example usage: obj.test_bounds() without return types