|
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, 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 orb import Orb, AsyncOrb, APIResponseValidationError |
25 | 22 | from orb._types import Omit |
| 23 | +from orb._utils import asyncify |
26 | 24 | from orb._models import BaseModel, FinalRequestOptions |
27 | 25 | from orb._exceptions import OrbError, APIStatusError, APITimeoutError, APIResponseValidationError |
28 | 26 | from orb._base_client import ( |
29 | 27 | DEFAULT_TIMEOUT, |
30 | 28 | HTTPX_DEFAULT_TIMEOUT, |
31 | 29 | BaseClient, |
| 30 | + OtherPlatform, |
32 | 31 | DefaultHttpxClient, |
33 | 32 | DefaultAsyncHttpxClient, |
| 33 | + get_platform, |
34 | 34 | make_request_options, |
35 | 35 | ) |
36 | 36 |
|
@@ -1724,50 +1724,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: |
1724 | 1724 | assert response.retries_taken == failures_before_success |
1725 | 1725 | assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success |
1726 | 1726 |
|
1727 | | - def test_get_platform(self) -> None: |
1728 | | - # A previous implementation of asyncify could leave threads unterminated when |
1729 | | - # used with nest_asyncio. |
1730 | | - # |
1731 | | - # Since nest_asyncio.apply() is global and cannot be un-applied, this |
1732 | | - # test is run in a separate process to avoid affecting other tests. |
1733 | | - test_code = dedent(""" |
1734 | | - import asyncio |
1735 | | - import nest_asyncio |
1736 | | - import threading |
1737 | | -
|
1738 | | - from orb._utils import asyncify |
1739 | | - from orb._base_client import get_platform |
1740 | | -
|
1741 | | - async def test_main() -> None: |
1742 | | - result = await asyncify(get_platform)() |
1743 | | - print(result) |
1744 | | - for thread in threading.enumerate(): |
1745 | | - print(thread.name) |
1746 | | -
|
1747 | | - nest_asyncio.apply() |
1748 | | - asyncio.run(test_main()) |
1749 | | - """) |
1750 | | - with subprocess.Popen( |
1751 | | - [sys.executable, "-c", test_code], |
1752 | | - text=True, |
1753 | | - ) as process: |
1754 | | - timeout = 10 # seconds |
1755 | | - |
1756 | | - start_time = time.monotonic() |
1757 | | - while True: |
1758 | | - return_code = process.poll() |
1759 | | - if return_code is not None: |
1760 | | - if return_code != 0: |
1761 | | - raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code") |
1762 | | - |
1763 | | - # success |
1764 | | - break |
1765 | | - |
1766 | | - if time.monotonic() - start_time > timeout: |
1767 | | - process.kill() |
1768 | | - raise AssertionError("calling get_platform using asyncify resulted in a hung process") |
1769 | | - |
1770 | | - time.sleep(0.1) |
| 1727 | + async def test_get_platform(self) -> None: |
| 1728 | + platform = await asyncify(get_platform)() |
| 1729 | + assert isinstance(platform, (str, OtherPlatform)) |
1771 | 1730 |
|
1772 | 1731 | async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
1773 | 1732 | # Test that the proxy environment variables are set correctly |
|
0 commit comments