Skip to content

Commit

Permalink
Merge pull request #594 from nose-devs/remove-ruff
Browse files Browse the repository at this point in the history
Remove ruff
  • Loading branch information
sirosen authored Dec 22, 2023
2 parents bd8f47b + f1a9af8 commit 8cbde62
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 120 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
exclude = .git,.tox,__pycache__,.eggs,dist,.venv*,docs,build
max-line-length = 88
extend-ignore = W503,W504,E203,B011
39 changes: 26 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
rev: 0.27.3
hooks:
- id: check-github-workflows
- id: check-dependabot
- id: check-readthedocs
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.12.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- 'flake8-bugbear==23.12.2'
- 'flake8-comprehensions==3.14.0'
- 'flake8-typing-as-t==0.0.3'
- repo: https://github.com/sirosen/slyp
rev: 0.1.2
hooks:
- id: slyp
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
hooks:
- id: ruff
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.14
hooks:
- id: validate-pyproject
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.2.0
rev: 1.5.3
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.9"]
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Changed
Fixed
~~~~~

* Respect ``fail_under`` in converage config
* Respect ``fail_under`` in coverage config
* Avoid infinite recursion when loading setuptools from zipped egg
* Manpage now renders reproducibly
* MP doc build now reproducible
Expand Down
16 changes: 10 additions & 6 deletions nose2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ def setInitialArguments(self):
nargs="?",
action="append",
default=["unittest.cfg", "nose2.cfg"],
help="Config files to load, if they exist. ('unittest.cfg' "
"and 'nose2.cfg' in start directory default)",
help=(
"Config files to load, if they exist. ('unittest.cfg' "
"and 'nose2.cfg' in start directory default)"
),
)
self.argparse.add_argument(
"--no-user-config",
Expand All @@ -162,8 +164,10 @@ def setInitialArguments(self):
dest="load_plugins",
const=False,
default=True,
help="Do not load any plugins. Warning: nose2 does not "
"do anything if no plugins are loaded",
help=(
"Do not load any plugins. Warning: nose2 does not "
"do anything if no plugins are loaded"
),
)
self.argparse.add_argument(
"--plugin",
Expand All @@ -182,7 +186,7 @@ def setInitialArguments(self):
self.argparse.add_argument(
"--verbosity",
type=int,
help=("Set starting verbosity level (int). " "Applies before -v and -q"),
help=("Set starting verbosity level (int). Applies before -v and -q"),
)
self.argparse.add_argument(
"--verbose",
Expand All @@ -200,7 +204,7 @@ def setInitialArguments(self):
action="count",
default=0,
dest="quiet",
help=("Reduce verbosity. Multiple '-q's result in " "lower verbosity."),
help=("Reduce verbosity. Multiple '-q's result in lower verbosity."),
)
self.argparse.add_argument(
"--log-level",
Expand Down
6 changes: 4 additions & 2 deletions nose2/plugins/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ def __init__(self):
metavar="TYPE",
choices=["term", "term-missing", "annotate", "html", "xml"],
dest="coverage_report",
help="Generate selected reports, available types:"
" term, term-missing, annotate, html, xml (multi-allowed)",
help=(
"Generate selected reports, available types:"
" term, term-missing, annotate, html, xml (multi-allowed)"
),
)
group.add_argument(
"--coverage-config",
Expand Down
2 changes: 1 addition & 1 deletion nose2/plugins/loader/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def isTestMethod(attrname, testCaseClass=testCaseClass, excluded=excluded):
prefix = evt.testMethodPrefix or self.session.testMethodPrefix
return (
attrname.startswith(prefix)
and hasattr(getattr(testCaseClass, attrname), "__call__")
and attrname not in excluded
and callable(getattr(testCaseClass, attrname))
)

evt = events.GetTestCaseNamesEvent(event.loader, testCaseClass, isTestMethod)
Expand Down
2 changes: 1 addition & 1 deletion nose2/plugins/loader/testclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def isTestMethod(attrname, cls=cls, excluded=excluded):
prefix = self.session.testMethodPrefix
return (
attrname.startswith(prefix)
and hasattr(getattr(cls, attrname), "__call__")
and attrname not in excluded
and callable(getattr(cls, attrname))
)

evt = GetTestMethodNamesEvent(event.loader, cls, isTestMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_2(self):


class Test3(Test):
# this has class setup by virtue of inheritting from Test
# this has class setup by virtue of inheriting from Test

def test_3(self):
assert self.x
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
import unittest


Expand All @@ -6,7 +7,6 @@ def test_failing_assert(self):
x = True
y = False
# fmt: off
# ruff: noqa
assert x; assert y
# fmt: on

Expand Down
12 changes: 8 additions & 4 deletions nose2/tests/functional/test_layers_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ def test_layer_reporter_error_output(self):
r"ERROR: fixture with a value test_err \(test_layers_with_errors.Test"
+ _method_name("test_err")
+ r"\)",
"ERROR: A test scenario with errors should check for an attribute "
"that does not exist and raise an error",
(
"ERROR: A test scenario with errors should check for an attribute "
"that does not exist and raise an error"
),
r"FAIL: fixture with a value test_fail \(test_layers_with_errors.Test"
+ _method_name("test_fail")
+ r"\)",
"FAIL: A test scenario with errors should check that value == 2 "
"and fail",
(
"FAIL: A test scenario with errors should check that value == 2 "
"and fail"
),
]
for line in expect:
self.assertTestRunOutputMatches(proc, stderr=line)
Expand Down
4 changes: 2 additions & 2 deletions nose2/tests/functional/test_loadtests_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_package(self):
proc = self.runIn(
"scenario/load_tests_pkg",
"-v",
"-c=" "nose2/tests/functional/support/scenario/load_tests_pkg/unittest.cfg",
"-c=nose2/tests/functional/support/scenario/load_tests_pkg/unittest.cfg",
"--plugin=nose2.plugins.loader.loadtests",
)
self.assertTestRunOutputMatches(proc, stderr="Ran 2 tests")
Expand All @@ -34,7 +34,7 @@ def test_project_directory_inside_package(self):
proc = self.runIn(
"scenario/load_tests_pkg/ltpkg/tests",
"-v",
"-c=" "nose2/tests/functional/support/scenario/load_tests_pkg/unittest.cfg",
"-c=nose2/tests/functional/support/scenario/load_tests_pkg/unittest.cfg",
"--plugin=nose2.plugins.loader.loadtests",
)
self.assertTestRunOutputMatches(proc, stderr="Ran 1 test")
Expand Down
2 changes: 1 addition & 1 deletion nose2/tests/functional/test_such_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_load_sublayer_test_by_name(self):
"such",
"-v",
"--plugin=nose2.plugins.layers",
"test_such.having an expensive fixture." "should do more things",
"test_such.having an expensive fixture.should do more things",
)
self.assertTestRunOutputMatches(proc, stderr="Ran 1 test")
self.assertEqual(proc.poll(), 0, proc.stderr.getvalue())
Expand Down
6 changes: 3 additions & 3 deletions nose2/tests/unit/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _fromisoformat(date_str):
class TestJunitXmlPlugin(TestCase):
_RUN_IN_TEMP = True

BAD_FOR_XML_U = "A\x07 B\x0B C\x10 D\uD900 " "E\uFFFE F\x80 G\x90 H\uFDDD"
BAD_FOR_XML_U = "A\x07 B\x0B C\x10 D\uD900 E\uFFFE F\x80 G\x90 H\uFDDD"
# UTF-8 string with double null (invalid)
BAD_FOR_XML_B = (
b"A\x07 B\x0b C\x10 D\xed\xa4\x80 "
Expand Down Expand Up @@ -51,10 +51,10 @@ class TestJunitXmlPlugin(TestCase):
if sys.maxunicode <= 0xFFFF:
EXPECTED_RE = "^[\x09\x0A\x0D\x20\x21-\uD7FF\uE000-\uFFFD]*$"
EXPECTED_RE_SAFE = (
"^[\x09\x0A\x0D\x20\x21-\x7E\x85" "\xA0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD]*$"
"^[\x09\x0A\x0D\x20\x21-\x7E\x85\xA0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD]*$"
)
else:
EXPECTED_RE = "^[\x09\x0A\x0D\x20\x21-\uD7FF\uE000-\uFFFD" "\u10000-\u10FFFF]*$"
EXPECTED_RE = "^[\x09\x0A\x0D\x20\x21-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]*$"
EXPECTED_RE_SAFE = (
"^[\x09\x0A\x0D\x20\x21-\x7E\x85"
"\xA0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD"
Expand Down
6 changes: 3 additions & 3 deletions nose2/tests/unit/test_printhooks_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_traces_hooks_created_after_own_registration(self):
result = self.session.hooks.pluginHookA(event)
self.assertEqual(result, "TestPluginB.pluginHookA")
self.assertEqual(
"\n" "pluginHookA: " "CustomEvent(handled=False, args='args')",
"\npluginHookA: CustomEvent(handled=False, args='args')",
self.buf.getvalue(),
)

Expand All @@ -87,7 +87,7 @@ def test_traces_hooks_created_before_own_registration(self):
result = self.session.hooks.pluginHookA(event)
self.assertEqual(result, "TestPluginB.pluginHookA")
self.assertEqual(
"\n" "pluginHookA: " "CustomEvent(handled=False, args='args')",
"\npluginHookA: CustomEvent(handled=False, args='args')",
self.buf.getvalue(),
)

Expand All @@ -99,7 +99,7 @@ def test_traces_hooks_that_nobody_implements(self):
result = self.session.hooks.pluginHookA(event)
self.assertEqual(result, None)
self.assertEqual(
"\n" "pluginHookA: " "CustomEvent(handled=False, args='args')",
"\npluginHookA: CustomEvent(handled=False, args='args')",
self.buf.getvalue(),
)

Expand Down
2 changes: 1 addition & 1 deletion nose2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def is_not_base_class(c):
def safe_decode(string):
"""Safely decode a byte string into unicode"""
if string is None:
return string
return None
try:
return string.decode()
except AttributeError:
Expand Down
83 changes: 3 additions & 80 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,83 +59,6 @@ nose2 = "nose2:discover"
[tool.setuptools.dynamic]
version = {attr = "nose2.__version__"}

[tool.ruff]
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"C90", # McCabe cyclomatic complexity
"E", # pycodestyle
"EXE", # flake8-executable
"F", # Pyflakes
"I", # isort
"ICN", # flake8-import-conventions
"INT", # flake8-gettext
"PLE", # Pylint errors
"PLR091", # Pylint Refactor just for max-args, max-branches, etc.
"PYI", # flake8-pyi
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
# "A", # flake8-builtins
# "ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
# "BLE", # flake8-blind-except
# "COM", # flake8-commas
# "D", # pydocstyle
# "DJ", # flake8-django
# "DTZ", # flake8-datetimez
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "FBT", # flake8-boolean-trap
# "G", # flake8-logging-format
# "INP", # flake8-no-pep420
# "ISC", # flake8-implicit-str-concat
# "N", # pep8-naming
# "NPY", # NumPy-specific rules
# "PD", # pandas-vet
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PT", # flake8-pytest-style
# "PTH", # flake8-use-pathlib
# "Q", # flake8-quotes
# "RET", # flake8-return
# "S", # flake8-bandit
# "SIM", # flake8-simplify
# "SLF", # flake8-self
# "T10", # flake8-debugger
# "T20", # flake8-print
# "TRY", # tryceratops
]
ignore = [
"B904",
"RUF005",
"RUF012",
"RUF100"
]
target-version = "py37"

[tool.ruff.isort]
known-third-party = [
"coverage",
"mock",
]

[tool.ruff.mccabe]
max-complexity = 15

[tool.ruff.pylint]
max-args = 9
max-branches = 15
max-statements = 66

[tool.ruff.per-file-ignores]
"nose2/tests/*" = ["B011"]
# FIXME: resolving these could change behavior -- do it in a separate
# cleanup and note it in the changelog
"nose2/plugins/loader/*.py" = ["B004"]
"nose2/plugins/mp.py" = ["UP031"]
"nose2/tests/functional/support/such/test_regression_same_havings.py" = ["EXE001"]
[tool.isort]
profile = "black"
known_third_party = ["coverage", "mock"]

0 comments on commit 8cbde62

Please sign in to comment.