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 a test to check the gated datasets warnings. #5541

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _hf_features(self) -> hf_datasets.Features:

def _info(self) -> dataset_info_lib.DatasetInfo:
ds_description = self._get_text_field('description')
ds_license = self._get_license()
ds_license = self._get_license() or ''
if self._is_gated():
ds_description = self._gated_text + '\n' + ds_description
ds_license = ds_license + ' ' + self._gated_dataset_warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def mock_hub_dataset_info():
downloads=123,
likes=456,
tags=[],
gated='automatic',
card_data={'extra_gated_prompt': 'Extra condition'},
)
with mock.patch.object(
huggingface_hub, 'dataset_info', return_value=fake_dataset_info
Expand Down Expand Up @@ -111,12 +113,32 @@ def mock_huggingface_dataset_builder(


def test_dataset_info(builder):
assert builder.info.description == 'description'
assert builder.info.description.endswith('description')
assert builder.info.citation == 'citation from the hub'
assert builder.info.redistribution_info.license == 'test-license'
assert builder.info.redistribution_info.license.startswith('test-license')
assert builder.info.homepage == 'https://huggingface.co/datasets/foo/bar'


def test_gated_text(builder):
expected_warning = (
'WARNING: This dataset is gated. Before using it, make sure to sign the'
' conditions at: https://huggingface.co/datasets/foo/bar. Important:'
' access requests are always granted to individual users rather than to'
' entire organizations.'
)
expected_conditions = (
'The conditions consist of:\nBy agreeing you'
' accept to share your contact information (email and username) with the'
' repository authors.\nExtra condition'
)
expected_gated_text = expected_warning + '\n' + expected_conditions
assert builder._gated_text == expected_gated_text
expected_description = expected_gated_text + '\n' + 'description'
assert builder.info.description == expected_description
expected_license = 'test-license' + ' ' + expected_warning
assert builder.info.redistribution_info.license == expected_license


def test_download_and_prepare(builder):
builder.download_and_prepare()
ds = builder.as_data_source()
Expand Down
Loading