Skip to content

Commit

Permalink
Make changes requested in code review
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Mar 20, 2023
1 parent 4200898 commit 430f0c8
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ repos:
rev: v0.0.253
hooks:
- id: ruff
# args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
49 changes: 40 additions & 9 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,33 @@ exclude = [
"ci/templates",
"dist",
]
line-length = 140
select = [
"E",
"F",
"I",
"PLC",
"PLE",
"UP",
"W",
ignore = [
"ANN", # flake8-annotations
"ARG", # flake8-unused-arguments
"BLE", # flake8-blind-except
"COM", # flake8-comma
"D", # pydocstyle
"EM", # flake8-errmsg
"FBT", # flake8-boolean-trap
"INP", # flake8-no-pep420
"PLR0133", # Pylint Refactor
"PLR2004", # Pylint Refactor
"PLW", # Pylint Warning
"PTH", # flake8-use-pathlib
"Q", # flake8-quotes
"RET", # flake8-return
"RUF100", # Ruff-internal
"S101", # flake8-bandit assert
"S102", # flake8-bandit exec
"S110", # flake8-bandit try-except-pass
"SIM102", # flake8-simplify collapsible-if
"SIM105", # flake8-simplify use-contextlib-suppress
"SLF", # flake8-self
"T20", # flake8-print
"TRY", # tryceratops
]
line-length = 140
select = ["ALL"]
target-version = "py37"

# [tool.ruff.isort] # <- TODO Uncomment when migrating to pyproject.toml
Expand All @@ -24,3 +41,17 @@ target-version = "py37"
force-single-line = true
forced-separate = ["test_pytest_cov"]
known-first-party = ["pytest_cov"]

[mccabe]
max-complexity = 12

[per-file-ignores]
"ci/bootstrap.py" = ["S701"]
"docs/conf.py" = ["A001"]
"src/pytest_cov/plugin.py" = ["B904", "PT004"]
"setup.py" = ["SIM117"]
"tests/test_pytest_cov.py" = ["N801", "PT004", "RSE102", "SIM117"]

[pylint]
max-args = 8
max-branches = 13
2 changes: 1 addition & 1 deletion examples/adhoc-layout/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_add():
assert example.add(1, 1) == 2
assert not example.add(0, 1) == 2
assert example.add(0, 1) != 2
2 changes: 1 addition & 1 deletion examples/src-layout/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_add():
assert example.add(1, 1) == 2
assert not example.add(0, 1) == 2
assert example.add(0, 1) != 2
12 changes: 0 additions & 12 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
[flake8]
max-line-length = 140
exclude = .tox,.eggs,ci/templates,build,dist

[tool:pytest]
testpaths = tests
python_files = test_*.py
addopts =
-ra
--strict
-p pytester

[tool:isort]
force_single_line = True
line_length = 120
known_first_party = pytest_cov
default_section = THIRDPARTY
forced_separate = test_pytest_cov
skip = .tox,.eggs,ci/templates,build,dist
7 changes: 2 additions & 5 deletions src/pytest_cov/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def init():
import coverage

# Determine all source roots.
if cov_source in os.pathsep:
cov_source = None
else:
cov_source = cov_source.split(os.pathsep)
cov_source = None if cov_source in os.pathsep else cov_source.split(os.pathsep)
if cov_config == os.pathsep:
cov_config = True

Expand Down Expand Up @@ -108,7 +105,7 @@ def _signal_cleanup_handler(signum, frame):
elif signum == signal.SIGTERM:
os._exit(128 + signum)
elif signum == signal.SIGINT:
raise KeyboardInterrupt()
raise KeyboardInterrupt


def cleanup_on_signal(signum):
Expand Down
2 changes: 0 additions & 2 deletions src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,3 @@ def finish(self):

def summary(self, stream):
"""Only the master reports so do nothing."""

pass
9 changes: 4 additions & 5 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validate_report(arg):
all_choices = term_choices + file_choices
values = arg.split(":", 1)
report_type = values[0]
if report_type not in all_choices + ['']:
if report_type not in [*all_choices, '']:
msg = f'invalid choice: "{arg}" (choose from "{all_choices}")'
raise argparse.ArgumentTypeError(msg)

Expand Down Expand Up @@ -247,7 +247,7 @@ def pytest_sessionstart(self, session):
self.pid = os.getpid()
if self._is_worker(session):
nodeid = (
session.config.workerinput.get('workerid', getattr(session, 'nodeid'))
session.config.workerinput.get('workerid', session.nodeid)
)
self.start(engine.DistWorker, session.config, nodeid)
elif not self._started:
Expand Down Expand Up @@ -389,13 +389,12 @@ def switch_context(self, item, when):
os.environ['COV_CORE_CONTEXT'] = context


@pytest.fixture
@pytest.fixture()
def no_cover():
"""A pytest fixture to disable coverage."""
pass


@pytest.fixture
@pytest.fixture()
def cov(request):
"""A pytest fixture to provide access to the underlying coverage object."""

Expand Down
8 changes: 4 additions & 4 deletions tests/contextful.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_04(self):
assert self.items[0] == "hello" # r4


@pytest.fixture
@pytest.fixture()
def some_data():
return [1, 2, 3] # s5 s6

Expand All @@ -48,7 +48,7 @@ def test_05(some_data):
assert len(some_data) == 3 # r5


@pytest.fixture
@pytest.fixture()
def more_data(some_data):
return [2*x for x in some_data] # s6

Expand Down Expand Up @@ -83,15 +83,15 @@ def test_10():
assert 1 == 1 # r10


@pytest.mark.parametrize("x, ans", [
@pytest.mark.parametrize(("x", "ans"), [
(1, 101),
(2, 202),
])
def test_11(x, ans):
assert 100 * x + x == ans # r11-1 r11-2


@pytest.mark.parametrize("x, ans", [
@pytest.mark.parametrize(("x", "ans"), [
(1, 101),
(2, 202),
], ids=['one', 'two'])
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ deps =
check-manifest
colorama # TODO Remove when isort > v6.0.0b2 is released.
docutils
flake8
isort
pygments
readme-renderer
ruff
skip_install = true
usedevelop = false
commands =
python setup.py check --strict --metadata --restructuredtext
check-manifest {toxinidir}
flake8 src tests setup.py
ruff .
isort --check-only --diff src tests setup.py

0 comments on commit 430f0c8

Please sign in to comment.