Skip to content
Open
Prev Previous commit
Next Next commit
test: make file URI tests cross-platform
  • Loading branch information
CompilError-bts committed Mar 31, 2026
commit a844133e56a4f7acdb24a8a6632f87211e50c5ff
22 changes: 12 additions & 10 deletions tests/test_openai_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from types import SimpleNamespace
from pathlib import Path
from urllib.parse import urlparse, urlunparse

import pytest
from openai.types.chat.chat_completion import ChatCompletion
Expand Down Expand Up @@ -888,9 +890,8 @@ async def test_prepare_chat_payload_materializes_context_file_uri_image_urls(tmp
async def test_file_uri_to_path_preserves_windows_drive_letter():
provider = _make_provider()
try:
assert provider._file_uri_to_path("file:///C:/tmp/quoted-image.png") == (
"C:/tmp/quoted-image.png"
)
resolved = provider._file_uri_to_path("file:///C:/tmp/quoted-image.png")
assert Path(resolved) == Path("C:/tmp/quoted-image.png")
finally:
await provider.terminate()

Expand All @@ -899,9 +900,8 @@ async def test_file_uri_to_path_preserves_windows_drive_letter():
async def test_file_uri_to_path_preserves_windows_netloc_drive_letter():
provider = _make_provider()
try:
assert provider._file_uri_to_path("file://C:/tmp/quoted-image.png") == (
"C:/tmp/quoted-image.png"
)
resolved = provider._file_uri_to_path("file://C:/tmp/quoted-image.png")
assert Path(resolved) == Path("C:/tmp/quoted-image.png")
finally:
await provider.terminate()

Expand All @@ -910,9 +910,8 @@ async def test_file_uri_to_path_preserves_windows_netloc_drive_letter():
async def test_file_uri_to_path_preserves_remote_netloc_as_unc_path():
provider = _make_provider()
try:
assert provider._file_uri_to_path("file://server/share/quoted-image.png") == (
"//server/share/quoted-image.png"
)
resolved = provider._file_uri_to_path("file://server/share/quoted-image.png")
assert Path(resolved) == Path("//server/share/quoted-image.png")
finally:
await provider.terminate()

Expand Down Expand Up @@ -1083,7 +1082,10 @@ async def test_prepare_chat_payload_materializes_context_localhost_file_uri_imag
image_path = tmp_path / "quoted-image.png"
PILImage.new("RGBA", (1, 1), (255, 0, 0, 255)).save(image_path)

localhost_uri = f"file://localhost{image_path.as_posix()}"
parsed_local_uri = urlparse(image_path.as_uri())
localhost_uri = urlunparse(
("file", "localhost", parsed_local_uri.path, "", "", "")
)
payloads, _ = await provider._prepare_chat_payload(
prompt=None,
contexts=[
Expand Down