code: def test_save_mp4(smg, tmp_path):
      """Save a series of fake scenes to an mp4 video."""
      from satpy import MultiScene
  
      area = _create_test_area()
      scenes = _create_test_scenes(area=area)
      smg.side_effect = _fake_get_enhanced_image
  
      # Add a dataset to only one of the Scenes
      scenes[1]["ds3"] = _create_test_dataset("ds3")
      # Add a start and end time
      for ds_id in ["ds1", "ds2", "ds3"]:
          scenes[1][ds_id].attrs["start_time"] = datetime(2018, 1, 2)
          scenes[1][ds_id].attrs["end_time"] = datetime(2018, 1, 2, 12)
          if ds_id == "ds3":
              continue
          scenes[0][ds_id].attrs["start_time"] = datetime(2018, 1, 1)
          scenes[0][ds_id].attrs["end_time"] = datetime(2018, 1, 1, 12)
  
      mscn = MultiScene(scenes)
      fn = str(
          tmp_path
          / "test_save_mp4_{name}_{start_time:%Y%m%d_%H}_{end_time:%Y%m%d_%H}.mp4"
      )
      writer_mock = mock.MagicMock()
      with mock.patch(
          "satpy.multiscene._multiscene.imageio.get_writer"
      ) as get_writer:
          get_writer.return_value = writer_mock
          # force order of datasets by specifying them
          mscn.save_animation(
              fn, datasets=["ds1", "ds2", "ds3"], client=False
          )
  
      # 2 saves for the first scene + 1 black frame
      # 3 for the second scene
      assert writer_mock.append_data.call_count == 3 + 3
      filenames = [
          os.path.basename(args[0][0])
          for args in get_writer.call_args_list
      ]
      assert (
          filenames[0]
          == "test_save_mp4_ds1_20180101_00_20180102_12.mp4"
      )
      assert (
          filenames[1]
          == "test_save_mp4_ds2_20180101_00_20180102_12.mp4"
      )
      assert (
          filenames[2]
          == "test_save_mp4_ds3_20180102_00_20180102_12.mp4"
      )
  
      # make sure that not specifying datasets still saves all of them
      fn = str(
          tmp_path
          / "test_save_mp4_{name}_{start_time:%Y%m%d_%H}_{end_time:%Y%m%d_%H}.mp4"
      )
      writer_mock = mock.MagicMock()
      with mock.patch(
          "satpy.multiscene._multiscene.imageio.get_writer"
      ) as get_writer:
          get_writer.return_value = writer_mock
          # force order of datasets by specifying them
          mscn.save_animation(fn, client=False)
      # the 'ds3' dataset isn't known to the first scene so it doesn't get saved
      # 2 for first scene, 2 for second scene
      assert writer_mock.append_data.call_count == 2 + 2
      assert (
          "test_save_mp4_ds1_20180101_00_20180102_12.mp4" in filenames
      )
      assert (
          "test_save_mp4_ds2_20180101_00_20180102_12.mp4" in filenames
      )
      assert (
          "test_save_mp4_ds3_20180102_00_20180102_12.mp4" in filenames
      )
  
      # test decorating and enhancing
  
      fn = str(
          tmp_path
          / "test-{name}_{start_time:%Y%m%d_%H}_{end_time:%Y%m%d_%H}-rich.mp4"
      )
      writer_mock = mock.MagicMock()
      with mock.patch(
          "satpy.multiscene._multiscene.imageio.get_writer"
      ) as get_writer:
          get_writer.return_value = writer_mock
          mscn.save_animation(
              fn,
              client=False,
              enh_args={
                  "decorate": {
                      "decorate": [
                          {
                              "text": {
                                  "txt": "Test {start_time:%Y-%m-%d %H:%M} - "
                                  "{end_time:%Y-%m-%d %H:%M}"
                              }
                          }
                      ]
                  }
              },
          )
      assert writer_mock.append_data.call_count == 2 + 2
      assert (
          "2018-01-02"
          in smg.call_args_list[-1][1]["decorate"]["decorate"][0][
              "text"
          ]["txt"]
      )
  
file_path: satpy/satpy/tests/multiscene_tests/test_save_animation.py
imports: import os
  import shutil
  import tempfile
  import unittest
  from datetime import datetime
  from unittest import mock
  import pytest
  from satpy.tests.multiscene_tests.test_utils import _create_test_area, _create_test_dataset, _create_test_scenes, _fake_get_enhanced_image
label_desc: Use image node_id 1 for calling a global function with example usage: test_save_mp4(smg, tmp_path) without return types