|
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 conductor import Conductor, AsyncConductor, APIResponseValidationError |
25 | 22 | from conductor._types import Omit |
| 23 | +from conductor._utils import asyncify |
26 | 24 | from conductor._models import BaseModel, FinalRequestOptions |
27 | 25 | from conductor._exceptions import APIStatusError, ConductorError, APIResponseValidationError |
28 | 26 | from conductor._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 |
|
@@ -1587,50 +1587,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: |
1587 | 1587 |
|
1588 | 1588 | assert response.http_request.headers.get("x-stainless-retry-count") == "42" |
1589 | 1589 |
|
1590 | | - def test_get_platform(self) -> None: |
1591 | | - # A previous implementation of asyncify could leave threads unterminated when |
1592 | | - # used with nest_asyncio. |
1593 | | - # |
1594 | | - # Since nest_asyncio.apply() is global and cannot be un-applied, this |
1595 | | - # test is run in a separate process to avoid affecting other tests. |
1596 | | - test_code = dedent(""" |
1597 | | - import asyncio |
1598 | | - import nest_asyncio |
1599 | | - import threading |
1600 | | -
|
1601 | | - from conductor._utils import asyncify |
1602 | | - from conductor._base_client import get_platform |
1603 | | -
|
1604 | | - async def test_main() -> None: |
1605 | | - result = await asyncify(get_platform)() |
1606 | | - print(result) |
1607 | | - for thread in threading.enumerate(): |
1608 | | - print(thread.name) |
1609 | | -
|
1610 | | - nest_asyncio.apply() |
1611 | | - asyncio.run(test_main()) |
1612 | | - """) |
1613 | | - with subprocess.Popen( |
1614 | | - [sys.executable, "-c", test_code], |
1615 | | - text=True, |
1616 | | - ) as process: |
1617 | | - timeout = 10 # seconds |
1618 | | - |
1619 | | - start_time = time.monotonic() |
1620 | | - while True: |
1621 | | - return_code = process.poll() |
1622 | | - if return_code is not None: |
1623 | | - if return_code != 0: |
1624 | | - raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code") |
1625 | | - |
1626 | | - # success |
1627 | | - break |
1628 | | - |
1629 | | - if time.monotonic() - start_time > timeout: |
1630 | | - process.kill() |
1631 | | - raise AssertionError("calling get_platform using asyncify resulted in a hung process") |
1632 | | - |
1633 | | - time.sleep(0.1) |
| 1590 | + async def test_get_platform(self) -> None: |
| 1591 | + platform = await asyncify(get_platform)() |
| 1592 | + assert isinstance(platform, (str, OtherPlatform)) |
1634 | 1593 |
|
1635 | 1594 | async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
1636 | 1595 | # Test that the proxy environment variables are set correctly |
|
0 commit comments