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

Function test_render

tests/test_vec_envs.py:592–657  ·  view source on GitHub ↗
(vec_env_class)

Source from the content-addressed store, hash-verified

590
591@pytest.mark.parametrize("vec_env_class", VEC_ENV_CLASSES)
592def test_render(vec_env_class):
593 # Skip if no X-Server
594 if not os.environ.get("DISPLAY"):
595 pytest.skip("No X-Server")
596
597 env_id = "Pendulum-v1"
598 # DummyVecEnv human render is currently
599 # buggy because of gym:
600 # https://github.com/carlosluis/stable-baselines3/pull/3#issuecomment-1356863808
601 n_envs = 2
602 # Human render
603 vec_env = make_vec_env(
604 env_id,
605 n_envs,
606 vec_env_cls=vec_env_class,
607 env_kwargs=dict(render_mode="human"),
608 )
609
610 vec_env.reset()
611 vec_env.render()
612
613 with pytest.warns(UserWarning):
614 vec_env.render("rgb_array")
615
616 with pytest.warns(UserWarning):
617 vec_env.render(mode="blah")
618
619 for _ in range(10):
620 vec_env.step([vec_env.action_space.sample() for _ in range(n_envs)])
621 vec_env.render()
622
623 vec_env.close()
624 # rgb_array render, which allows human_render
625 # thanks to OpenCV
626 vec_env = make_vec_env(
627 env_id,
628 n_envs,
629 vec_env_cls=vec_env_class,
630 env_kwargs=dict(render_mode="rgb_array"),
631 )
632
633 vec_env.reset()
634 with warnings.catch_warnings(record=True) as record:
635 vec_env.render()
636 vec_env.render("rgb_array")
637 vec_env.render(mode="human")
638
639 # No warnings for using human mode
640 assert len(record) == 0
641
642 with pytest.warns(UserWarning):
643 vec_env.render(mode="blah")
644
645 for _ in range(10):
646 vec_env.step([vec_env.action_space.sample() for _ in range(n_envs)])
647 vec_env.render()
648
649 # Check that it still works with vec env wrapper

Callers

nothing calls this directly

Calls 9

resetMethod · 0.95
make_vec_envFunction · 0.90
VecFrameStackClass · 0.90
VecNormalizeClass · 0.90
getMethod · 0.45
renderMethod · 0.45
stepMethod · 0.45
sampleMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…