-
-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
wrappers.vector.HumanRendering
(#1069)
Co-authored-by: Mark Towers <[email protected]>
- Loading branch information
1 parent
0607994
commit 04fb345
Showing
2 changed files
with
71 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Test suite of HumanRendering wrapper.""" | ||
import re | ||
|
||
import pytest | ||
|
||
import gymnasium as gym | ||
from gymnasium.wrappers.vector import HumanRendering | ||
|
||
|
||
@pytest.mark.parametrize("env_id", ["CartPole-v1", "Ant-v4"]) | ||
@pytest.mark.parametrize("num_envs", [1, 3, 9]) | ||
@pytest.mark.parametrize("screen_size", [None, (400, 300), (300, 600), (600, 600)]) | ||
def test_num_envs_screen_size(env_id, num_envs, screen_size): | ||
envs = gym.make_vec(env_id, num_envs=num_envs, render_mode="rgb_array") | ||
envs = HumanRendering(envs, screen_size=screen_size) | ||
|
||
assert envs.render_mode == "human" | ||
|
||
envs.reset() | ||
for _ in range(25): | ||
envs.step(envs.action_space.sample()) | ||
envs.close() | ||
|
||
|
||
def test_render_modes(): | ||
envs = HumanRendering( | ||
gym.make_vec("CartPole-v1", num_envs=3, render_mode="rgb_array_list") | ||
) | ||
assert envs.render_mode == "human" | ||
|
||
envs.reset() | ||
for _ in range(25): | ||
envs.step(envs.action_space.sample()) | ||
envs.close() | ||
|
||
# HumanRenderer on human renderer should not work | ||
with pytest.raises( | ||
AssertionError, | ||
match=re.escape( | ||
"Expected env.render_mode to be one of ['rgb_array', 'rgb_array_list', 'depth_array', 'depth_array_list'] but got 'human'" | ||
), | ||
): | ||
HumanRendering(envs) |