From f79daf95c09486a2535c2d6ae7487868a8c1c59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Pokorn=C3=BD?= Date: Wed, 8 Jan 2025 14:36:36 +0100 Subject: [PATCH] =?UTF-8?q?test:=20=E2=9C=85=20Extend=20testing=20in=20Pyt?= =?UTF-8?q?hon=203.13+=20=20(#109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- .github/workflows/python-build.yml | 3 +- .github/workflows/python-lint.yml | 2 +- .github/workflows/python-test.yml | 4 ++- pyproject.toml | 14 ++++++++-- tests/_internal/load/test_load_discovery.py | 31 +++++++++++++++------ 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index 3418367..c3ee493 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -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 @@ -19,6 +19,7 @@ jobs: id: setup-python with: python-version: ${{ matrix.python-version }} + allow-prereleases: true - uses: actions/cache@v4 with: diff --git a/.github/workflows/python-lint.yml b/.github/workflows/python-lint.yml index 06757f7..c7ea228 100644 --- a/.github/workflows/python-lint.yml +++ b/.github/workflows/python-lint.yml @@ -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: diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 2d18d7c..92384e8 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -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 @@ -19,6 +19,8 @@ jobs: id: setup-python with: python-version: ${{ matrix.python-version }} + allow-prereleases: true + - uses: actions/cache@v4 with: diff --git a/pyproject.toml b/pyproject.toml index 4426c2d..2538c47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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' @@ -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] @@ -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", ] diff --git a/tests/_internal/load/test_load_discovery.py b/tests/_internal/load/test_load_discovery.py index 3eb533f..83e031c 100644 --- a/tests/_internal/load/test_load_discovery.py +++ b/tests/_internal/load/test_load_discovery.py @@ -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()) @@ -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", @@ -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 @@ -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) @@ -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 @@ -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]) @@ -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 @@ -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])