@@ -135,6 +135,24 @@ def test_load_pipeline_from_hub(mock_inference_pipeline: StaticModelPipeline) ->
135135 assert loaded .predict (["dog" ]).tolist () == mock_inference_pipeline .predict (["dog" ]).tolist ()
136136
137137
138+ def test_load_pipeline_from_hub_with_token (mock_inference_pipeline : StaticModelPipeline ) -> None :
139+ """Test that the token also reaches the encoder download, not just the head download."""
140+ with TemporaryDirectory () as temp_dir :
141+ mock_inference_pipeline .save_pretrained (temp_dir )
142+ downloaded_model = StaticModel .from_pretrained (temp_dir )
143+ head_path = os .path .join (temp_dir , "head.safetensors" )
144+
145+ with (
146+ patch ("model2vec.inference.model.huggingface_hub.hf_hub_download" , return_value = head_path ),
147+ patch (
148+ "model2vec.inference.model.StaticModel.from_pretrained" , return_value = downloaded_model
149+ ) as mock_from_pretrained ,
150+ ):
151+ StaticModelPipeline .from_pretrained ("fake/repo-id" , token = "secret" )
152+
153+ assert mock_from_pretrained .call_args .kwargs .get ("token" ) == "secret"
154+
155+
138156def test_push_to_hub (mock_inference_pipeline : StaticModelPipeline ) -> None :
139157 """Test that push_to_hub saves the pipeline to a temp folder before pushing it to the hub."""
140158 captured : dict [str , object ] = {}
@@ -278,6 +296,31 @@ def _fake_download(repo_id: str, filename: str, token: str | None = None) -> str
278296 assert np .allclose (loaded .predict (["dog" , "cat" ]), legacy_pipeline .predict (encoded ))
279297
280298
299+ def test_convert_legacy_pipeline_with_token (mock_static_model : StaticModel ) -> None :
300+ """Test that the token also reaches the encoder download on the legacy path."""
301+ rng = np .random .RandomState (0 )
302+ X = rng .randn (30 , mock_static_model .dim )
303+ y = rng .randn (30 , 4 )
304+ legacy_pipeline = make_pipeline (MLPRegressor (hidden_layer_sizes = (8 ,), max_iter = 1 , random_state = 0 ).fit (X , y ))
305+
306+ with TemporaryDirectory () as temp_dir :
307+ _dump_legacy_pipeline (temp_dir , mock_static_model , legacy_pipeline )
308+ downloaded_model = StaticModel .from_pretrained (temp_dir )
309+
310+ with (
311+ patch (
312+ "model2vec.inference.model.huggingface_hub.hf_hub_download" ,
313+ return_value = os .path .join (temp_dir , "pipeline.skops" ),
314+ ),
315+ patch (
316+ "model2vec.inference.model.StaticModel.from_pretrained" , return_value = downloaded_model
317+ ) as mock_from_pretrained ,
318+ ):
319+ convert_legacy_pipeline ("fake/repo-id" , token = "secret" )
320+
321+ assert mock_from_pretrained .call_args .kwargs .get ("token" ) == "secret"
322+
323+
281324def test_convert_legacy_pipeline_untrusted_type (mock_static_model : StaticModel ) -> None :
282325 """Test that an untrusted type in the legacy pipeline is rejected by default."""
283326 rng = np .random .RandomState (0 )
0 commit comments