mirror of
https://github.com/anomalyco/opencode-sdk-python.git
synced 2026-05-19 16:41:02 +00:00
chore(tests): simplify get_platform test
`nest_asyncio` is archived and broken on some platforms so it's not worth keeping in our test suite.
This commit is contained in:
parent
273dffa4ac
commit
0a47e601d1
3 changed files with 6 additions and 49 deletions
|
|
@ -56,7 +56,6 @@ dev-dependencies = [
|
||||||
"dirty-equals>=0.6.0",
|
"dirty-equals>=0.6.0",
|
||||||
"importlib-metadata>=6.7.0",
|
"importlib-metadata>=6.7.0",
|
||||||
"rich>=13.7.1",
|
"rich>=13.7.1",
|
||||||
"nest_asyncio==1.6.0",
|
|
||||||
"pytest-xdist>=3.6.1",
|
"pytest-xdist>=3.6.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ multidict==6.4.4
|
||||||
mypy==1.14.1
|
mypy==1.14.1
|
||||||
mypy-extensions==1.0.0
|
mypy-extensions==1.0.0
|
||||||
# via mypy
|
# via mypy
|
||||||
nest-asyncio==1.6.0
|
|
||||||
nodeenv==1.8.0
|
nodeenv==1.8.0
|
||||||
# via pyright
|
# via pyright
|
||||||
nox==2023.4.22
|
nox==2023.4.22
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,10 @@ import gc
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
import subprocess
|
|
||||||
import tracemalloc
|
import tracemalloc
|
||||||
from typing import Any, Union, cast
|
from typing import Any, Union, cast
|
||||||
from textwrap import dedent
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from typing_extensions import Literal
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
|
@ -23,6 +20,7 @@ from pydantic import ValidationError
|
||||||
|
|
||||||
from opencode_ai import Opencode, AsyncOpencode, APIResponseValidationError
|
from opencode_ai import Opencode, AsyncOpencode, APIResponseValidationError
|
||||||
from opencode_ai._types import Omit
|
from opencode_ai._types import Omit
|
||||||
|
from opencode_ai._utils import asyncify
|
||||||
from opencode_ai._models import BaseModel, FinalRequestOptions
|
from opencode_ai._models import BaseModel, FinalRequestOptions
|
||||||
from opencode_ai._streaming import Stream, AsyncStream
|
from opencode_ai._streaming import Stream, AsyncStream
|
||||||
from opencode_ai._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
|
from opencode_ai._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
|
||||||
|
|
@ -30,8 +28,10 @@ from opencode_ai._base_client import (
|
||||||
DEFAULT_TIMEOUT,
|
DEFAULT_TIMEOUT,
|
||||||
HTTPX_DEFAULT_TIMEOUT,
|
HTTPX_DEFAULT_TIMEOUT,
|
||||||
BaseClient,
|
BaseClient,
|
||||||
|
OtherPlatform,
|
||||||
DefaultHttpxClient,
|
DefaultHttpxClient,
|
||||||
DefaultAsyncHttpxClient,
|
DefaultAsyncHttpxClient,
|
||||||
|
get_platform,
|
||||||
make_request_options,
|
make_request_options,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1566,50 +1566,9 @@ class TestAsyncOpencode:
|
||||||
|
|
||||||
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
|
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
|
||||||
|
|
||||||
def test_get_platform(self) -> None:
|
async def test_get_platform(self) -> None:
|
||||||
# A previous implementation of asyncify could leave threads unterminated when
|
platform = await asyncify(get_platform)()
|
||||||
# used with nest_asyncio.
|
assert isinstance(platform, (str, OtherPlatform))
|
||||||
#
|
|
||||||
# Since nest_asyncio.apply() is global and cannot be un-applied, this
|
|
||||||
# test is run in a separate process to avoid affecting other tests.
|
|
||||||
test_code = dedent("""
|
|
||||||
import asyncio
|
|
||||||
import nest_asyncio
|
|
||||||
import threading
|
|
||||||
|
|
||||||
from opencode_ai._utils import asyncify
|
|
||||||
from opencode_ai._base_client import get_platform
|
|
||||||
|
|
||||||
async def test_main() -> None:
|
|
||||||
result = await asyncify(get_platform)()
|
|
||||||
print(result)
|
|
||||||
for thread in threading.enumerate():
|
|
||||||
print(thread.name)
|
|
||||||
|
|
||||||
nest_asyncio.apply()
|
|
||||||
asyncio.run(test_main())
|
|
||||||
""")
|
|
||||||
with subprocess.Popen(
|
|
||||||
[sys.executable, "-c", test_code],
|
|
||||||
text=True,
|
|
||||||
) as process:
|
|
||||||
timeout = 10 # seconds
|
|
||||||
|
|
||||||
start_time = time.monotonic()
|
|
||||||
while True:
|
|
||||||
return_code = process.poll()
|
|
||||||
if return_code is not None:
|
|
||||||
if return_code != 0:
|
|
||||||
raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
|
|
||||||
|
|
||||||
# success
|
|
||||||
break
|
|
||||||
|
|
||||||
if time.monotonic() - start_time > timeout:
|
|
||||||
process.kill()
|
|
||||||
raise AssertionError("calling get_platform using asyncify resulted in a hung process")
|
|
||||||
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
# Test that the proxy environment variables are set correctly
|
# Test that the proxy environment variables are set correctly
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue