code: def test_save(format, engine, basic_chart):
      if format in ["pdf", "png"]:
          out = io.BytesIO()
          mode = "rb"
      else:
          out = io.StringIO()
          mode = "r"
  
      if format in ["svg", "png", "pdf", "bogus"]:
          if engine == "altair_saver":
              if format == "bogus":
                  with pytest.raises(ValueError) as err:
                      basic_chart.save(
                          out, format=format, engine=engine
                      )
                  assert f"Unsupported format: '{format}'" in str(
                      err.value
                  )
                  return
              elif altair_saver is None:
                  with pytest.raises(ValueError) as err:
                      basic_chart.save(
                          out, format=format, engine=engine
                      )
                  assert "altair_saver" in str(err.value)
                  return
              elif format not in altair_saver.available_formats():
                  with pytest.raises(ValueError) as err:
                      basic_chart.save(
                          out, format=format, engine=engine
                      )
                  assert (
                      f"No enabled saver found that supports format='{format}'"
                      in str(err.value)
                  )
                  return
  
          elif engine == "vl-convert":
              if format == "bogus":
                  with pytest.raises(ValueError) as err:
                      basic_chart.save(
                          out, format=format, engine=engine
                      )
                  assert f"Unsupported format: '{format}'" in str(
                      err.value
                  )
                  return
              elif vlc is None:
                  with pytest.raises(ValueError) as err:
                      basic_chart.save(
                          out, format=format, engine=engine
                      )
                  assert "vl-convert-python" in str(err.value)
                  return
  
      basic_chart.save(out, format=format, engine=engine)
      out.seek(0)
      content = out.read()
  
      if format == "json":
          assert "$schema" in json.loads(content)
      elif format == "html":
          assert content.startswith("<!DOCTYPE html>")
      elif format == "svg":
          assert content.startswith("<svg")
      elif format == "png":
          assert content.startswith(b"\x89PNG")
      elif format == "pdf":
          assert content.startswith(b"%PDF-")
  
      fid, filename = tempfile.mkstemp(suffix="." + format)
      os.close(fid)
  
      # test both string filenames and pathlib.Paths
      for fp in [filename, pathlib.Path(filename)]:
          try:
              basic_chart.save(fp, format=format, engine=engine)
              with open(fp, mode) as f:
                  assert f.read()[:1000] == content[:1000]
          finally:
              os.remove(fp)
  
imports: import io
  import json
  import operator
  import os
  import pathlib
  import tempfile
  import jsonschema
  import pytest
  import pandas
  import altair.vegalite.v5
label_desc: Use image node_id 10 for calling a global function with example usage: test_save(format, engine, basic_chart) without return types