Files
Gymnasium/gym/monitoring/tests/test_monitor.py
Greg Brockman 9984589731 Improve score_from_local implementation (#66)
* Make sure that a callable is passed to start

* Improve autoflushing for score calculation

* Write stats and manifests using proper atomic_writes
2016-05-06 18:19:16 -07:00

48 lines
1.1 KiB
Python

import contextlib
import glob
import os
import shutil
import tempfile
import gym
from gym import error
from gym.monitoring import monitor
class FakeEnv(gym.Env):
def _render(self, close=True):
raise RuntimeError('Raising')
@contextlib.contextmanager
def tempdir():
temp = tempfile.mkdtemp()
yield temp
shutil.rmtree(temp)
def test_monitor_filename():
with tempdir() as temp:
env = gym.make('Acrobot-v0')
env.monitor.start(temp)
env.monitor.close()
manifests = glob.glob(os.path.join(temp, '*.manifest.*'))
assert len(manifests) == 1
def test_close_monitor():
with tempdir() as temp:
env = FakeEnv()
env.monitor.start(temp)
env.monitor.close()
manifests = monitor.detect_training_manifests(temp)
assert len(manifests) == 1
def test_video_callable():
with tempdir() as temp:
env = gym.make('Acrobot-v0')
try:
env.monitor.start(temp, video_callable=False)
except error.Error:
pass
else:
assert False