Skip to content

Commit 5779bed

Browse files
committed
Adjust tests for Python 3.9
1 parent 62f4978 commit 5779bed

File tree

8 files changed

+53
-10
lines changed

8 files changed

+53
-10
lines changed

infrahub_sdk/data.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
4-
53
from pydantic import BaseModel, ConfigDict, Field
64

7-
if TYPE_CHECKING:
8-
from .node import InfrahubNode
5+
from .node import InfrahubNode # noqa: TCH001
96

107

118
class RepositoryBranchInfo(BaseModel):

poetry.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ toml = { version = "^0.10", optional = true }
5050
typer = { version = "^0.12.3", optional = true }
5151
pytest = { version = "*", optional = true }
5252
pyyaml = { version = "^6", optional = true }
53+
eval-type-backport = { version = "^0.2.2", python = "~3.9" }
5354

5455
[tool.poetry.group.dev.dependencies]
5556
pytest = "*"

tests/unit/ctl/test_cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
import sys
2+
3+
import pytest
14
from typer.testing import CliRunner
25

36
from infrahub_sdk.ctl.cli import app
47

58
runner = CliRunner()
69

10+
requires_python_310 = pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10 or higher")
11+
712

13+
@requires_python_310
814
def test_main_app():
915
result = runner.invoke(app, ["--help"])
1016
assert result.exit_code == 0

tests/unit/ctl/test_repository_app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Integration tests for infrahubctl commands."""
22

3+
import sys
34
from unittest import mock
45

56
import pytest
@@ -10,6 +11,8 @@
1011

1112
runner = CliRunner()
1213

14+
requires_python_310 = pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10 or higher")
15+
1316

1417
@pytest.fixture
1518
def mock_client() -> mock.Mock:
@@ -25,6 +28,7 @@ def mock_client() -> mock.Mock:
2528
class TestInfrahubctlRepository:
2629
"""Groups the 'infrahubctl repository' test cases."""
2730

31+
@requires_python_310
2832
def test_repo_no_username(self, mock_init_client, mock_client) -> None:
2933
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
3034
mock_cred = mock.AsyncMock()
@@ -84,6 +88,7 @@ def test_repo_no_username(self, mock_init_client, mock_client) -> None:
8488
tracker="mutation-repository-create",
8589
)
8690

91+
@requires_python_310
8792
def test_repo_username(self, mock_init_client, mock_client) -> None:
8893
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
8994
mock_cred = mock.AsyncMock()
@@ -145,6 +150,7 @@ def test_repo_username(self, mock_init_client, mock_client) -> None:
145150
tracker="mutation-repository-create",
146151
)
147152

153+
@requires_python_310
148154
def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
149155
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
150156
mock_cred = mock.AsyncMock()
@@ -205,6 +211,7 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
205211
tracker="mutation-repository-create",
206212
)
207213

214+
@requires_python_310
208215
def test_repo_description_commit_branch(self, mock_init_client, mock_client) -> None:
209216
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
210217
mock_cred = mock.AsyncMock()

tests/unit/ctl/test_transform_app.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
Path(os.path.abspath(__file__)).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl"
2323
)
2424

25+
requires_python_310 = pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10 or higher")
26+
2527

2628
def read_fixture(file_name: str, fixture_subdir: str = ".") -> str:
2729
"""Read the contents of a fixture."""
@@ -57,6 +59,7 @@ class TestInfrahubctlTransform:
5759
"""Groups the 'infrahubctl transform' test cases."""
5860

5961
@staticmethod
62+
@requires_python_310
6063
def test_transform_not_exist_in_infrahub_yml(tags_transform_dir: str) -> None:
6164
"""Case transform is not specified in the infrahub.yml file."""
6265
transform_name = "not_existing_transform"
@@ -66,7 +69,7 @@ def test_transform_not_exist_in_infrahub_yml(tags_transform_dir: str) -> None:
6669
assert output.exit_code == 1
6770

6871
@staticmethod
69-
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
72+
@requires_python_310
7073
def test_transform_python_file_not_defined(tags_transform_dir: str) -> None:
7174
"""Case transform python file not defined."""
7275
# Remove transform file
@@ -81,7 +84,7 @@ def test_transform_python_file_not_defined(tags_transform_dir: str) -> None:
8184
assert output.exit_code == 1
8285

8386
@staticmethod
84-
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
87+
@requires_python_310
8588
def test_transform_python_class_not_defined(tags_transform_dir: str) -> None:
8689
"""Case transform python class not defined."""
8790
# Rename transform inside of python file so the class name searched for no longer exists
@@ -101,7 +104,7 @@ def test_transform_python_class_not_defined(tags_transform_dir: str) -> None:
101104
assert output.exit_code == 1
102105

103106
@staticmethod
104-
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
107+
@requires_python_310
105108
def test_gql_query_not_defined(tags_transform_dir: str) -> None:
106109
"""Case GraphQL Query is not defined"""
107110
# Remove GraphQL Query file
@@ -115,7 +118,7 @@ def test_gql_query_not_defined(tags_transform_dir: str) -> None:
115118
assert output.exit_code == 1
116119

117120
@staticmethod
118-
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
121+
@requires_python_310
119122
def test_infrahubctl_transform_cmd_success(httpx_mock: HTTPXMock, tags_transform_dir: str) -> None:
120123
"""Case infrahubctl transform command executes successfully"""
121124
httpx_mock.add_response(

tests/unit/ctl/test_validate_app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24
from typer.testing import CliRunner
35

@@ -7,7 +9,10 @@
79

810
runner = CliRunner()
911

12+
requires_python_310 = pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10 or higher")
13+
1014

15+
@requires_python_310
1116
def test_validate_schema_valid():
1217
fixture_file = get_fixtures_dir() / "models" / "valid_model_01.json"
1318

@@ -16,6 +21,7 @@ def test_validate_schema_valid():
1621
assert "Schema is valid" in result.stdout
1722

1823

24+
@requires_python_310
1925
def test_validate_schema_empty():
2026
fixture_file = get_fixtures_dir() / "models" / "empty.json"
2127

@@ -24,6 +30,7 @@ def test_validate_schema_empty():
2430
assert "Empty YAML/JSON file" in remove_ansi_color(result.stdout)
2531

2632

33+
@requires_python_310
2734
def test_validate_schema_non_valid():
2835
fixture_file = get_fixtures_dir() / "models" / "non_valid_model_01.json"
2936

tests/unit/sdk/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def return_annotation_map() -> dict[str, str]:
7676
"Optional[type[SchemaType]]": "Optional[type[SchemaTypeSync]]",
7777
"Optional[Union[CoreNode, SchemaType]]": "Optional[Union[CoreNodeSync, SchemaTypeSync]]",
7878
"InfrahubBatch": "InfrahubBatchSync",
79+
"CoreNode | None": "CoreNodeSync | None",
80+
"str | type[SchemaType]": "str | type[SchemaTypeSync]",
81+
"InfrahubNode | SchemaType": "InfrahubNodeSync | SchemaTypeSync",
82+
"InfrahubNode | SchemaType | None": "InfrahubNodeSync | SchemaTypeSync | None",
83+
"list[InfrahubNode] | list[SchemaType]": "list[InfrahubNodeSync] | list[SchemaTypeSync]",
84+
"InfrahubNode | None": "InfrahubNodeSync | None",
85+
"type[SchemaType] | None": "type[SchemaTypeSync] | None",
86+
"CoreNode | SchemaType | None": "CoreNodeSync | SchemaTypeSync | None",
7987
}
8088

8189

0 commit comments

Comments
 (0)