@@ -17,12 +17,12 @@ def test_local_loading(mock_static_model: StaticModel) -> None:
1717 with patch (
1818 "model2vec.persistence.persistence.huggingface_hub.snapshot_download" ,
1919 ) as mock_snapshot :
20- mock_snapshot .return_value = dir_name
20+ mock_snapshot .return_value = Path ( dir_name )
2121 # Patch the cache to return the local path, simulate a cache hit
2222 # we pass a fake model name to actually hit the cache and snapshot download paths
2323 with patch ("model2vec.persistence.persistence.maybe_get_cached_model_path" ) as cache :
2424 # Simulate cache hit
25- cache .return_value = dir_name
25+ cache .return_value = Path ( dir_name )
2626 s = StaticModel .from_pretrained ("haha" , force_download = True )
2727 assert s .tokens == mock_static_model .tokens
2828 s = StaticModel .from_pretrained ("haha" , force_download = False )
@@ -52,6 +52,17 @@ def test_garbage(mock_static_model: StaticModel) -> None:
5252 StaticModel .from_pretrained (dir_name )
5353
5454
55+ def test_subfolder_loading (mock_static_model : StaticModel ) -> None :
56+ """Test that garbage loading crashes."""
57+ with TemporaryDirectory () as dir_name :
58+ dir_name_path = Path (dir_name )
59+ mock_static_model .save_pretrained (dir_name_path / "subfolder" )
60+ with pytest .raises (ValueError ):
61+ StaticModel .from_pretrained (dir_name )
62+ model = StaticModel .from_pretrained (dir_name , subfolder = "subfolder" )
63+ assert isinstance (model , StaticModel )
64+
65+
5566def test_maybe_get_cached_model_path () -> None :
5667 """Test cached model path."""
5768 model_id = "t/t"
0 commit comments