code: def test_savefig_rcparam(monkeypatch, tmp_path):
      def new_choose_save_file(title, directory, filename):
          # Replacement function instead of opening a GUI window
          # Make a new directory for testing the update of the rcParams
          assert directory == str(tmp_path)
          os.makedirs(f"{directory}/test")
          return f"{directory}/test/{filename}"
  
      monkeypatch.setattr(
          _macosx, "choose_save_file", new_choose_save_file
      )
      fig = plt.figure()
      with mpl.rc_context({"savefig.directory": tmp_path}):
          fig.canvas.toolbar.save_figure()
          # Check the saved location got created
          save_file = (
              f"{tmp_path}/test/{fig.canvas.get_default_filename()}"
          )
          assert os.path.exists(save_file)
  
          # Check the savefig.directory rcParam got updated because
          # we added a subdirectory "test"
          assert mpl.rcParams["savefig.directory"] == f"{tmp_path}/test"
  
imports: import os
  import pytest
  import matplotlib
  import matplotlib.pyplot
label_desc: Use image node_id 2 for calling a global function with example usage: test_savefig_rcparam(monkeypatch, tmp_path) and returns: directory, str, filename