| 
									
										
										
										
											2024-01-12 12:34:01 +08:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2024-01-12 12:34:01 +08:00
										 |  |  | from _pytest.monkeypatch import MonkeyPatch | 
					
						
							|  |  |  | from huggingface_hub import InferenceClient | 
					
						
							| 
									
										
										
										
											2024-04-18 20:24:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-12 12:34:01 +08:00
										 |  |  | from tests.integration_tests.model_runtime.__mock.huggingface_chat import MockHuggingfaceChatClass | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | MOCK = os.getenv('MOCK_SWITCH', 'false').lower() == 'true' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture | 
					
						
							|  |  |  | def setup_huggingface_mock(request, monkeypatch: MonkeyPatch): | 
					
						
							|  |  |  |     if MOCK: | 
					
						
							|  |  |  |         monkeypatch.setattr(InferenceClient, "text_generation", MockHuggingfaceChatClass.text_generation) | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     yield | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if MOCK: | 
					
						
							|  |  |  |         monkeypatch.undo() |