|
44 | 44 | from huggingface_hub.repocard_data import CardData |
45 | 45 | from huggingface_hub.utils import SoftTemporaryDirectory, is_jinja_available |
46 | 46 |
|
47 | | -from .testing_constants import ( |
48 | | - ENDPOINT_STAGING, |
49 | | - TOKEN, |
50 | | - USER, |
51 | | -) |
52 | | -from .testing_utils import ( |
53 | | - repo_name, |
54 | | - with_production_testing, |
55 | | -) |
| 47 | +from .testing_constants import ENDPOINT_STAGING, TOKEN, USER |
| 48 | +from .testing_utils import repo_name, with_production_testing |
56 | 49 |
|
57 | 50 |
|
58 | 51 | SAMPLE_CARDS_DIR = Path(__file__).parent / "fixtures/cards" |
@@ -271,6 +264,23 @@ def test_metadata_eval_result(self): |
271 | 264 | self.assertEqual(content, DUMMY_MODELCARD_EVAL_RESULT.splitlines()) |
272 | 265 |
|
273 | 266 |
|
| 267 | +@with_production_testing |
| 268 | +def test_load_from_hub_if_repo_id_or_path_is_a_dir(monkeypatch): |
| 269 | + """If `repo_id_or_path` happens to be both a `repo_id` and a local directory, the card must be loaded from the Hub. |
| 270 | +
|
| 271 | + Path can only be a file path. |
| 272 | +
|
| 273 | + Regression test for https://github.com/huggingface/huggingface_hub/issues/2768. |
| 274 | + """ |
| 275 | + with SoftTemporaryDirectory() as tmpdir: |
| 276 | + monkeypatch.chdir(tmpdir) |
| 277 | + repo_id = "openai-community/gpt2" |
| 278 | + (Path(tmpdir) / "openai-community" / "gpt2").mkdir(parents=True) |
| 279 | + |
| 280 | + card = RepoCard.load(repo_id) |
| 281 | + assert "GPT-2" in str(card) # loaded from Hub |
| 282 | + |
| 283 | + |
274 | 284 | class RepocardMetadataUpdateTest(unittest.TestCase): |
275 | 285 | def setUp(self) -> None: |
276 | 286 | self.token = TOKEN |
|
0 commit comments