Skip to content

Commit

Permalink
test: ✅ Extend testing in Python 3.13+ (#109)
Browse files Browse the repository at this point in the history
* test: ✅ Extend testing in Python 3.13+

[Python 3.13 removed cgi module](https://docs.python.org/3.13/library/cgi.html),
which is used by httpx 0.23 and lower.
So we do not lower version with Python 3.13 and set higher requiremnts for Python 3.13+

* also test under python 3.14

* newer asyncio for newer python.
  • Loading branch information
zoido authored Jan 8, 2025
1 parent 1d8f6bf commit f79daf9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v4
Expand All @@ -19,6 +19,7 @@ jobs:
id: setup-python
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- uses: actions/cache@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/setup-python@v5
id: setup-python
with:
python-version: "3.10"
python-version: "3.13"

- uses: actions/cache@v4
with:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v4
Expand All @@ -19,6 +19,8 @@ jobs:
id: setup-python
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true


- uses: actions/cache@v4
with:
Expand Down
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ classifiers = [
"Topic :: Utilities",
]
dependencies = [
"httpx>=0.16",
"httpx>=0.16 ; python_version < '3.13'" ,
"httpx>=0.23 ; python_version >= '3.13'" ,
"tomli >= 1.1.0 ; python_version < '3.11'",
]
description = 'H2O Cloud Discovery Python CLient'
Expand All @@ -38,7 +39,11 @@ include = ["/src", "/tests", "CHANGELOG.md"]
packages = ["src/h2o_discovery"]

[[tool.hatch.envs.test.matrix]]
httpx = ["httpx0.16", "httpx0.21", "httpx0.22", "httpx0.23", "httpx0.24", "httpx0.25", "httpx0.26"]
httpx = ["httpx0.23", "httpx0.24", "httpx0.25", "httpx0.26", "httpx0.27", "httpx0.28"]
python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

[[tool.hatch.envs.test.matrix]]
httpx = ["httpx0.16", "httpx0.21", "httpx0.22"]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.test.overrides]
Expand All @@ -50,11 +55,14 @@ matrix.httpx.dependencies = [
{value = "httpx==0.24.*", if = ["httpx0.24"]},
{value = "httpx==0.25.*", if = ["httpx0.25"]},
{value = "httpx==0.26.*", if = ["httpx0.26"]},
{value = "httpx==0.27.*", if = ["httpx0.27"]},
{value = "httpx==0.28.*", if = ["httpx0.28"]},
]

[tool.hatch.envs.test]
dependencies = [
"pytest-asyncio==0.24.0",
"pytest-asyncio==0.24.0 ; python_version < '3.9'",
"pytest-asyncio==0.25.1 ;python_version >= '3.9'",
"pytest==8.3",
"respx>=0.16",
]
Expand Down
31 changes: 23 additions & 8 deletions tests/_internal/load/test_load_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from h2o_discovery._internal import load


@pytest.fixture()
def mock_client():
def mock_async_client():
client = mock.Mock()
client.get_environment.return_value = asyncio.Future()
client.get_environment.return_value.set_result(mock.Mock())
Expand All @@ -20,6 +19,16 @@ def mock_client():
return client


def mock_sync_client():
client = mock.Mock()
client.get_environment.return_value = {}
client.list_services.return_value = {}
client.list_clients.return_value = {}
client.list_clients.return_value = {}

return client


ENVIRONMENT_DATA = model.Environment(
h2o_cloud_environment="https://test.example.com",
h2o_cloud_platform_oauth2_scope="test-scope",
Expand All @@ -28,8 +37,9 @@ def mock_client():
)


def test_load_environment(mock_client):
def test_load_environment():
# Given
mock_client = mock_sync_client()
mock_client.get_environment.return_value = ENVIRONMENT_DATA

# When
Expand All @@ -40,8 +50,9 @@ def test_load_environment(mock_client):


@pytest.mark.asyncio
async def test_load_environment_async(mock_client):
async def test_load_environment_async():
# Given
mock_client = mock_async_client()
mock_client.get_environment.return_value = asyncio.Future()
mock_client.get_environment.return_value.set_result(ENVIRONMENT_DATA)

Expand All @@ -52,8 +63,9 @@ async def test_load_environment_async(mock_client):
assert discovery.environment == ENVIRONMENT_DATA


def test_load_services(mock_client):
def test_load_services():
# Given
mock_client = mock_sync_client()
mock_client.list_services.return_value = [SERVICE_RECORD]

# When
Expand All @@ -74,8 +86,9 @@ def test_load_services(mock_client):


@pytest.mark.asyncio
async def test_load_services_async(mock_client):
async def test_load_services_async():
# Given
mock_client = mock_async_client()
mock_client.list_services.return_value = asyncio.Future()
mock_client.list_services.return_value.set_result([SERVICE_RECORD])

Expand All @@ -93,8 +106,9 @@ async def test_load_services_async(mock_client):
)


def test_load_clients(mock_client):
def test_load_clients():
# Given
mock_client = mock_sync_client()
mock_client.list_clients.return_value = [CLIENT_RECORD]

# When
Expand All @@ -105,8 +119,9 @@ def test_load_clients(mock_client):


@pytest.mark.asyncio
async def test_load_clients_async(mock_client):
async def test_load_clients_async():
# Given
mock_client = mock_async_client()
mock_client.list_clients.return_value = asyncio.Future()
mock_client.list_clients.return_value.set_result([CLIENT_RECORD])

Expand Down

0 comments on commit f79daf9

Please sign in to comment.