def test_is_wrapped(): """Test that is_wrapped correctly detects wraps""" env = gym.make("Pendulum-v0") env = gym.Wrapper(env) assert not is_wrapped(env, Monitor) monitor_env = Monitor(env) assert is_wrapped(monitor_env, Monitor) env = gym.Wrapper(monitor_env) assert is_wrapped(env, Monitor) # Test that unwrap works as expected assert unwrap_wrapper(env, Monitor) == monitor_env
def test_typing_wrapper(): # # == test if the wrapper correctly mimics isinstance() behaviour == # env = _InnerEnv() env = gym.Wrapper(env) env = _WrapperWithInterface(env) env = Wrapper(env) assert (isinstance(env, _EnvInterfaceWrapper) and isinstance(env, _EnvInterfaceInner) and isinstance(env, _WrapperWithInterface)) # check if we can still call the inner method assert env.method_inner() == 41 # check if the wrapper works correctly assert env.method_wrapper() == 42 # # == test idempotency == # env = Wrapper(env) assert (isinstance(env, _EnvInterfaceWrapper) and isinstance(env, _EnvInterfaceInner) and isinstance(env, _WrapperWithInterface)) # check if we can still call the inner method assert env.method_inner() == 41 # check if the wrapper works correctly assert env.method_wrapper() == 42