Skip to content

Commit

Permalink
Add regression test for empty modelcard update (#1060)
Browse files Browse the repository at this point in the history
* add regression test

* typing
  • Loading branch information
Wauplin authored Sep 20, 2022
1 parent 300b792 commit 15d0f5d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_repocard.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
---
"""

DUMMY_MODELCARD_NO_TEXT_CONTENT = """---
license: cc-by-sa-4.0
---
"""

logger = logging.get_logger(__name__)

REPOCARD_DIR = os.path.join(
Expand Down Expand Up @@ -394,6 +399,23 @@ def test_update_new_result_new_dataset(self):
updated_metadata = metadata_load(self.repo_path / self.REPO_NAME / "README.md")
self.assertDictEqual(updated_metadata, expected_metadata)

def test_update_metadata_on_empty_text_content(self) -> None:
"""Test `update_metadata` on a model card that has metadata but no text content
Regression test for https://github.com/huggingface/huggingface_hub/issues/1010
"""
# Create modelcard with metadata but empty text content
with self.repo.commit("Add README to main branch"):
with open("README.md", "w") as f:
f.write(DUMMY_MODELCARD_NO_TEXT_CONTENT)
metadata_update(f"{USER}/{self.REPO_NAME}", {"tag": "test"}, token=self._token)

# Check update went fine
self.repo.git_pull()
updated_metadata = metadata_load(self.repo_path / self.REPO_NAME / "README.md")
expected_metadata = {"license": "cc-by-sa-4.0", "tag": "test"}
self.assertDictEqual(updated_metadata, expected_metadata)


class TestCaseWithCapLog(unittest.TestCase):
_api = HfApi(endpoint=ENDPOINT_STAGING)
Expand Down

0 comments on commit 15d0f5d

Please sign in to comment.