From 07e0c98f8e8e18c5197fab7ff74635f5b0cb2662 Mon Sep 17 00:00:00 2001 From: pzhokhov Date: Fri, 8 Feb 2019 11:46:51 -0800 Subject: [PATCH] python27 tests (#1314) * add py27 test environment (sans box2d and atari) * skip mujoco tests if mujoco_py not present * re-enable python3 tests * remove unicode symbols * remove more unicode symbols --- gym/envs/box2d/__init__.py | 12 ++++++++---- gym/envs/box2d/test_lunar_lander.py | 11 ++++++++++- gym/envs/classic_control/cartpole.py | 8 ++++---- gym/envs/tests/spec_list.py | 15 +++++++++++++++ gym/envs/tests/test_determinism.py | 1 - tox.ini | 12 +++++++++--- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/gym/envs/box2d/__init__.py b/gym/envs/box2d/__init__.py index 725f319eae8..46cb91d389b 100644 --- a/gym/envs/box2d/__init__.py +++ b/gym/envs/box2d/__init__.py @@ -1,4 +1,8 @@ -from gym.envs.box2d.lunar_lander import LunarLander -from gym.envs.box2d.lunar_lander import LunarLanderContinuous -from gym.envs.box2d.bipedal_walker import BipedalWalker, BipedalWalkerHardcore -from gym.envs.box2d.car_racing import CarRacing +try: + import Box2D + from gym.envs.box2d.lunar_lander import LunarLander + from gym.envs.box2d.lunar_lander import LunarLanderContinuous + from gym.envs.box2d.bipedal_walker import BipedalWalker, BipedalWalkerHardcore + from gym.envs.box2d.car_racing import CarRacing +except ImportError: + Box2D = None diff --git a/gym/envs/box2d/test_lunar_lander.py b/gym/envs/box2d/test_lunar_lander.py index bdd81ce58a4..d41634c987d 100644 --- a/gym/envs/box2d/test_lunar_lander.py +++ b/gym/envs/box2d/test_lunar_lander.py @@ -1,11 +1,20 @@ -from .lunar_lander import LunarLander, LunarLanderContinuous, demo_heuristic_lander +import pytest +try: + import Box2D + from .lunar_lander import LunarLander, LunarLanderContinuous, demo_heuristic_lander +except ImportError: + Box2D = None + +@pytest.mark.skipif(Box2D is None, reason='Box2D not installed') def test_lunar_lander(): _test_lander(LunarLander(), seed=0) +@pytest.mark.skipif(Box2D is None, reason='Box2D not installed') def test_lunar_lander_continuous(): _test_lander(LunarLanderContinuous(), seed=0) +@pytest.mark.skipif(Box2D is None, reason='Box2D not installed') def _test_lander(env, seed=None, render=False): total_reward = demo_heuristic_lander(env, seed=seed, render=render) assert total_reward > 100 diff --git a/gym/envs/classic_control/cartpole.py b/gym/envs/classic_control/cartpole.py index ec0f4fbb77f..96480c35803 100644 --- a/gym/envs/classic_control/cartpole.py +++ b/gym/envs/classic_control/cartpole.py @@ -23,7 +23,7 @@ class CartPoleEnv(gym.Env): Num Observation Min Max 0 Cart Position -4.8 4.8 1 Cart Velocity -Inf Inf - 2 Pole Angle -24° 24° + 2 Pole Angle -24 deg 24 deg 3 Pole Velocity At Tip -Inf Inf Actions: @@ -38,11 +38,11 @@ class CartPoleEnv(gym.Env): Reward is 1 for every step taken, including the termination step Starting State: - All observations are assigned a uniform random value between ±0.05 + All observations are assigned a uniform random value in [-0.05..0.05] Episode Termination: - Pole Angle is more than ±12° - Cart Position is more than ±2.4 (center of the cart reaches the edge of the display) + Pole Angle is more than 12 degrees + Cart Position is more than 2.4 (center of the cart reaches the edge of the display) Episode length is greater than 200 Solved Requirements Considered solved when the average reward is greater than or equal to 195.0 over 100 consecutive trials. diff --git a/gym/envs/tests/spec_list.py b/gym/envs/tests/spec_list.py index 6e9551ebaf1..6a02a1305d2 100644 --- a/gym/envs/tests/spec_list.py +++ b/gym/envs/tests/spec_list.py @@ -7,8 +7,23 @@ def should_skip_env_spec_for_tests(spec): ep = spec._entry_point # Skip mujoco tests for pull request CI skip_mujoco = not (os.environ.get('MUJOCO_KEY')) + try: + import mujoco_py + except ImportError: + skip_mujoco = True if skip_mujoco and (ep.startswith('gym.envs.mujoco:') or ep.startswith('gym.envs.robotics:')): return True + try: + import atari_py + except ImportError: + if ep.startswith('gym.envs.atari'): + return True + try: + import Box2D + except ImportError: + if ep.startswith('gym.envs.box2d'): + return True + if ( 'GoEnv' in ep or 'HexEnv' in ep or (ep.startswith("gym.envs.atari") and not spec.id.startswith("Pong") and not spec.id.startswith("Seaquest")) diff --git a/gym/envs/tests/test_determinism.py b/gym/envs/tests/test_determinism.py index d1ce2f2c0cb..d08f2dad80b 100644 --- a/gym/envs/tests/test_determinism.py +++ b/gym/envs/tests/test_determinism.py @@ -3,7 +3,6 @@ from gym.envs.tests.spec_list import spec_list - @pytest.mark.parametrize("spec", spec_list) def test_env(spec): # Note that this precludes running this test in multiple diff --git a/tox.ini b/tox.ini index 3ee8d39f359..82bb4b7185b 100644 --- a/tox.ini +++ b/tox.ini @@ -4,16 +4,22 @@ # and then run "tox" from this directory. [tox] -envlist = py3 +envlist = py27, py3 [testenv:py3] -whitelist_externals=make passenv=DISPLAY MUJOCO_KEY LD_LIBRARY_PATH TRAVIS* deps = pytest pytest-forked - mock -e .[all] commands = pytest --forked {posargs} +[testenv:py27] +passenv=DISPLAY MUJOCO_KEY LD_LIBRARY_PATH TRAVIS* +deps = + pytest + pytest-forked + -e . +commands = + pytest --forked {posargs}