|
6 | 6 | import os
|
7 | 7 | import sys
|
8 | 8 | import json
|
9 |
| -import time |
10 | 9 | import asyncio
|
11 | 10 | import inspect
|
12 |
| -import subprocess |
13 | 11 | import tracemalloc
|
14 | 12 | from typing import Any, Union, Protocol, cast
|
15 |
| -from textwrap import dedent |
16 | 13 | from unittest import mock
|
17 | 14 | from typing_extensions import Literal
|
18 | 15 |
|
|
23 | 20 |
|
24 | 21 | from openai import OpenAI, AsyncOpenAI, APIResponseValidationError
|
25 | 22 | from openai._types import Omit
|
| 23 | +from openai._utils import asyncify |
26 | 24 | from openai._models import BaseModel, FinalRequestOptions
|
27 | 25 | from openai._streaming import Stream, AsyncStream
|
28 | 26 | from openai._exceptions import OpenAIError, APIStatusError, APITimeoutError, APIResponseValidationError
|
29 | 27 | from openai._base_client import (
|
30 | 28 | DEFAULT_TIMEOUT,
|
31 | 29 | HTTPX_DEFAULT_TIMEOUT,
|
32 | 30 | BaseClient,
|
| 31 | + OtherPlatform, |
33 | 32 | DefaultHttpxClient,
|
34 | 33 | DefaultAsyncHttpxClient,
|
| 34 | + get_platform, |
35 | 35 | make_request_options,
|
36 | 36 | )
|
37 | 37 |
|
@@ -1857,50 +1857,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
|
1857 | 1857 | assert response.retries_taken == failures_before_success
|
1858 | 1858 | assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
|
1859 | 1859 |
|
1860 |
| - def test_get_platform(self) -> None: |
1861 |
| - # A previous implementation of asyncify could leave threads unterminated when |
1862 |
| - # used with nest_asyncio. |
1863 |
| - # |
1864 |
| - # Since nest_asyncio.apply() is global and cannot be un-applied, this |
1865 |
| - # test is run in a separate process to avoid affecting other tests. |
1866 |
| - test_code = dedent(""" |
1867 |
| - import asyncio |
1868 |
| - import nest_asyncio |
1869 |
| - import threading |
1870 |
| -
|
1871 |
| - from openai._utils import asyncify |
1872 |
| - from openai._base_client import get_platform |
1873 |
| -
|
1874 |
| - async def test_main() -> None: |
1875 |
| - result = await asyncify(get_platform)() |
1876 |
| - print(result) |
1877 |
| - for thread in threading.enumerate(): |
1878 |
| - print(thread.name) |
1879 |
| -
|
1880 |
| - nest_asyncio.apply() |
1881 |
| - asyncio.run(test_main()) |
1882 |
| - """) |
1883 |
| - with subprocess.Popen( |
1884 |
| - [sys.executable, "-c", test_code], |
1885 |
| - text=True, |
1886 |
| - ) as process: |
1887 |
| - timeout = 10 # seconds |
1888 |
| - |
1889 |
| - start_time = time.monotonic() |
1890 |
| - while True: |
1891 |
| - return_code = process.poll() |
1892 |
| - if return_code is not None: |
1893 |
| - if return_code != 0: |
1894 |
| - raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code") |
1895 |
| - |
1896 |
| - # success |
1897 |
| - break |
1898 |
| - |
1899 |
| - if time.monotonic() - start_time > timeout: |
1900 |
| - process.kill() |
1901 |
| - raise AssertionError("calling get_platform using asyncify resulted in a hung process") |
1902 |
| - |
1903 |
| - time.sleep(0.1) |
| 1860 | + async def test_get_platform(self) -> None: |
| 1861 | + platform = await asyncify(get_platform)() |
| 1862 | + assert isinstance(platform, (str, OtherPlatform)) |
1904 | 1863 |
|
1905 | 1864 | async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
1906 | 1865 | # Test that the proxy environment variables are set correctly
|
|
0 commit comments