code: def test_run_evaluation_episodes_with_n_steps(n_episodes, n_steps):
      # MagicMock can mock eval_mode while Mock cannot
      agent = mock.MagicMock()
      env = mock.Mock()
      # First episode: 0 -> 1 -> 2 -> 3 (reset)
      # Second episode: 4 -> 5 -> 6 -> 7 (done)
      env.reset.side_effect = [("state", 0), ("state", 4)]
      env.step.side_effect = [
          (("state", 1), 0.1, False, {}),
          (("state", 2), 0.2, False, {}),
          (("state", 3), 0.3, False, {"needs_reset": True}),
          (("state", 5), -0.5, False, {}),
          (("state", 6), 0, False, {}),
          (("state", 7), 1, True, {}),
      ]
  
      if n_episodes:
          with pytest.raises(AssertionError):
              scores, lengths = evaluator.run_evaluation_episodes(
                  env, agent, n_steps=n_steps, n_episodes=n_episodes
              )
      else:
          scores, lengths = evaluator.run_evaluation_episodes(
              env, agent, n_steps=n_steps, n_episodes=n_episodes
          )
          assert agent.act.call_count == n_steps
          assert agent.observe.call_count == n_steps
          if n_steps == 2:
              assert len(scores) == 1
              assert len(lengths) == 1
              np.testing.assert_allclose(scores[0], 0.3)
              np.testing.assert_allclose(lengths[0], 2)
          elif n_steps == 5:
              assert len(scores) == 1
              assert len(lengths) == 1
              np.testing.assert_allclose(scores[0], 0.6)
              np.testing.assert_allclose(lengths[0], 3)
          else:
              assert len(scores) == 2
              assert len(lengths) == 2
              np.testing.assert_allclose(scores[0], 0.6)
              np.testing.assert_allclose(scores[1], 0.5)
              np.testing.assert_allclose(lengths[0], 3)
              np.testing.assert_allclose(lengths[1], 3)
  
file_path: pfrl/tests/experiments_tests/test_evaluator.py
imports: import tempfile
  import unittest
  from unittest import mock
  import numpy
  import pytest
  import pfrl
  from pfrl.experiments import evaluator
label_desc: Use image node_id 3 for calling a global function with example usage: test_run_evaluation_episodes_with_n_steps(n_episodes, n_steps) without return types