From 7a6e4ac3de40a52279d25e7e0e6739df2cbc023e Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Fri, 26 Jul 2024 15:44:29 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20Do=20not=20mock=20create=5Fc?= =?UTF-8?q?ommit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_hub.py | 73 ++--------------------------------------------- 1 file changed, 3 insertions(+), 70 deletions(-) diff --git a/tests/test_hub.py b/tests/test_hub.py index 3a7bd6d782b..b4c9f55b04a 100644 --- a/tests/test_hub.py +++ b/tests/test_hub.py @@ -57,81 +57,14 @@ def test_convert_to_parquet(temporary_repo, hf_api, hf_token, ci_hub_config, ci_ repo_id=repo_id, repo_type="dataset", ) - commit_info = SimpleNamespace( - pr_revision="refs/pr/1", # "main", # - pr_url="https:///hub-ci.huggingface.co/datasets/__DUMMY_USER__/__DUMMY_DATASET__/refs%2Fpr%2F1", - ) - with patch.object(datasets.hub.HfApi, "create_commit", return_value=commit_info) as mock_create_commit: - with patch.object(datasets.hub.HfApi, "create_branch") as mock_create_branch: - with patch.object(datasets.hub.HfApi, "list_repo_tree", return_value=[]): # not needed - _ = convert_to_parquet(repo_id, token=hf_token, trust_remote_code=True) + with patch.object(datasets.hub.HfApi, "create_branch") as mock_create_branch: + with patch.object(datasets.hub.HfApi, "list_repo_tree", return_value=[]): # not needed + _ = convert_to_parquet(repo_id, token=hf_token, trust_remote_code=True) # mock_create_branch assert mock_create_branch.called assert mock_create_branch.call_count == 2 for call_args, expected_branch in zip(mock_create_branch.call_args_list, ["refs/pr/1", "script"]): assert call_args.kwargs.get("branch") == expected_branch - # mock_create_commit - assert mock_create_commit.called - assert mock_create_commit.call_count == 2 - expected_readmes = [ - dedent(f"""\ - --- - dataset_info: - config_name: first - features: - - name: text - dtype: string - splits: - - name: train - num_bytes: 55 - num_examples: 5 - download_size: 790 - dataset_size: 55 - {METADATA_CONFIGS_FIELD}: - - config_name: first - data_files: - - split: train - path: first/train-* - default: true - --- - """), - dedent(f"""\ - --- - dataset_info: - config_name: second - features: - - name: text - dtype: string - splits: - - name: train - num_bytes: 60 - num_examples: 5 - download_size: 798 - dataset_size: 60 - {METADATA_CONFIGS_FIELD}: - - config_name: second - data_files: - - split: train - path: second/train-* - --- - """), - ] - for call_args, expected_commit_message, expected_create_pr, expected_readme, expected_parquet_path_in_repo in zip( - mock_create_commit.call_args_list, - ["Convert dataset to Parquet", "Add 'second' config data files"], - [True, False], - expected_readmes, - ["first/train-00000-of-00001.parquet", "second/train-00000-of-00001.parquet"], - ): - assert call_args.kwargs.get("commit_message") == expected_commit_message - assert call_args.kwargs.get("create_pr") is expected_create_pr - operations = call_args.kwargs.get("operations") - assert len(operations) == 2 - for operation in operations: - if operation.path_in_repo == "README.md": - assert operation.path_or_fileobj.decode() == expected_readme - else: - assert operation.path_in_repo == expected_parquet_path_in_repo def test_delete_from_hub(temporary_repo, hf_api, hf_token, csv_path, ci_hub_config, ci_hfh_hf_hub_url) -> None: From 0e50f5c713cd0a3b3f069f933c421236bc8ded35 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Fri, 26 Jul 2024 15:45:05 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20Remove=20failing=20mark?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_hub.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_hub.py b/tests/test_hub.py index b4c9f55b04a..dd414d954f3 100644 --- a/tests/test_hub.py +++ b/tests/test_hub.py @@ -45,8 +45,6 @@ def test_dataset_url(repo_id, filename, revision): assert url == f"https://huggingface.co/datasets/{repo_id}/resolve/{revision or 'main'}/{quote(filename)}" -# Temporarily mark this test as expected to fail: GH-7073 -@pytest.mark.xfail def test_convert_to_parquet(temporary_repo, hf_api, hf_token, ci_hub_config, ci_hfh_hf_hub_url): with temporary_repo() as repo_id: hf_api.create_repo(repo_id, token=hf_token, repo_type="dataset")