Skip to content

Commit

Permalink
Replace List with built-in list for type hints in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Šoltis <[email protected]>
  • Loading branch information
slimreaper35 committed Jan 14, 2025
1 parent c71d29e commit 85badba
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 27 deletions.
3 changes: 1 addition & 2 deletions tests/integration/test_generic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import List

import pytest

Expand Down Expand Up @@ -88,7 +87,7 @@ def test_generic_fetcher(
)
def test_e2e_generic(
test_params: utils.TestParameters,
check_cmd: List[str],
check_cmd: list[str],
expected_cmd_output: str,
cachi2_image: utils.ContainerImage,
tmp_path: Path,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_gomod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
from pathlib import Path
from typing import List

import pytest

Expand Down Expand Up @@ -257,7 +256,7 @@ def test_gomod_packages(
)
def test_e2e_gomod(
test_params: utils.TestParameters,
check_cmd: List[str],
check_cmd: list[str],
expected_cmd_output: str,
cachi2_image: utils.ContainerImage,
tmp_path: Path,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_npm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from pathlib import Path
from typing import List

import pytest

Expand Down Expand Up @@ -313,7 +312,7 @@ def test_npm_smoketest(
)
def test_e2e_npm(
test_params: utils.TestParameters,
check_cmd: List[str],
check_cmd: list[str],
expected_cmd_output: str,
cachi2_image: utils.ContainerImage,
tmp_path: Path,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_pip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
from pathlib import Path
from typing import List

import pytest

Expand Down Expand Up @@ -223,7 +222,7 @@ def test_pip_packages(
)
def test_e2e_pip(
test_params: utils.TestParameters,
check_cmd: List[str],
check_cmd: list[str],
expected_cmd_output: str,
cachi2_image: utils.ContainerImage,
tmp_path: Path,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
from configparser import ConfigParser
from pathlib import Path
from typing import List

import pytest

Expand Down Expand Up @@ -270,7 +269,7 @@ def read_and_normalize_repofile(path: Path) -> str:
)
def test_e2e_rpm(
test_params: utils.TestParameters,
check_cmd: List[str],
check_cmd: list[str],
expected_cmd_output: str,
cachi2_image: utils.ContainerImage,
tmp_path: Path,
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from subprocess import PIPE, Popen
from tarfile import ExtractError, TarFile
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Dict, Optional, Sequence, Tuple, Union

import jsonschema
import requests
Expand Down Expand Up @@ -71,7 +71,7 @@ class TestParameters:
check_vendor_checksums: bool = True
expected_exit_code: int = 0
expected_output: str = ""
flags: List[str] = field(default_factory=list)
flags: list[str] = field(default_factory=list)


StrPath = Union[str, os.PathLike[str]]
Expand All @@ -94,7 +94,7 @@ def pull_image(self) -> None:

def run_cmd_on_image(
self,
cmd: List,
cmd: list[Any],
tmpdir: StrPath,
mounts: Sequence[tuple[StrPath, StrPath]] = (),
net: Optional[str] = None,
Expand All @@ -118,7 +118,7 @@ def __exit__(self, exc_type: Any, exc_value: Any, exc_traceback: Any) -> None:
class Cachi2Image(ContainerImage):
def run_cmd_on_image(
self,
cmd: List,
cmd: list[Any],
tmpdir: StrPath,
mounts: Sequence[tuple[StrPath, StrPath]] = (),
net: Optional[str] = "host",
Expand Down Expand Up @@ -191,7 +191,7 @@ def clone_repository(repo_url: str, ref: str, folder_name: str, tmpdir: Path) ->
return folder


def run_cmd(cmd: List[str]) -> Tuple[str, int]:
def run_cmd(cmd: list[str]) -> Tuple[str, int]:
"""
Run command via subprocess.
Expand Down Expand Up @@ -424,7 +424,7 @@ def build_image_and_check_cmd(
output_folder: Path,
test_data_dir: Path,
test_case: str,
check_cmd: List,
check_cmd: list[str],
expected_cmd_output: str,
cachi2_image: ContainerImage,
) -> None:
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/models/test_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from textwrap import dedent
from typing import Any, Dict, List
from typing import Any, Dict

import pydantic
import pytest
Expand Down Expand Up @@ -178,7 +178,6 @@ def test_resolution(
expected: str,
mappings: Dict[str, str],
) -> None:

assert env_variables[var].resolve_value(mappings) == expected
assert "kind" not in env_variables[var].model_dump()

Expand All @@ -199,7 +198,7 @@ def test_resolution(
),
],
)
def test_nested_resolution_failure(self, envs: List[EnvironmentVariable]) -> None:
def test_nested_resolution_failure(self, envs: list[EnvironmentVariable]) -> None:
mappings = {e.name: e.value for e in envs}

err_msg = f"Detected a cycle in environment variable expansion of '{envs[0].name}'"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/package_managers/test_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import urllib.parse
from pathlib import Path
from typing import Any, Dict, Iterator, List, Optional, Union
from typing import Any, Dict, Iterator, Optional, Union
from unittest import mock

import pytest
Expand Down Expand Up @@ -863,7 +863,7 @@ def test_fetch_npm_source(
mock_resolve_npm: mock.Mock,
npm_request: Request,
npm_input_packages: dict[str, str],
resolved_packages: List[ResolvedNpmPackage],
resolved_packages: list[ResolvedNpmPackage],
request_output: dict[str, list[Any]],
) -> None:
"""Test fetch_npm_source with different Request inputs."""
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/package_managers/test_rpm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ssl
from configparser import ConfigParser
from pathlib import Path
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, Optional, Union
from unittest import mock

import pytest
Expand Down Expand Up @@ -94,11 +94,11 @@
def test_fetch_rpm_source(
mock_resolve_rpm_project: mock.Mock,
mock_from_obj_list: mock.Mock,
model_input: Union[mock.Mock, RpmPackageInput, List[RpmPackageInput]],
model_input: Union[mock.Mock, RpmPackageInput, list[RpmPackageInput]],
result_options: Optional[Dict[str, Dict[str, Any]]],
caplog: LogCaptureFixture,
) -> None:
def _has_multiple_options(rpm_models: List[RpmPackageInput]) -> bool:
def _has_multiple_options(rpm_models: list[RpmPackageInput]) -> bool:
options = 0
for model in rpm_models:
if model.options:
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/package_managers/yarn/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from itertools import zip_longest
from pathlib import Path
from typing import List, Optional, Union
from typing import Optional, Union
from unittest import mock

import pytest
Expand Down Expand Up @@ -53,11 +53,11 @@ class YarnVersions(Enum):
YARN_V5 = semver.VersionInfo(5, 0, 0)

@classmethod
def supported(cls) -> List["YarnVersions"]:
def supported(cls) -> list["YarnVersions"]:
return [cls.YARN_V3, cls.YARN_V36_RC1, cls.YARN_V4, cls.YARN_V4_RC1]

@classmethod
def unsupported(cls) -> List["YarnVersions"]:
def unsupported(cls) -> list["YarnVersions"]:
return list(set(cls.__members__.values()).difference(set(cls.supported())))


Expand Down

0 comments on commit 85badba

Please sign in to comment.