"""Test using custom spaces for shared memory functions."""
withpytest.raises(
CustomSpaceError,
match=re.escape(
"Space of type `<class 'gymnasium.spaces.space.Space'>` doesn't have an registered `create_shared_memory` function. Register `<class 'gymnasium.spaces.space.Space'>` for `create_shared_memory` to support it."
),
):
create_shared_memory(Space())
withpytest.raises(
CustomSpaceError,
match=re.escape(
"Space of type `<class 'gymnasium.spaces.space.Space'>` doesn't have an registered `read_from_shared_memory` function. Register `<class 'gymnasium.spaces.space.Space'>` for `read_from_shared_memory` to support it."
),
):
read_from_shared_memory(Space(),None,1)
withpytest.raises(
CustomSpaceError,
match=re.escape(
"Space of type `<class 'gymnasium.spaces.space.Space'>` doesn't have an registered `write_to_shared_memory` function. Register `<class 'gymnasium.spaces.space.Space'>` for `write_to_shared_memory` to support it."
),
):
write_to_shared_memory(Space(),1,None,None)
deftest_non_space():
"""Test the use of non-space types on the shared memory functions."""
withpytest.raises(
TypeError,
match=re.escape(
"The space provided to `create_shared_memory` is not a gymnasium Space instance, type: <class 'str'>, space"
),
):
create_shared_memory("space")
withpytest.raises(
TypeError,
match=re.escape(
"The space provided to `read_from_shared_memory` is not a gymnasium Space instance, type: <class 'str'>, space"
),
):
read_from_shared_memory("space",None,1)
withpytest.raises(
TypeError,
match=re.escape(
"The space provided to `write_to_shared_memory` is not a gymnasium Space instance, type: <class 'str'>, space"