forked from openai/baselines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run test_monitor through pytest; fix the test, add flake8 to bench di…
…reectory - like PR 891 (openai#921)
- Loading branch information
Showing
5 changed files
with
32 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# flake8: noqa F403 | ||
from baselines.bench.benchmarks import * | ||
from baselines.bench.monitor import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import re | ||
import os.path as osp | ||
import os | ||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from .monitor import Monitor | ||
import gym | ||
import json | ||
|
||
def test_monitor(): | ||
import pandas | ||
import os | ||
import uuid | ||
|
||
env = gym.make("CartPole-v1") | ||
env.seed(0) | ||
mon_file = "/tmp/baselines-test-%s.monitor.csv" % uuid.uuid4() | ||
menv = Monitor(env, mon_file) | ||
menv.reset() | ||
for _ in range(1000): | ||
_, _, done, _ = menv.step(0) | ||
if done: | ||
menv.reset() | ||
|
||
f = open(mon_file, 'rt') | ||
|
||
firstline = f.readline() | ||
assert firstline.startswith('#') | ||
metadata = json.loads(firstline[1:]) | ||
assert metadata['env_id'] == "CartPole-v1" | ||
assert set(metadata.keys()) == {'env_id', 't_start'}, "Incorrect keys in monitor metadata" | ||
|
||
last_logline = pandas.read_csv(f, index_col=None) | ||
assert set(last_logline.keys()) == {'l', 't', 'r'}, "Incorrect keys in monitor logline" | ||
f.close() | ||
os.remove(mon_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ exclude = | |
.git, | ||
__pycache__, | ||
baselines/ppo1, | ||
baselines/bench, |