Files
Gymnasium/tests/utils/test_env_checker.py
Ariel Kwiatkowski 925823661d Add options to the signature of env.reset (#2515)
* First find/replace, now tests

* Fixes to the vector env

* Make seed keyword only in wrappers

* (try to) fix the bug with old environments using new wrappers (with the seed keyword)

* black

* Change **kwargs to options, try to make it work; black

* Add OrderEnforcing wrapper to wrapper exports
Add a test for compatibility with old (pybullet-like) envs

* Add OrderEnforcing wrapper to wrapper exports
Add a test for compatibility with old (pybullet-like) envs
black

* Update the env checker

* Update the env checker

* Update the env checker to use inspect (might fail tests, let's see)

* Allow the signature to include kwargs in env_checker

* Minor fix
2022-01-19 17:28:59 -05:00

39 lines
1.1 KiB
Python

from typing import Optional
import gym
import numpy as np
import pytest
from gym.spaces import Box, Dict, Discrete
from gym.utils.env_checker import check_env
class ActionDictTestEnv(gym.Env):
action_space = Dict({"position": Discrete(1), "velocity": Discrete(1)})
observation_space = Box(low=-1.0, high=2.0, shape=(3,), dtype=np.float32)
def step(self, action):
observation = np.array([1.0, 1.5, 0.5])
reward = 1
done = True
return observation, reward, done
def reset(self, *, seed: Optional[int] = None, options: Optional[dict] = None):
super().reset(seed=seed)
return np.array([1.0, 1.5, 0.5])
def render(self, mode="human"):
pass
def test_check_env_dict_action():
# Environment.step() only returns 3 values: obs, reward, done. Not info!
test_env = ActionDictTestEnv()
with pytest.raises(AssertionError) as errorinfo:
check_env(env=test_env, warn=True)
assert (
str(errorinfo.value)
== "The `step()` method must return four values: obs, reward, done, info"
)