Skip to content

Commit

Permalink
Update pre-commit hooks and fix new ruff errors
Browse files Browse the repository at this point in the history
Ruff rules addressed: ICN001, PT001, PT023, PLR1730.
  • Loading branch information
martinhoyer authored and happz committed Sep 10, 2024
1 parent 21c9e97 commit 5146968
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 44 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.11.1"
rev: "v1.11.2"
hooks:
- id: mypy
language_version: "3.9"
Expand Down Expand Up @@ -67,7 +67,7 @@ repos:
args: [--config-file=pyproject.toml]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.371
rev: v1.1.379
hooks:
- id: pyright
language_version: "3.9"
Expand Down Expand Up @@ -110,7 +110,7 @@ repos:
- "types-docutils"

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.29.1"
rev: "0.29.2"
hooks:
- id: check-metaschema
name: "Check JSON schemas validity"
Expand Down Expand Up @@ -139,15 +139,15 @@ repos:
# in order to be parsed by ansible-lint

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.7
rev: v0.6.4
hooks:
- id: ruff
args:
- '--fix'
- '--show-fixes'

- repo: https://github.com/teemtee/tmt.git
rev: 1.35.0
rev: 1.36.0
hooks:
- id: tmt-lint
additional_dependencies:
Expand All @@ -167,7 +167,7 @@ repos:
- tomli # Required for python < 3.11

- repo: https://github.com/djlint/djLint
rev: v1.34.1
rev: v1.35.2
hooks:
- id: djlint
files: "\\.j2"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def tmppath_factory(
tmp_path_factory: '_pytest.tmpdir.TempPathFactory') -> TempPathFactory: # noqa: F811
return TempPathFactory(tmp_path_factory)

@pytest.fixture()
@pytest.fixture
def tmppath(tmp_path: pathlib.Path) -> Path: # noqa: TID251
return Path(str(tmp_path))

Expand All @@ -75,7 +75,7 @@ def tmppath_factory(
) -> TempPathFactory:
return TempPathFactory(tmpdir_factory)

@pytest.fixture()
@pytest.fixture
def tmppath(tmpdir: py.path.local) -> Path:
return Path(str(tmpdir))

Expand All @@ -94,7 +94,7 @@ def source_dir(tmppath_factory: TempPathFactory) -> Path:
return source_location


@pytest.fixture()
@pytest.fixture
def target_dir(tmppath_factory: TempPathFactory) -> Path:
""" Return target directory path and clean up after tests """
return tmppath_factory.mktemp('target')
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from tmt.utils import ConvertError


@pytest.fixture()
@pytest.fixture
def mini(root_logger):
""" Minimal example """
return relevancy_to_adjust("distro = fedora: False", root_logger)


