|
9 | 9 | from pytest_httpserver import HTTPServer, URIPattern |
10 | 10 | from werkzeug.wrappers import Request, Response |
11 | 11 |
|
12 | | -from ollama._client import AsyncClient, Client, _copy_tools |
| 12 | +from ollama._client import CONNECTION_ERROR_MESSAGE, AsyncClient, Client, _copy_tools |
13 | 13 |
|
14 | 14 | PNG_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNgYGAAAAAEAAH2FzhVAAAAAElFTkSuQmCC' |
15 | 15 | PNG_BYTES = base64.b64decode(PNG_BASE64) |
@@ -1116,15 +1116,15 @@ def test_tool_validation(): |
1116 | 1116 |
|
1117 | 1117 | def test_client_connection_error(): |
1118 | 1118 | client = Client('http://localhost:1234') |
1119 | | - with pytest.raises(ConnectionError) as exc_info: |
| 1119 | + |
| 1120 | + with pytest.raises(ConnectionError, match=CONNECTION_ERROR_MESSAGE): |
1120 | 1121 | client.chat('model', messages=[{'role': 'user', 'content': 'prompt'}]) |
1121 | | - assert str(exc_info.value) == 'Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download' |
1122 | | - with pytest.raises(ConnectionError) as exc_info: |
| 1122 | + with pytest.raises(ConnectionError, match=CONNECTION_ERROR_MESSAGE): |
| 1123 | + client.chat('model', messages=[{'role': 'user', 'content': 'prompt'}]) |
| 1124 | + with pytest.raises(ConnectionError, match=CONNECTION_ERROR_MESSAGE): |
1123 | 1125 | client.generate('model', 'prompt') |
1124 | | - assert str(exc_info.value) == 'Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download' |
1125 | | - with pytest.raises(ConnectionError) as exc_info: |
| 1126 | + with pytest.raises(ConnectionError, match=CONNECTION_ERROR_MESSAGE): |
1126 | 1127 | client.show('model') |
1127 | | - assert str(exc_info.value) == 'Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download' |
1128 | 1128 |
|
1129 | 1129 |
|
1130 | 1130 | @pytest.mark.asyncio |
|
0 commit comments