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

Ruggedizes list_local_datasets and adds basic tests for CLI #126

Merged

Conversation

grahamannett
Copy link
Contributor

@grahamannett grahamannett commented Jul 30, 2023

Description

There was an issue where if you used minari cli it would break if you had datasets that metadata isnt available. Can see here:
ss_2023-07-29_at_8 09 11_PM

Fixes # (issue), Depends on # (pull request)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Please attach before and after screenshots of the change if applicable.
To upload images to a PR -- simply drag and drop or copy paste.

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have run pytest -v and no errors are present.
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I solved any possible warnings that pytest -v has generated that are related to my code to the best of my knowledge.
  • 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
Collaborator

@balisujohn balisujohn left a comment

Choose a reason for hiding this comment

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

A few comments and questions. The ruggedization of list_local_datasets all seems correct; the pattern for testing the CLI seems correct, and the only potential improvement would be mocking functions such as download_dataset, though I don't know what the pattern is for doing that, and I don't think it's essential.

def test_list_app():
result = runner.invoke(app, ["list", "local", "--all"])
assert result.exit_code == 0
# some of the other columns may be cut off by Rich
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is "Rich" as alluded to in this comment is that rich text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from rich.table import Table

my initial plan was just check if the whole header is what is expected in the table but the table format changes depending on terminal size. i'm pretty sure there is a way it could be done by specifying something related in rich but i think it might require changing more aspects of the cli.py file

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's fine as-is, I didn't realize rich as actually a package we used in the CLI

"""

# might have to clear up the local dataset first.
# ideally this seems like it could just be handled by the tests
Copy link
Collaborator

@balisujohn balisujohn Jul 30, 2023

Choose a reason for hiding this comment

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

It might be possible to mock the actual download_dataset function called by the cli function if we really want to avoid repetition, particularly because dataset downloads are slow and add to the overall test time, but I don't think it's strictly speaking required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these lines + 34+35 probably can be removed but i dont know if some other test will download the dataset for testing elsewhere and this runs concurrent or afterwords and the dataset wasnt cleaned up by the other test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As long as each test cleans up after itself, its fine if they also have redundant cleaning at the beginning. Your test cleans up the dataset it downloads, so I think it's fine.

@@ -36,16 +36,19 @@ def _show_dataset_table(datasets, table_title):
table.add_column("Email", justify="left", style="magenta")

for dst_metadata in datasets.values():
author = dst_metadata.get("author", "Unknown")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like a reasonable ruggedization.

@@ -59,8 +59,9 @@ def list_local_datasets(
main_file_path = os.path.join(datasets_path, dst_id, "data/main_data.hdf5")
with h5py.File(main_file_path, "r") as f:
metadata = dict(f.attrs.items())
if compatible_minari_version and __version__ not in SpecifierSet(
metadata["minari_version"]
if ("minari_version" not in metadata) or (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also good ruggedization

@grahamannett
Copy link
Contributor Author

the pre-commit hook let me commit because its showing issues in other files not related to this, is running with --all-files not what others are doing?

Copy link
Collaborator

@balisujohn balisujohn left a comment

Choose a reason for hiding this comment

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

LGTM :^)

@balisujohn balisujohn changed the title Graham/fix list local version Ruggedizes list_local_datasets and adds basic tests for CLI Jul 30, 2023
@balisujohn balisujohn merged commit 0320c4c into Farama-Foundation:main Jul 30, 2023
10 checks passed
@grahamannett grahamannett deleted the graham/fix-list-local-version branch August 2, 2023 17:54
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