|
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 isaacus import Isaacus, AsyncIsaacus, APIResponseValidationError
|
25 | 22 | from isaacus._types import Omit
|
| 23 | +from isaacus._utils import asyncify |
26 | 24 | from isaacus._models import BaseModel, FinalRequestOptions
|
27 | 25 | from isaacus._exceptions import IsaacusError, APIStatusError, APITimeoutError, APIResponseValidationError
|
28 | 26 | from isaacus._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 |
|
@@ -1669,50 +1669,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
|
1669 | 1669 |
|
1670 | 1670 | assert response.http_request.headers.get("x-stainless-retry-count") == "42"
|
1671 | 1671 |
|
1672 |
| - def test_get_platform(self) -> None: |
1673 |
| - # A previous implementation of asyncify could leave threads unterminated when |
1674 |
| - # used with nest_asyncio. |
1675 |
| - # |
1676 |
| - # Since nest_asyncio.apply() is global and cannot be un-applied, this |
1677 |
| - # test is run in a separate process to avoid affecting other tests. |
1678 |
| - test_code = dedent(""" |
1679 |
| - import asyncio |
1680 |
| - import nest_asyncio |
1681 |
| - import threading |
1682 |
| -
|
1683 |
| - from isaacus._utils import asyncify |
1684 |
| - from isaacus._base_client import get_platform |
1685 |
| -
|
1686 |
| - async def test_main() -> None: |
1687 |
| - result = await asyncify(get_platform)() |
1688 |
| - print(result) |
1689 |
| - for thread in threading.enumerate(): |
1690 |
| - print(thread.name) |
1691 |
| -
|
1692 |
| - nest_asyncio.apply() |
1693 |
| - asyncio.run(test_main()) |
1694 |
| - """) |
1695 |
| - with subprocess.Popen( |
1696 |
| - [sys.executable, "-c", test_code], |
1697 |
| - text=True, |
1698 |
| - ) as process: |
1699 |
| - timeout = 10 # seconds |
1700 |
| - |
1701 |
| - start_time = time.monotonic() |
1702 |
| - while True: |
1703 |
| - return_code = process.poll() |
1704 |
| - if return_code is not None: |
1705 |
| - if return_code != 0: |
1706 |
| - raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code") |
1707 |
| - |
1708 |
| - # success |
1709 |
| - break |
1710 |
| - |
1711 |
| - if time.monotonic() - start_time > timeout: |
1712 |
| - process.kill() |
1713 |
| - raise AssertionError("calling get_platform using asyncify resulted in a hung process") |
1714 |
| - |
1715 |
| - time.sleep(0.1) |
| 1672 | + async def test_get_platform(self) -> None: |
| 1673 | + platform = await asyncify(get_platform)() |
| 1674 | + assert isinstance(platform, (str, OtherPlatform)) |
1716 | 1675 |
|
1717 | 1676 | async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
1718 | 1677 | # Test that the proxy environment variables are set correctly
|
|
0 commit comments