class_docstr: Mixin for testing actor-learner training.
  Inherit this after _TestTraining to enable test cases for batch training.
class_docstr_tok: ["Mixin","for","testing","actor-learner","training",".","Inherit","this","after","_TestTraining","to","enable","test","cases","for","batch","training","."]
code: def _test_actor_learner_training(
      self, gpu, steps=100000, require_success=True
  ):
      logging.basicConfig(level=logging.DEBUG)
  
      test_env, successful_return = self.make_env_and_successful_return(
          test=True
      )
      agent = self.make_agent(test_env, gpu)
  
      # cumulative_steps init to 0
      assert agent.cumulative_steps == 0
  
      def make_env(process_idx, test):
          env, _ = self.make_env_and_successful_return(test=test)
          return env
  
      step_hook = mock.Mock()
      optimizer_step_hook = mock.Mock()
  
      # Train
      if steps > 0:
          (
              make_actor,
              learner,
              poller,
              exception_event,
          ) = agent.setup_actor_learner_training(
              n_actors=2,
              step_hooks=[step_hook],
              optimizer_step_hooks=[optimizer_step_hook],
          )
  
          poller.start()
          learner.start()
          train_agent_async(
              processes=2,
              steps=steps,
              outdir=self.tmpdir,
              eval_interval=200,
              eval_n_steps=None,
              eval_n_episodes=5,
              successful_score=successful_return,
              make_env=make_env,
              make_agent=make_actor,
              stop_event=learner.stop_event,
              exception_event=exception_event,
          )
          learner.stop()
          learner.join()
          poller.stop()
          poller.join()
  
      # Test
  
      # Because in actor-learner traininig the model can be updated between
      # evaluation and saving, it is difficult to guarantee the learned
      # model successfully passes the test.
      # Thus we only check if the training was successful.
  
      # As the test can finish before running all the steps,
      # we can only test the range
      assert agent.cumulative_steps > 0
      assert agent.cumulative_steps <= steps + 1
  
      # Unlike the non-actor-learner cases, the step_hooks and
      # optimizer_step_hooks are only called when the update happens
      # when we do a fast test, the update may not be triggered due to
      # limited amount of experience, the call_count can be 0 in such case
      assert step_hook.call_count >= 0
      assert step_hook.call_count <= steps / agent.update_interval
      assert optimizer_step_hook.call_count == step_hook.call_count
  
      for i, call in enumerate(step_hook.call_args_list):
          args, kwargs = call
          assert args[0] is None
          assert args[1] is agent
          assert args[2] == (i + 1) * agent.update_interval
  
      for i, call in enumerate(optimizer_step_hook.call_args_list):
          args, kwargs = call
          assert args[0] is None
          assert args[1] is agent
          assert args[2] == i + 1
  
      successful_path = os.path.join(self.tmpdir, "successful")
      finished_path = os.path.join(
          self.tmpdir, "{}_finish".format(steps)
      )
      if require_success:
          assert os.path.exists(successful_path)
      else:
          assert os.path.exists(successful_path) or os.path.exists(
              finished_path
          )
  
imports: import logging
  import os
  import tempfile
  from unittest import mock
  import numpy
  import pytest
  import pfrl
  from pfrl.experiments import train_agent_async, train_agent_batch_with_evaluation, train_agent_with_evaluation
  from pfrl.experiments.evaluator import batch_run_evaluation_episodes, run_evaluation_episodes
  from pfrl.utils import random_seed
label_desc: Use image node_id 1 for calling the _TestActorLearnerTrainingMixin obj's underlying member method code with example usage: obj._test_actor_learner_training(gpu, steps, require_success) and returns: env