Skip to content

Commit

Permalink
python27 tests (openai#1314)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pzhokhov authored Feb 8, 2019
1 parent f1f8848 commit 07e0c98
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
12 changes: 8 additions & 4 deletions gym/envs/box2d/__init__.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion gym/envs/box2d/test_lunar_lander.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions gym/envs/classic_control/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions gym/envs/tests/spec_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
1 change: 0 additions & 1 deletion gym/envs/tests/test_determinism.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 07e0c98

Please sign in to comment.