@pytest.fixture()
@pytest.fixture
def full(root_logger):
""" Full example """
return relevancy_to_adjust("""
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_beakerlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tmt.utils import Path


@pytest.mark.web()
@pytest.mark.web
def test_basic(root_logger):
""" Fetch a beakerlib library with/without providing a parent """
parent = tmt.utils.Common(logger=root_logger, workdir=True)
Expand All @@ -32,7 +32,7 @@ def test_basic(root_logger):
shutil.rmtree(library.parent.workdir)


@pytest.mark.web()
@pytest.mark.web
@pytest.mark.parametrize(
('url', 'name', 'default_branch'), [
('https://github.com/beakerlib/httpd', '/http', 'master'),
Expand All @@ -55,7 +55,7 @@ def test_require_from_fmf(url, name, default_branch, root_logger):
shutil.rmtree(library.parent.workdir)


@pytest.mark.web()
@pytest.mark.web
def test_invalid_url_conflict(root_logger):
""" Saner check if url mismatched for translated library """
parent = tmt.utils.Common(logger=root_logger, workdir=True)
Expand All @@ -76,7 +76,7 @@ def test_invalid_url_conflict(root_logger):
shutil.rmtree(parent.workdir)


@pytest.mark.web()
@pytest.mark.web
def test_dependencies(root_logger):
""" Check requires for possible libraries """
parent = tmt.utils.Common(logger=root_logger, workdir=True)
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_dependencies(root_logger):
shutil.rmtree(parent.workdir)


@pytest.mark.web()
@pytest.mark.web
def test_mark_nonexistent_url(root_logger, monkeypatch):
""" Check url existence just one time """
parent = tmt.utils.Common(logger=root_logger, workdir=True)
Expand Down
28 changes: 14 additions & 14 deletions tests/unit/test_package_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _parametrize_test_discovery() -> Iterator[tuple[ContainerData, PackageManage
yield from CONTAINER_DISCOVERY_MATRIX.values()


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container',
'expected_package_manager'),
list(_parametrize_test_discovery()),
Expand Down Expand Up @@ -389,7 +389,7 @@ def _parametrize_test_install() -> \
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'package',
Expand Down Expand Up @@ -510,7 +510,7 @@ def _parametrize_test_install_nonexistent() -> \
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container',
'package_manager_class',
'expected_command',
Expand Down Expand Up @@ -621,7 +621,7 @@ def _parametrize_test_install_nonexistent_skip() -> \
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container',
'package_manager_class',
'expected_command',
Expand Down Expand Up @@ -737,7 +737,7 @@ def _parametrize_test_install_dont_check_first() -> \
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'package',
Expand Down Expand Up @@ -852,7 +852,7 @@ def _parametrize_test_reinstall() -> Iterator[tuple[
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'package',
Expand Down Expand Up @@ -977,7 +977,7 @@ def _generate_test_reinstall_nonexistent_matrix() -> Iterator[tuple[
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container',
'package_manager_class',
'supported',
Expand Down Expand Up @@ -1300,7 +1300,7 @@ def _generate_test_check_presence_ids(value) -> str:
return ''


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container',
'package_manager_class',
'installable',
Expand Down Expand Up @@ -1401,7 +1401,7 @@ def _parametrize_test_install_filesystempath() -> Iterator[
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'installable',
Expand Down Expand Up @@ -1521,7 +1521,7 @@ def _parametrize_test_install_multiple() -> \
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'packages',
Expand Down Expand Up @@ -1658,7 +1658,7 @@ def _parametrize_test_install_downloaded() -> \
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'packages',
Expand Down Expand Up @@ -1803,7 +1803,7 @@ def _parametrize_test_install_debuginfo() -> Iterator[
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'installables',
Expand Down Expand Up @@ -1881,7 +1881,7 @@ def _parametrize_test_install_debuginfo_nonexistent() -> Iterator[
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'installables',
Expand Down Expand Up @@ -1993,7 +1993,7 @@ def _parametrize_test_install_debuginfo_nonexistent_skip() -> Iterator[
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.containers
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'installables',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_report_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tmt.utils import Path


@pytest.fixture()
@pytest.fixture
def report_fix(tmppath: Path, root_logger):
# need to provide genuine workdir paths - mock would break os.path.* calls
step_mock = MagicMock(workdir=tmppath)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
run = Common(logger=tmt.log.Logger.create(verbose=0, debug=0, quiet=False)).run


@pytest.fixture()
@pytest.fixture
def local_git_repo(tmppath: Path) -> Path:
origin = tmppath / 'origin'
origin.mkdir()
Expand All @@ -75,7 +75,7 @@ def local_git_repo(tmppath: Path) -> Path:
return origin


@pytest.fixture()
@pytest.fixture
def origin_and_local_git_repo(local_git_repo: Path) -> tuple[Path, Path]:
top_dir = local_git_repo.parent
fork_dir = top_dir / 'fork'
Expand All @@ -88,7 +88,7 @@ def origin_and_local_git_repo(local_git_repo: Path) -> tuple[Path, Path]:
return local_git_repo, fork_dir


@pytest.fixture()
@pytest.fixture
def nested_file(tmppath: Path) -> tuple[Path, Path, Path]:
top_dir = tmppath / 'top_dir'
top_dir.mkdir()
Expand Down
3 changes: 1 addition & 2 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3740,8 +3740,7 @@ def print_run_status(self, run: Run) -> None:
earliest_step_index = -1
break
plan_status_index = tmt.steps.STEPS.index(plan_status)
if plan_status_index < earliest_step_index:
earliest_step_index = plan_status_index
earliest_step_index = min(plan_status_index, earliest_step_index)

if earliest_step_index == len(tmt.steps.STEPS):
run_status = 'done'
Expand Down
16 changes: 8 additions & 8 deletions tmt/steps/report/polarion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime
import os
from typing import Optional
from xml.etree import ElementTree
from xml.etree import ElementTree as ET

from requests import post

Expand Down Expand Up @@ -226,7 +226,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:

junit_suite = make_junit_xml(self)
# S314: Any potential xml parser vulnerability mitigation would require defusedxml package
xml_tree = ElementTree.fromstring(junit_suite.to_xml_string([junit_suite])) # noqa: S314
xml_tree = ET.fromstring(junit_suite.to_xml_string([junit_suite])) # noqa: S314
properties = {
'polarion-project-id': project_id,
'polarion-user-id': PolarionWorkItem._session.user_id,
Expand All @@ -247,9 +247,9 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
logs = os.getenv('TMT_REPORT_ARTIFACTS_URL')
if logs and 'polarion-custom-logs' not in properties:
properties['polarion-custom-logs'] = logs
testsuites_properties = ElementTree.SubElement(xml_tree, 'properties')
testsuites_properties = ET.SubElement(xml_tree, 'properties')
for name, value in properties.items():
ElementTree.SubElement(testsuites_properties, 'property', attrib={
ET.SubElement(testsuites_properties, 'property', attrib={
'name': name, 'value': str(value)})

testsuite = xml_tree.find('testsuite')
Expand Down Expand Up @@ -281,16 +281,16 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
assert testsuite is not None
test_case = testsuite.find(f"*[@name='{result.name}']")
assert test_case is not None
properties_elem = ElementTree.SubElement(test_case, 'properties')
properties_elem = ET.SubElement(test_case, 'properties')
for name, value in test_properties.items():
ElementTree.SubElement(properties_elem, 'property', attrib={
ET.SubElement(properties_elem, 'property', attrib={
'name': name, 'value': value})

assert self.workdir is not None

f_path = self.data.file or self.workdir / DEFAULT_NAME
with open(f_path, 'wb') as fw:
ElementTree.ElementTree(xml_tree).write(fw)
ET.ElementTree(xml_tree).write(fw)

if upload:
server_url = str(PolarionWorkItem._session._server.url)
Expand All @@ -303,7 +303,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:

response = post(
polarion_import_url, auth=auth,
files={'file': ('xunit.xml', ElementTree.tostring(xml_tree))}, timeout=10
files={'file': ('xunit.xml', ET.tostring(xml_tree))}, timeout=10
)
self.info(
f'Response code is {response.status_code} with text: {response.text}')
Expand Down

0 comments on commit 5146968

Please sign in to comment.