-
-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
320b52c
commit e9f4655
Showing
7 changed files
with
123 additions
and
83 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
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,25 @@ | ||
# A Dockerfile that sets up a full Gymnasium install with test dependencies | ||
ARG PYTHON_VERSION | ||
FROM python:$PYTHON_VERSION | ||
|
||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
|
||
RUN apt-get -y update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
unzip \ | ||
libglu1-mesa-dev \ | ||
libgl1-mesa-dev \ | ||
libosmesa6-dev \ | ||
xvfb \ | ||
patchelf \ | ||
ffmpeg cmake \ | ||
&& apt-get autoremove -y \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY . /usr/local/gymnasium/ | ||
WORKDIR /usr/local/gymnasium/ | ||
|
||
RUN pip install .[testing] --no-cache-dir | ||
|
||
ENTRYPOINT ["/usr/local/gymnasium/bin/docker_entrypoint"] |
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
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,74 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from gymnasium.logger import warn | ||
from tests.envs.utils import all_testing_env_specs | ||
|
||
|
||
def check_rendered(rendered_frame, mode: str): | ||
"""Check that the rendered frame is as expected.""" | ||
if mode == "rgb_array_list": | ||
assert isinstance(rendered_frame, list) | ||
for frame in rendered_frame: | ||
check_rendered(frame, "rgb_array") | ||
elif mode == "rgb_array": | ||
assert isinstance(rendered_frame, np.ndarray) | ||
assert len(rendered_frame.shape) == 3 | ||
assert rendered_frame.shape[2] == 3 | ||
assert np.all(rendered_frame >= 0) and np.all(rendered_frame <= 255) | ||
elif mode == "ansi": | ||
assert isinstance(rendered_frame, str) | ||
assert len(rendered_frame) > 0 | ||
elif mode == "state_pixels_list": | ||
assert isinstance(rendered_frame, list) | ||
for frame in rendered_frame: | ||
check_rendered(frame, "rgb_array") | ||
elif mode == "state_pixels": | ||
check_rendered(rendered_frame, "rgb_array") | ||
elif mode == "depth_array_list": | ||
assert isinstance(rendered_frame, list) | ||
for frame in rendered_frame: | ||
check_rendered(frame, "depth_array") | ||
elif mode == "depth_array": | ||
assert isinstance(rendered_frame, np.ndarray) | ||
assert len(rendered_frame.shape) == 2 | ||
else: | ||
warn( | ||
f"Unknown render mode: {mode}, cannot check that the rendered data is correct. Add case to `check_rendered`" | ||
) | ||
|
||
|
||
# We do not check render_mode for some mujoco envs and any old Gym environment wrapped by `GymEnvironment` | ||
render_mode_env_specs = [ | ||
spec | ||
for spec in all_testing_env_specs | ||
if "mujoco" not in spec.entry_point or "v4" in spec.id | ||
] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"spec", render_mode_env_specs, ids=[spec.id for spec in render_mode_env_specs] | ||
) | ||
def test_render_modes(spec): | ||
"""There is a known issue where rendering a mujoco environment then mujoco-py will cause an error on non-mac based systems. | ||
Therefore, we are only testing with mujoco environments. | ||
""" | ||
env = spec.make() | ||
|
||
assert "rgb_array" in env.metadata["render_modes"] | ||
|
||
for mode in env.metadata["render_modes"]: | ||
if mode != "human": | ||
new_env = spec.make(render_mode=mode) | ||
|
||
new_env.reset() | ||
rendered = new_env.render() | ||
check_rendered(rendered, mode) | ||
|
||
new_env.step(new_env.action_space.sample()) | ||
rendered = new_env.render() | ||
check_rendered(rendered, mode) | ||
|
||
new_env.close() | ||
env.close() |
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