Files
Gymnasium/gym/wrappers/test_resize_observation.py
Jesse Farebrother f6742ea808 Remove AtariEnv in favour of official ALE Python package (#2348)
* Remove AtariEnv in favour of official ALE Python

* More robust frame stacking test case

* Atari documentation update
2021-09-11 13:04:41 -04:00

31 lines
831 B
Python

import pytest
import gym
from gym.wrappers import ResizeObservation
try:
import ale_py
except ImportError:
ale_py = None
@pytest.mark.skipif(
ale_py is None, reason="Only run this test when ale_py is installed"
)
@pytest.mark.parametrize(
"env_id", ["PongNoFrameskip-v0", "SpaceInvadersNoFrameskip-v0"]
)
@pytest.mark.parametrize("shape", [16, 32, (8, 5), [10, 7]])
def test_resize_observation(env_id, shape):
env = gym.make(env_id)
env = ResizeObservation(env, shape)
assert env.observation_space.shape[-1] == 3
obs = env.reset()
if isinstance(shape, int):
assert env.observation_space.shape[:2] == (shape, shape)
assert obs.shape == (shape, shape, 3)
else:
assert env.observation_space.shape[:2] == tuple(shape)
assert obs.shape == tuple(shape) + (3,)