mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-03 12:52:35 +00:00
fix tests
This commit is contained in:
+46
-8
@@ -267,11 +267,14 @@ def test_client_pull_stream(httpserver: HTTPServer):
|
|||||||
'insecure': False,
|
'insecure': False,
|
||||||
'stream': True,
|
'stream': True,
|
||||||
},
|
},
|
||||||
).respond_with_json({})
|
).respond_with_handler(stream_handler)
|
||||||
|
|
||||||
client = Client(httpserver.url_for('/'))
|
client = Client(httpserver.url_for('/'))
|
||||||
response = client.pull('dummy', stream=True)
|
response = client.pull('dummy', stream=True)
|
||||||
assert isinstance(response, types.GeneratorType)
|
|
||||||
|
it = iter(['pulling manifest', 'verifying sha256 digest', 'writing manifest', 'removing any unused layers', 'success'])
|
||||||
|
for part in response:
|
||||||
|
assert part['status'] == next(it)
|
||||||
|
|
||||||
|
|
||||||
def test_client_push(httpserver: HTTPServer):
|
def test_client_push(httpserver: HTTPServer):
|
||||||
@@ -291,6 +294,14 @@ def test_client_push(httpserver: HTTPServer):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_push_stream(httpserver: HTTPServer):
|
def test_client_push_stream(httpserver: HTTPServer):
|
||||||
|
def stream_handler(_: Request):
|
||||||
|
def generate():
|
||||||
|
yield json.dumps({'status': 'retrieving manifest'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'pushing manifest'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'success'}) + '\n'
|
||||||
|
|
||||||
|
return Response(generate())
|
||||||
|
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/push',
|
'/api/push',
|
||||||
method='POST',
|
method='POST',
|
||||||
@@ -299,11 +310,14 @@ def test_client_push_stream(httpserver: HTTPServer):
|
|||||||
'insecure': False,
|
'insecure': False,
|
||||||
'stream': True,
|
'stream': True,
|
||||||
},
|
},
|
||||||
).respond_with_json({})
|
).respond_with_handler(stream_handler)
|
||||||
|
|
||||||
client = Client(httpserver.url_for('/'))
|
client = Client(httpserver.url_for('/'))
|
||||||
response = client.push('dummy', stream=True)
|
response = client.push('dummy', stream=True)
|
||||||
assert isinstance(response, types.GeneratorType)
|
|
||||||
|
it = iter(['retrieving manifest', 'pushing manifest', 'success'])
|
||||||
|
for part in response:
|
||||||
|
assert part['status'] == next(it)
|
||||||
|
|
||||||
|
|
||||||
def test_client_create_path(httpserver: HTTPServer):
|
def test_client_create_path(httpserver: HTTPServer):
|
||||||
@@ -642,6 +656,16 @@ async def test_async_client_pull(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_pull_stream(httpserver: HTTPServer):
|
async def test_async_client_pull_stream(httpserver: HTTPServer):
|
||||||
|
def stream_handler(_: Request):
|
||||||
|
def generate():
|
||||||
|
yield json.dumps({'status': 'pulling manifest'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'verifying sha256 digest'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'writing manifest'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'removing any unused layers'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'success'}) + '\n'
|
||||||
|
|
||||||
|
return Response(generate())
|
||||||
|
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/pull',
|
'/api/pull',
|
||||||
method='POST',
|
method='POST',
|
||||||
@@ -650,11 +674,14 @@ async def test_async_client_pull_stream(httpserver: HTTPServer):
|
|||||||
'insecure': False,
|
'insecure': False,
|
||||||
'stream': True,
|
'stream': True,
|
||||||
},
|
},
|
||||||
).respond_with_json({})
|
).respond_with_handler(stream_handler)
|
||||||
|
|
||||||
client = AsyncClient(httpserver.url_for('/'))
|
client = AsyncClient(httpserver.url_for('/'))
|
||||||
response = await client.pull('dummy', stream=True)
|
response = await client.pull('dummy', stream=True)
|
||||||
assert isinstance(response, types.AsyncGeneratorType)
|
|
||||||
|
it = iter(['pulling manifest', 'verifying sha256 digest', 'writing manifest', 'removing any unused layers', 'success'])
|
||||||
|
async for part in response:
|
||||||
|
assert part['status'] == next(it)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -676,6 +703,14 @@ async def test_async_client_push(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_push_stream(httpserver: HTTPServer):
|
async def test_async_client_push_stream(httpserver: HTTPServer):
|
||||||
|
def stream_handler(_: Request):
|
||||||
|
def generate():
|
||||||
|
yield json.dumps({'status': 'retrieving manifest'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'pushing manifest'}) + '\n'
|
||||||
|
yield json.dumps({'status': 'success'}) + '\n'
|
||||||
|
|
||||||
|
return Response(generate())
|
||||||
|
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/push',
|
'/api/push',
|
||||||
method='POST',
|
method='POST',
|
||||||
@@ -684,11 +719,14 @@ async def test_async_client_push_stream(httpserver: HTTPServer):
|
|||||||
'insecure': False,
|
'insecure': False,
|
||||||
'stream': True,
|
'stream': True,
|
||||||
},
|
},
|
||||||
).respond_with_json({})
|
).respond_with_handler(stream_handler)
|
||||||
|
|
||||||
client = AsyncClient(httpserver.url_for('/'))
|
client = AsyncClient(httpserver.url_for('/'))
|
||||||
response = await client.push('dummy', stream=True)
|
response = await client.push('dummy', stream=True)
|
||||||
assert isinstance(response, types.AsyncGeneratorType)
|
|
||||||
|
it = iter(['retrieving manifest', 'pushing manifest', 'success'])
|
||||||
|
async for part in response:
|
||||||
|
assert part['status'] == next(it)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Reference in New Issue
Block a user