Skip to content

Commit 119fda9

Browse files
committed
Add test for timeout
1 parent 656004e commit 119fda9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
"""Test for the Glances API client."""
2-

tests/test_timeout.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Test the interaction with the currencylayer API."""
2+
import pytest
3+
from pytest_httpx import HTTPXMock
4+
5+
from glances_api import Glances
6+
import httpx
7+
8+
9+
@pytest.mark.asyncio
10+
async def test_timeout(httpx_mock: HTTPXMock):
11+
"""Test if the connection is hitting the timeout."""
12+
13+
def raise_timeout(request, extensions: dict):
14+
"""Set the timeout for the requests."""
15+
raise httpx.ReadTimeout(
16+
f"Unable to read within {extensions['timeout']}", request=request
17+
)
18+
19+
httpx_mock.add_callback(raise_timeout)
20+
21+
with pytest.raises(httpx.ReadTimeout):
22+
client = Glances()
23+
await client.get_metrics("mem")

0 commit comments

Comments
 (0)