docstr: Tests that the connector respects the flags within view_requirements (i.e.
  used_for_training, used_for_compute_actions).
  
  the returned data is the input dict itself, which the policy collector in
  env_runner will use to construct the episode, and a SampleBatch that can be
  used to run corresponding policy.
docstr_tok: ["Tests","that","the","connector","respects","the","flags","within","view_requirements","(","i.e",".","used_for_training",",","used_for_compute_actions",")",".","the","returned","data","is","the","input","dict","itself",",","which","the","policy","collector","in","env_runner","will","use","to","construct","the","episode",",","and","a","SampleBatch","that","can","be","used","to","run","corresponding","policy","."]
code: def test_vr_connector_respects_training_or_inference_vr_flags(self):
      """Tests that the connector respects the flags within view_requirements (i.e.
      used_for_training, used_for_compute_actions).
  
      the returned data is the input dict itself, which the policy collector in
      env_runner will use to construct the episode, and a SampleBatch that can be
      used to run corresponding policy.
      """
      view_rq_dict = {
          "both": ViewRequirement(
              "obs",
              used_for_training=True,
              used_for_compute_actions=True,
          ),
          "only_inference": ViewRequirement(
              "obs",
              used_for_training=False,
              used_for_compute_actions=True,
          ),
          "none": ViewRequirement(
              "obs",
              used_for_training=False,
              used_for_compute_actions=False,
          ),
          "only_training": ViewRequirement(
              "obs",
              used_for_training=True,
              used_for_compute_actions=False,
          ),
      }
  
      obs_arr = np.array([0, 1, 2, 3])
      agent_data = {SampleBatch.NEXT_OBS: obs_arr}
      data = AgentConnectorDataType(0, 1, agent_data)
  
      config = PPOConfig().to_dict()
      ctx = ConnectorContext(
          view_requirements=view_rq_dict,
          config=config,
          is_policy_recurrent=True,
      )
  
      sample_batch_expected = SampleBatch(
          {
              "both": obs_arr[None],
              # Output in training model as well.
              "only_inference": obs_arr[None],
              "seq_lens": np.array([1]),
          }
      )
  
      c = ViewRequirementAgentConnector(ctx)
      c.in_training()
      processed = c([data])
  
      raw_dict = processed[0].data.raw_dict
      sample_batch = processed[0].data.sample_batch
  
      check(raw_dict, agent_data)
      check(sample_batch, sample_batch_expected)
  
imports: import gymnasium
  from gymnasium.spaces import Box
  import numpy
  import tree
  import unittest
  from ray.rllib.algorithms.ppo.ppo import PPOConfig
  from ray.rllib.connectors.agent.clip_reward import ClipRewardAgentConnector
  from ray.rllib.connectors.agent.lambdas import FlattenDataAgentConnector
  from ray.rllib.connectors.agent.obs_preproc import ObsPreprocessorConnector
  from ray.rllib.connectors.agent.pipeline import AgentConnectorPipeline
  from ray.rllib.connectors.agent.state_buffer import StateBufferConnector
  from ray.rllib.connectors.agent.view_requirement import ViewRequirementAgentConnector
  from ray.rllib.connectors.connector import ConnectorContext
  from ray.rllib.connectors.registry import get_connector
  from ray.rllib.policy.view_requirement import ViewRequirement
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.test_utils import check
  from ray.rllib.utils.typing import ActionConnectorDataType, AgentConnectorDataType, AgentConnectorsOutput
  from ray.rllib.connectors.agent.mean_std_filter import MeanStdObservationFilterAgentConnector
label_desc: Use image node_id 1 for calling the TestViewRequirementAgentConnector obj's underlying member method code with example usage: obj.test_vr_connector_respects_training_or_inference_vr_flags() without return types