|
1 | 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
| 4 | +from typing import TYPE_CHECKING |
| 5 | + |
4 | 6 | import pytest |
5 | 7 | from smithy_core.aio.interfaces import ErrorInfo |
6 | 8 |
|
| 9 | +if TYPE_CHECKING: |
| 10 | + from smithy_http.aio.aiohttp import AIOHTTPClient |
| 11 | + from smithy_http.aio.crt import AWSCRTHTTPClient |
| 12 | + |
7 | 13 | try: |
8 | 14 | from smithy_http.aio.aiohttp import AIOHTTPClient |
9 | 15 |
|
10 | | - HAS_AIOHTTP = True |
| 16 | + has_aiohttp = True |
11 | 17 | except ImportError: |
12 | | - HAS_AIOHTTP = False |
| 18 | + has_aiohttp = False |
13 | 19 |
|
14 | 20 | try: |
15 | 21 | from smithy_http.aio.crt import AWSCRTHTTPClient |
16 | 22 |
|
17 | | - HAS_CRT = True |
| 23 | + has_crt = True |
18 | 24 | except ImportError: |
19 | | - HAS_CRT = False |
| 25 | + has_crt = False |
20 | 26 |
|
21 | 27 |
|
22 | | -@pytest.mark.skipif(not HAS_AIOHTTP, reason="aiohttp not available") |
| 28 | +@pytest.mark.skipif(not has_aiohttp, reason="aiohttp not available") |
23 | 29 | class TestAIOHTTPTimeoutErrorHandling: |
24 | 30 | """Test timeout error handling for AIOHTTPClient.""" |
25 | 31 |
|
26 | 32 | @pytest.fixture |
27 | | - async def client(self): |
| 33 | + async def client(self) -> "AIOHTTPClient": |
28 | 34 | return AIOHTTPClient() |
29 | 35 |
|
30 | 36 | @pytest.mark.asyncio |
31 | | - async def test_timeout_error_detection(self, client): |
| 37 | + async def test_timeout_error_detection(self, client: "AIOHTTPClient") -> None: |
32 | 38 | """Test timeout error detection for standard TimeoutError.""" |
33 | 39 | timeout_err = TimeoutError("Connection timed out") |
34 | 40 | result = client.get_error_info(timeout_err) |
35 | 41 | assert result == ErrorInfo(is_timeout_error=True, fault="client") |
36 | 42 |
|
37 | 43 | @pytest.mark.asyncio |
38 | | - async def test_non_timeout_error_detection(self, client): |
| 44 | + async def test_non_timeout_error_detection(self, client: "AIOHTTPClient") -> None: |
39 | 45 | """Test non-timeout error detection.""" |
40 | 46 | other_err = ValueError("Not a timeout") |
41 | 47 | result = client.get_error_info(other_err) |
42 | 48 | assert result == ErrorInfo(is_timeout_error=False, fault="client") |
43 | 49 |
|
44 | 50 |
|
45 | | -@pytest.mark.skipif(not HAS_CRT, reason="AWS CRT not available") |
| 51 | +@pytest.mark.skipif(not has_crt, reason="AWS CRT not available") |
46 | 52 | class TestAWSCRTTimeoutErrorHandling: |
47 | 53 | """Test timeout error handling for AWSCRTHTTPClient.""" |
48 | 54 |
|
49 | 55 | @pytest.fixture |
50 | | - def client(self): |
| 56 | + def client(self) -> "AWSCRTHTTPClient": |
51 | 57 | return AWSCRTHTTPClient() |
52 | 58 |
|
53 | | - def test_timeout_error_detection(self, client): |
| 59 | + def test_timeout_error_detection(self, client: "AWSCRTHTTPClient") -> None: |
54 | 60 | """Test timeout error detection for standard TimeoutError.""" |
55 | 61 | timeout_err = TimeoutError("Connection timed out") |
56 | 62 | result = client.get_error_info(timeout_err) |
57 | 63 | assert result == ErrorInfo(is_timeout_error=True, fault="client") |
58 | 64 |
|
59 | | - def test_non_timeout_error_detection(self, client): |
| 65 | + def test_non_timeout_error_detection(self, client: "AWSCRTHTTPClient") -> None: |
60 | 66 | """Test non-timeout error detection.""" |
61 | 67 | other_err = ValueError("Not a timeout") |
62 | 68 | result = client.get_error_info(other_err) |
|
0 commit comments