-
Notifications
You must be signed in to change notification settings - Fork 3k
Add tests for dataset cards #2348
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7033a4e
Add dataset card tests
gchhablani fbfbd29
Fix style
gchhablani c785291
Add combined dataset card test
gchhablani 3ece9df
Fix code quality
gchhablani c4c0456
Change variable name
gchhablani 751f67c
Merge remote-tracking branch 'upstream/master' into add-readme-tests
gchhablani 78f25d2
Fix get_changed_datasets
gchhablani 4e2c6c5
Fix style
gchhablani 44bc990
Update get_changed_datasets
gchhablani 4d648f6
Remove scripts, combine tests
gchhablani f1c5ad9
Fix style
gchhablani c7d7ca7
Merge remote-tracking branch 'upstream/master' into add-readme-tests
gchhablani 238cb94
Add changes from review
gchhablani 14d2ac1
Fix get_changed_datasets
gchhablani 365f278
Fix get_changed_datasets
gchhablani 29d7df7
Add changes from review
gchhablani 412ecb0
Merge remote-tracking branch 'upstream/master' into add-readme-tests
gchhablani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2021 HuggingFace Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from pathlib import Path | ||
| from subprocess import check_output | ||
| from typing import List | ||
|
|
||
| import pytest | ||
|
|
||
| from datasets.utils.logging import get_logger | ||
| from datasets.utils.metadata import DatasetMetadata | ||
| from datasets.utils.readme import ReadMe | ||
|
|
||
| from .utils import slow | ||
|
|
||
|
|
||
| repo_path = Path.cwd() | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def get_changed_datasets(repo_path: Path) -> List[Path]: | ||
| diff_output = check_output(["git", "diff", "--name-only", "HEAD..origin/master"], cwd=repo_path) | ||
| changed_files = [Path(repo_path, f) for f in diff_output.decode().splitlines()] | ||
|
|
||
| datasets_dir_path = repo_path / "datasets" | ||
|
|
||
| changed_datasets = set( | ||
| f.parent.name for f in changed_files if f.exists() and str(f.resolve()).startswith(str(datasets_dir_path)) | ||
| ) | ||
|
|
||
| return sorted(changed_datasets) | ||
|
|
||
|
|
||
| def get_all_datasets(repo_path: Path) -> List[Path]: | ||
| return [path.parts[-1] for path in (repo_path / "datasets").iterdir()] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("dataset_name", get_changed_datasets(repo_path)) | ||
| def test_changed_dataset_card(dataset_name): | ||
| card_path = repo_path / "datasets" / dataset_name / "README.md" | ||
| assert card_path.exists() | ||
| error_messages = [] | ||
| try: | ||
| ReadMe.from_readme(card_path) | ||
| except Exception as readme_error: | ||
| error_messages.append(f"The following issues have been found in the dataset cards:\nREADME:\n{readme_error}") | ||
| try: | ||
| DatasetMetadata.from_readme(card_path) | ||
| except Exception as metadata_error: | ||
| error_messages.append( | ||
| f"The following issues have been found in the dataset cards:\nYAML tags:\n{metadata_error}" | ||
| ) | ||
|
|
||
| if error_messages: | ||
| raise ValueError("\n".join(error_messages)) | ||
|
|
||
|
|
||
| @slow | ||
| @pytest.mark.parametrize("dataset_name", get_all_datasets(repo_path)) | ||
| def test_dataset_card(dataset_name): | ||
| card_path = repo_path / "datasets" / dataset_name / "README.md" | ||
| assert card_path.exists() | ||
| error_messages = [] | ||
| try: | ||
| ReadMe.from_readme(card_path) | ||
| except Exception as readme_error: | ||
| error_messages.append(f"The following issues have been found in the dataset cards:\nREADME:\n{readme_error}") | ||
| try: | ||
| DatasetMetadata.from_readme(card_path) | ||
| except Exception as metadata_error: | ||
| error_messages.append( | ||
| f"The following issues have been found in the dataset cards:\nYAML tags:\n{metadata_error}" | ||
| ) | ||
|
|
||
| if error_messages: | ||
| raise ValueError("\n".join(error_messages)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.