mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-23 15:04:20 +00:00
* add dtype to Box * remove board_game, debugging, safety, parameter_tuning environments * massive set of breaking changes - remove python logging module - _step, _reset, _seed, _close => non underscored method - remove benchmark and scoring folder * Improve render("human"), now resizable, closable window. * get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods * CubeCrash unit test environment * followup fixes * MemorizeDigits unit test envrionment * refactored spaces a bit fixed indentation disabled test_env_semantics * fix unit tests * fixes * CubeCrash, MemorizeDigits tested * gym backwards compatibility patch * gym backwards compatibility, followup fixes * changelist, add spaces to main namespaces * undo_logger_setup for backwards compat * remove configuration.py
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import numpy as np
|
|
import pytest
|
|
from gym import envs
|
|
from gym.envs.tests.spec_list import spec_list
|
|
|
|
# This runs a smoketest on each official registered env. We may want
|
|
# to try also running environments which are not officially registered
|
|
# envs.
|
|
@pytest.mark.parametrize("spec", spec_list)
|
|
def test_env(spec):
|
|
env = spec.make()
|
|
ob_space = env.observation_space
|
|
act_space = env.action_space
|
|
ob = env.reset()
|
|
assert ob_space.contains(ob), 'Reset observation: {!r} not in space'.format(ob)
|
|
a = act_space.sample()
|
|
observation, reward, done, _info = env.step(a)
|
|
assert ob_space.contains(observation), 'Step observation: {!r} not in space'.format(observation)
|
|
assert np.isscalar(reward), "{} is not a scalar for {}".format(reward, env)
|
|
assert isinstance(done, bool), "Expected {} to be a boolean".format(done)
|
|
|
|
for mode in env.metadata.get('render.modes', []):
|
|
env.render(mode=mode)
|
|
|
|
# Make sure we can render the environment after close.
|
|
for mode in env.metadata.get('render.modes', []):
|
|
env.render(mode=mode)
|
|
|
|
env.close()
|
|
|
|
# Run a longer rollout on some environments
|
|
def test_random_rollout():
|
|
for env in [envs.make('CartPole-v0'), envs.make('FrozenLake-v0')]:
|
|
agent = lambda ob: env.action_space.sample()
|
|
ob = env.reset()
|
|
for _ in range(10):
|
|
assert env.observation_space.contains(ob)
|
|
a = agent(ob)
|
|
assert env.action_space.contains(a)
|
|
(ob, _reward, done, _info) = env.step(a)
|
|
if done: break
|
|
env.close()
|
|
|