diff --git a/tests/integration/utils.py b/tests/helpers/utils.py similarity index 100% rename from tests/integration/utils.py rename to tests/helpers/utils.py diff --git a/tests/integration/test_infrahubctl.py b/tests/unit/ctl/test_transform_app.py similarity index 86% rename from tests/integration/test_infrahubctl.py rename to tests/unit/ctl/test_transform_app.py index a63514f1..d4fd0316 100644 --- a/tests/integration/test_infrahubctl.py +++ b/tests/unit/ctl/test_transform_app.py @@ -3,25 +3,27 @@ import json import os import shutil +import sys import tempfile from pathlib import Path import pytest from git import Repo from pytest_httpx._httpx_mock import HTTPXMock -from typer.testing import Any, CliRunner +from typer.testing import CliRunner from infrahub_sdk.ctl.cli_commands import app - -from .utils import change_directory, strip_color +from tests.helpers.utils import change_directory, strip_color runner = CliRunner() -FIXTURE_BASE_DIR = Path(Path(os.path.abspath(__file__)).parent / ".." / "fixtures" / "integration" / "test_infrahubctl") +FIXTURE_BASE_DIR = Path( + Path(os.path.abspath(__file__)).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl" +) -def read_fixture(file_name: str, fixture_subdir: str = ".") -> Any: +def read_fixture(file_name: str, fixture_subdir: str = ".") -> str: """Read the contents of a fixture.""" with Path(FIXTURE_BASE_DIR / fixture_subdir / file_name).open("r", encoding="utf-8") as fhd: fixture_contents = fhd.read() @@ -38,7 +40,7 @@ def tags_transform_dir(): shutil.copytree(fixture_path, temp_dir, dirs_exist_ok=True) # Initialize fixture as git repo. This is necessary to run some infrahubctl commands. with change_directory(temp_dir): - Repo.init(".") + Repo.init(".", initial_branch="main") yield temp_dir @@ -64,6 +66,7 @@ def test_transform_not_exist_in_infrahub_yml(tags_transform_dir: str) -> None: assert output.exit_code == 1 @staticmethod + @pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") def test_transform_python_file_not_defined(tags_transform_dir: str) -> None: """Case transform python file not defined.""" # Remove transform file @@ -78,6 +81,7 @@ def test_transform_python_file_not_defined(tags_transform_dir: str) -> None: assert output.exit_code == 1 @staticmethod + @pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") def test_transform_python_class_not_defined(tags_transform_dir: str) -> None: """Case transform python class not defined.""" # Rename transform inside of python file so the class name searched for no longer exists @@ -97,6 +101,7 @@ def test_transform_python_class_not_defined(tags_transform_dir: str) -> None: assert output.exit_code == 1 @staticmethod + @pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") def test_gql_query_not_defined(tags_transform_dir: str) -> None: """Case GraphQL Query is not defined""" # Remove GraphQL Query file @@ -110,6 +115,7 @@ def test_gql_query_not_defined(tags_transform_dir: str) -> None: assert output.exit_code == 1 @staticmethod + @pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") def test_infrahubctl_transform_cmd_success(httpx_mock: HTTPXMock, tags_transform_dir: str) -> None: """Case infrahubctl transform command executes successfully""" httpx_mock.add_response(