mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-28 09:17:18 +00:00
* feat: add `isort` to `pre-commit` * ci: skip `__init__.py` file for `isort` * ci: make `isort` mandatory in lint pipeline * docs: add a section on Git hooks * ci: check isort diff * fix: isort from master branch * docs: add pre-commit badge * ci: update black + bandit versions * feat: add PR template * refactor: PR template * ci: remove bandit * docs: add Black badge * ci: try to remove all `|| true` statements * ci: remove lint_python job - Remove `lint_python` CI job - Move `pyupgrade` job to `pre-commit` workflow * fix: avoid messing with typing * docs: add a note on running `pre-cpmmit` manually * ci: apply `pre-commit` to the whole codebase
26 lines
806 B
Python
26 lines
806 B
Python
import numpy as np
|
|
import pytest
|
|
|
|
import gym
|
|
from gym.wrappers import TransformObservation
|
|
|
|
|
|
@pytest.mark.parametrize("env_id", ["CartPole-v1", "Pendulum-v1"])
|
|
def test_transform_observation(env_id):
|
|
affine_transform = lambda x: 3 * x + 2
|
|
env = gym.make(env_id)
|
|
wrapped_env = TransformObservation(
|
|
gym.make(env_id), lambda obs: affine_transform(obs)
|
|
)
|
|
|
|
obs = env.reset(seed=0)
|
|
wrapped_obs = wrapped_env.reset(seed=0)
|
|
assert np.allclose(wrapped_obs, affine_transform(obs))
|
|
|
|
action = env.action_space.sample()
|
|
obs, reward, done, _ = env.step(action)
|
|
wrapped_obs, wrapped_reward, wrapped_done, _ = wrapped_env.step(action)
|
|
assert np.allclose(wrapped_obs, affine_transform(obs))
|
|
assert np.allclose(wrapped_reward, reward)
|
|
assert wrapped_done == done
|