Files
Gymnasium/tests/wrappers/test_lambda_observation.py

23 lines
877 B
Python
Raw Normal View History

"""Test suite for LambdaObservation wrappers."""
2022-11-20 00:57:10 +01:00
import numpy as np
2022-12-10 22:04:14 +00:00
from gymnasium.spaces import Box
from gymnasium.wrappers import TransformObservation
2022-12-05 19:14:56 +00:00
from tests.testing_env import GenericTestEnv
from tests.wrappers.utils import check_obs, record_action_as_obs_step, record_obs_reset
2022-11-20 00:57:10 +01:00
2022-12-05 19:14:56 +00:00
def test_lambda_observation_wrapper():
"""Tests lambda observation that the function is applied to both the reset and step observation."""
env = GenericTestEnv(
2022-12-10 22:04:14 +00:00
reset_func=record_obs_reset, step_func=record_action_as_obs_step
2022-12-05 19:14:56 +00:00
)
wrapped_env = TransformObservation(env, lambda _obs: _obs + 2, Box(2, 3))
2022-12-05 19:14:56 +00:00
obs, info = wrapped_env.reset(options={"obs": np.array([0], dtype=np.float32)})
2022-12-10 22:04:14 +00:00
check_obs(env, wrapped_env, obs, info["obs"])
2022-12-05 19:14:56 +00:00
obs, _, _, _, info = wrapped_env.step(np.array([1], dtype=np.float32))
2022-12-10 22:04:14 +00:00
check_obs(env, wrapped_env, obs, info["obs"])