MCPcopy
hub / github.com/DLR-RM/stable-baselines3 / test_monitor_error_cases

Function test_monitor_error_cases

tests/test_monitor.py:147–174  ·  view source on GitHub ↗

Test error cases in Monitor wrapper

()

Source from the content-addressed store, hash-verified

145
146
147def test_monitor_error_cases():
148 """
149 Test error cases in Monitor wrapper
150 """
151 env = gym.make("CartPole-v1")
152 env.reset(seed=0)
153
154 with pytest.raises(RuntimeError, match="Tried to reset an environment before done"):
155 monitor_env = Monitor(env, allow_early_resets=False)
156 monitor_env.reset()
157 monitor_env.step(monitor_env.action_space.sample())
158 monitor_env.reset()
159
160 env2 = gym.make("CartPole-v1")
161 env2.reset(seed=0)
162 with pytest.raises(ValueError, match="Expected you to pass keyword argument test_key into reset"):
163 monitor_env2 = Monitor(env2, reset_keywords=("test_key",))
164 monitor_env2.reset()
165
166 # Note: cannot use test_key because CartPole doesn't accept this keyword
167 monitor_env2 = Monitor(env2, reset_keywords=("options",))
168 monitor_env2.reset(options={"ok": 1})
169
170 env3 = gym.make("CartPole-v1")
171 env3.reset(seed=0)
172 with pytest.raises(RuntimeError, match="Tried to step environment that needs reset"):
173 monitor_env3 = Monitor(env3)
174 monitor_env3.step(monitor_env3.action_space.sample())

Callers

nothing calls this directly

Calls 5

resetMethod · 0.95
stepMethod · 0.95
MonitorClass · 0.90
resetMethod · 0.45
sampleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…