code: def test_memory_runs_of_multiple_stages(
      tmp_dir, dvc, run_copy, mocker
  ):
      tmp_dir.gen("foo", "foo")
      assert not os.path.exists(dvc.stage_cache.cache_dir)
  
      run_copy("foo", "foo.bak", name="backup-foo")
      assert _recurse_count_files(dvc.stage_cache.cache_dir) == 1
  
      tmp_dir.gen("bar", "bar")
      run_copy("bar", "bar.bak", name="backup-bar")
      assert _recurse_count_files(dvc.stage_cache.cache_dir) == 2
  
      from dvc.stage import run as _run
  
      mock_restore = mocker.spy(dvc.stage_cache, "restore")
      mock_run = mocker.spy(_run, "cmd_run")
  
      (tmp_dir / "foo.bak").unlink()
      (tmp_dir / "bar.bak").unlink()
      (tmp_dir / LOCK_FILE).unlink()
      (stage,) = dvc.reproduce("backup-foo")
  
      assert (tmp_dir / "foo.bak").read_text() == "foo"
      assert (tmp_dir / LOCK_FILE).exists()
      mock_run.assert_not_called()
      mock_restore.assert_called_once_with(stage, dry=False)
      mock_restore.reset_mock()
  
      (stage,) = dvc.reproduce("backup-bar")
  
      assert (tmp_dir / "bar.bak").read_text() == "bar"
      assert (tmp_dir / LOCK_FILE).exists()
      mock_run.assert_not_called()
      mock_restore.assert_called_once_with(stage, dry=False)
  
file_path: dvc/tests/func/test_run_cache.py
imports: import os
  import pytest
  from funcy import first
  from dvc.dvcfile import LOCK_FILE
  from dvc.stage.cache import RunCacheNotSupported, _get_stage_hash
  from dvc.utils.fs import remove
label_desc: Use image node_id 9 for calling a global function with example usage: test_memory_runs_of_multiple_stages(tmp_dir, dvc, run_copy, mocker) without return types