Skip to content

Commit

Permalink
Fix missing raise.
Browse files Browse the repository at this point in the history
Without this `raise`, the check in `EnvSpec._check_can_jsonify()`
doesn't actually do anything.
  • Loading branch information
troiganto committed Apr 17, 2024
1 parent c0aa3d8 commit b1e181d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gymnasium/envs/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _check_can_jsonify(env_spec: dict[str, Any]):

for key, value in env_spec.items():
if callable(value):
ValueError(
raise ValueError(
f"Callable found in {spec_name} for {key} attribute with value={value}. Currently, Gymnasium does not support serialising callables."
)

Expand Down
15 changes: 15 additions & 0 deletions tests/envs/registration/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,18 @@ def test_spec_default_lookups():

assert gym.spec("test/TestEnv") is not None
del gym.registry["test/TestEnv"]


def test_check_can_jsonify():
def no_entry_point():
pass

gym.register(id="test/TestEnv-v0", entry_point=no_entry_point)
with pytest.raises(
ValueError,
match="^Callable found in test/TestEnv-v0 for entry_point attribute "
"with value=<.*>. Currently, Gymnasium does not support "
"serialising callables.$",
):
gym.spec("test/TestEnv-v0").to_json()
del gym.registry["test/TestEnv-v0"]

0 comments on commit b1e181d

Please sign in to comment.