Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API tests for all supported environments #18

Merged
merged 11 commits into from
Jan 30, 2023

Conversation

ppasupat
Copy link
Collaborator

Description

For all registered environments (excluding FlightWoB), added tests for the following:

  • Run gymnasium.utils.env_checker.check_env, which checks the observation space and seed determinism (except click-pie, where the UI position can jitter by a few pixels).
  • Verify the flattened observation space.

Also added a utility for inspecting the observation space. Tasks were modified to pass the tests.

Addressed part of issue #15.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (not applicable)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the tests look good, I just have a couple of minor questions

print()
if terminated:
break
finally:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not catch the exception and tell the user?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any exception would halt the program (and the stack trace would be printed to stderr). The try-finally block is there to ensure that the environment is closed.

from gymnasium import spaces
from gymnasium.utils.env_checker import check_env
from gymnasium.wrappers.flatten_observation import FlattenObservation

import miniwob # noqa: F401
from miniwob.tests.utils import ALL_TESTABLE_MINIWOB_ENVS


class TestGymAPI:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks completely fine, Im just more use to functional style testing rather than class based testing.
Is @pytest.fixture(params=...) equal to @pytest.mark.parameterize("env_id", ALL_...)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should do the same thing.

@@ -0,0 +1,111 @@
"""Test utilities."""

ALL_TESTABLE_MINIWOB_ENVS = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn that is alot of environments, is there anyway to make this programmatic? i.e., loop over the environment registry (gymnasium.registry) for all env id with miniwob in the env_id (more proper would be to check namespace)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed to reading from the registry.


# Throw errors on warnings, except for some specific warnings.
filterwarnings = [
"error",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we filtering errors?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "error" in filterwarnings means to turn warnings into errors (source). I have edited the comment to clarify this.

.github/workflows/build.yml Outdated Show resolved Hide resolved
@ppasupat
Copy link
Collaborator Author

Sorry for not responding earlier. I have addressed the comments.

@pseudo-rnd-thoughts
Copy link
Member

Thanks for the PR, looks good

@pseudo-rnd-thoughts pseudo-rnd-thoughts merged commit 68fa19a into Farama-Foundation:master Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants