Skip to content

Commit 9239e17

Browse files
committed
fix: ruff findings
1 parent c992909 commit 9239e17

File tree

10 files changed

+27
-48
lines changed

10 files changed

+27
-48
lines changed

.github/workflows/python-test-scan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
uses: chartboost/ruff-action@v1
117117
with:
118118
src: src
119-
args: check --show-source
119+
args: check --show-files
120120
- name: Ruff src diff
121121
uses: chartboost/ruff-action@v1
122122
if: ${{ always() }}
@@ -128,7 +128,7 @@ jobs:
128128
if: ${{ always() }}
129129
with:
130130
src: test
131-
args: check --show-source
131+
args: check --show-files
132132
- name: Ruff test diff
133133
uses: chartboost/ruff-action@v1
134134
if: ${{ always() }}

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ ignore = [
105105
"TRY003", # Avoid specifying long messages outside the exception class
106106
]
107107

108+
[tool.ruff.lint.flake8-pytest-style]
109+
fixture-parentheses = true
110+
108111
[tool.ruff.lint.isort]
109112
known-first-party = ["pytest_sort"]
110113

req/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pytest>=7.4.0
22
whatthepatch>=1.0.5
3-
coverage>=7.3.1
4-
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
3+
coverage>=7.3.1

req/tools.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ isort
44

55
-r pytest.txt
66
-r mypy.txt
7-
-r build.txt
7+
-r build.txt
8+
-r poodle.txt

src/pytest_sort/core.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import hashlib
66
import random
7-
import sys
87
from functools import partial
98
from typing import TYPE_CHECKING, Any, Callable
109

@@ -15,9 +14,7 @@
1514
from pytest_sort.database import get_all_totals, get_stats
1615
from pytest_sort.diffcov import get_diff_test_scores, get_mut_test_scores
1716

18-
md5: Callable = hashlib.md5
19-
if sys.version_info >= (3, 9):
20-
md5: Callable = partial(hashlib.md5, usedforsecurity=False) # type: ignore[no-redef]
17+
md5: Callable = partial(hashlib.md5, usedforsecurity=False) # type: ignore[no-redef]
2118

2219

2320
if TYPE_CHECKING:

src/pytest_sort/database.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,12 @@ def update_test_cases(recorded_times: dict) -> None:
3131
"""Update Test Case Data with specfiied duration(s) and recalculate total(s)."""
3232
_load_data()
3333

34-
for nodeid in recorded_times:
34+
for nodeid, recorded_node in recorded_times.items():
3535
node_data = _sort_data.get(nodeid, {})
3636

37-
node_data["setup"] = node_data.get("setup", 0)
38-
node_data["call"] = node_data.get("call", 0)
39-
node_data["teardown"] = node_data.get("teardown", 0)
40-
41-
setup = recorded_times[nodeid].get("setup", 0)
42-
if node_data["setup"] < setup:
43-
node_data["setup"] = setup
44-
45-
call = recorded_times[nodeid].get("call", 0)
46-
if node_data["call"] < call:
47-
node_data["call"] = call
48-
49-
teardown = recorded_times[nodeid].get("teardown", 0)
50-
if node_data["teardown"] < teardown:
51-
node_data["teardown"] = teardown
37+
node_data["setup"] = max(node_data.get("setup", 0), recorded_node.get("setup", 0))
38+
node_data["call"] = max(node_data.get("call", 0), recorded_node.get("call", 0))
39+
node_data["teardown"] = max(node_data.get("teardown", 0), recorded_node.get("teardown", 0))
5240

5341
node_data["total"] = node_data["setup"] + node_data["call"] + node_data["teardown"]
5442

src/pytest_sort/diffcov.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
import shlex
88
import subprocess
99
from pathlib import Path
10-
from typing import Any, Generator
10+
from typing import TYPE_CHECKING, Any
1111

1212
import whatthepatch
1313
from coverage.sqldata import CoverageData
1414

15+
if TYPE_CHECKING:
16+
from collections.abc import Generator
17+
1518
# pytest-cov populates test context as <nodeid>|(setup|run|teardown)
1619
PARSE_TEST_CONTEXT = re.compile(r"(?P<nodeid>.*)\|(?P<when>setup|run|teardown)")
1720

@@ -50,10 +53,10 @@ def get_mut_changed_lines() -> dict[Path, set[int]]:
5053
"""
5154
changed_lines = {}
5255
mut_source_file = os.environ.get("MUT_SOURCE_FILE", None)
53-
mut_lineno = os.environ.get("MUT_LINENO", 0)
56+
mut_lineno = os.environ.get("MUT_LINENO", "0")
5457
mut_end_lineno = os.environ.get("MUT_END_LINENO", mut_lineno)
5558

56-
if mut_source_file and mut_lineno:
59+
if mut_source_file and int(mut_lineno):
5760
rpath = Path(mut_source_file).resolve()
5861
changed_lines[rpath] = set(range(int(mut_lineno), int(mut_end_lineno) + 1))
5962

src/pytest_sort/plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import argparse
6-
from typing import TYPE_CHECKING, Generator
6+
from typing import TYPE_CHECKING
77

88
import pytest
99

@@ -12,6 +12,8 @@
1212
from pytest_sort.database import clear_db, update_test_cases
1313

1414
if TYPE_CHECKING:
15+
from collections.abc import Generator
16+
1517
from _pytest.terminal import TerminalReporter
1618

1719

test/test_core.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import hashlib
22
import importlib
3-
import sys
43
from functools import partial
54
from typing import Callable, ClassVar
65
from unittest import mock
@@ -10,9 +9,7 @@
109

1110
from pytest_sort import config, core
1211

13-
md5: Callable = hashlib.md5
14-
if sys.version_info >= (3, 9):
15-
md5: Callable = partial(hashlib.md5, usedforsecurity=False) # type: ignore[no-redef]
12+
md5: Callable = partial(hashlib.md5, usedforsecurity=False) # type: ignore[no-redef]
1613

1714

1815
class TestImports:
@@ -21,23 +18,12 @@ def mock_md5(self):
2118
with mock.patch("hashlib.md5") as mock_md5:
2219
yield mock_md5
2320

24-
@pytest.fixture()
25-
def version_info(self):
26-
with mock.patch("sys.version_info") as version_info:
27-
yield version_info
28-
2921
@pytest.fixture(autouse=True)
3022
def _cleanup(self):
3123
yield
3224
importlib.reload(core)
3325

34-
def test_import_md5_38(self, version_info, mock_md5):
35-
version_info.__ge__ = lambda _, __: False
36-
importlib.reload(core)
37-
assert core.md5 == mock_md5
38-
39-
def test_import_md5_39(self, version_info, mock_md5):
40-
version_info.__ge__ = lambda _, v: v == (3, 9)
26+
def test_import_md5_39(self, mock_md5):
4127
importlib.reload(core)
4228
assert isinstance(core.md5, partial)
4329
assert core.md5.func == mock_md5
@@ -235,7 +221,7 @@ def test_validate_order_marker_error(self):
235221
with pytest.raises(TypeError, match="^Incorrect arguments on marker 'order'. Target:testnodeid$") as type_error:
236222
core.validate_order_marker(order_marker, "testnodeid")
237223

238-
assert type(type_error.value.__cause__) == TypeError
224+
assert isinstance(type_error.value.__cause__, TypeError)
239225

240226
@pytest.mark.parametrize(
241227
("args", "kwargs", "key"),
@@ -261,7 +247,7 @@ def test_validate_sort_marker_type_error(self):
261247
with pytest.raises(TypeError, match="^Incorrect arguments on marker 'sort'. Target:testnodeid$") as type_error:
262248
core.validate_sort_marker(sort_marker, "testnodeid")
263249

264-
assert type(type_error.value.__cause__) == TypeError
250+
assert isinstance(type_error.value.__cause__, TypeError)
265251

266252
def test_validate_sort_marker_value_error(self):
267253
sort_marker = mock.MagicMock()

tools.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
},
158158
"outputs": [],
159159
"source": [
160-
"!ruff check --show-files src test"
160+
"!ruff check src test"
161161
]
162162
},
163163
{

0 commit comments

Comments
 (0)