From 2f74f99dee10e823d9c408c97c37a2675277ec4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Tue, 28 May 2024 15:15:35 +0200 Subject: [PATCH] Cover `tmt.trying` with `pyright` check (#2942) --- pyproject.toml | 1 - tmt/trying.py | 27 ++++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6ae85ce65c..9c6587aa1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -249,7 +249,6 @@ ignore = [ "tmt/convert.py", "tmt/lint.py", "tmt/queue.py", - "tmt/trying.py", "tmt/utils.py" ] diff --git a/tmt/trying.py b/tmt/trying.py index 1fcc03de1d..e1a653bb39 100644 --- a/tmt/trying.py +++ b/tmt/trying.py @@ -3,15 +3,18 @@ import enum import re import textwrap -from typing import Any +from collections.abc import Iterator +from typing import Any, cast import click import fmf -from fmf.utils import listed +import fmf.utils import tmt +import tmt.base import tmt.log import tmt.steps +import tmt.steps.execute import tmt.steps.provision import tmt.templates import tmt.utils @@ -130,7 +133,7 @@ def check_tests(self) -> None: self.tests = self.tree.tests(names=test_names) if not self.tests: raise tmt.utils.GeneralError( - f"No test matching '{listed(test_names)}' found.") + f"No test matching '{fmf.utils.listed(test_names)}' found.") # Default to tests under the current working directory else: @@ -144,7 +147,7 @@ def check_tests(self) -> None: self.warn(f"No tests found under the '{relative_path}' directory.") # Short debug info about what was found - self.debug("Test name filter", listed(test_names, quote="'")) + self.debug("Test name filter", fmf.utils.listed(test_names, quote="'")) self.debug("Matching tests found\n" + tmt.utils.format_value(self.tests)) # Inject the test filtering options into the Test class @@ -160,10 +163,12 @@ def get_default_plans(self, run: tmt.base.Run) -> list[Plan]: try: config_tree = tmt.utils.Config().fmf_tree plan_name = re.escape(USER_PLAN_NAME) - user_plans = list(config_tree.prune(names=[f"^{plan_name}"])) + # cast: once fmf is properly annotated, cast() would not be needed. + # pyright isn't able to infer the type. + user_plans = list(cast(Iterator[fmf.Tree], config_tree.prune(names=[f"^{plan_name}"]))) if user_plans: for user_plan in user_plans: - plan_dict = {user_plan.name: user_plan.data} + plan_dict: dict[str, Any] = {user_plan.name: user_plan.data} self.tree.tree.update(plan_dict) self.debug("Use the default user plan config.") return self.tree.plans(names=[f"^{plan_name}"], run=run) @@ -183,11 +188,11 @@ def check_plans(self, run: tmt.base.Run) -> None: # Search for matching plans if plan names provided plan_names = list(self.opt("plan")) if plan_names: - self.debug("Plan names filter", listed(plan_names, quote="'")) + self.debug("Plan names filter", fmf.utils.listed(plan_names, quote="'")) self.plans = self.tree.plans(names=plan_names, run=run) if not self.plans: raise tmt.utils.GeneralError( - f"No plan matching '{listed(plan_names)}' found.") + f"No plan matching '{fmf.utils.listed(plan_names)}' found.") # Use default plans if no plan names requested else: @@ -212,20 +217,20 @@ def welcome(self) -> None: if self.opt("login"): parts += [click.style("login", fg="red")] elif test_names and not self.opt("ask"): - parts += [listed(test_names, 'test', max=3)] + parts += [fmf.utils.listed(test_names, 'test', max=3)] else: parts += ["something"] parts += ["with"] # Plan names plan_names = [click.style(plan, fg="magenta") for plan in self.plans] - parts += [listed(plan_names, 'plan', max=3)] + parts += [fmf.utils.listed(plan_names, 'plan', max=3)] # Image names if self.image_and_how: parts += ["on"] image_names = [click.style(image, fg="blue") for image in self.image_and_how] - parts += [listed(image_names)] + parts += [fmf.utils.listed(image_names)] self.print(" ".join(parts) + ".")