From f1a9af8b2853e4e78af12763ba1f13a41918fad7 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Thu, 21 Dec 2023 21:25:05 -0600 Subject: [PATCH] Update to pass 'slyp' linting --- nose2/main.py | 16 ++++++++++------ nose2/plugins/coverage.py | 6 ++++-- nose2/tests/functional/test_layers_plugin.py | 12 ++++++++---- nose2/tests/functional/test_loadtests_plugin.py | 4 ++-- nose2/tests/functional/test_such_dsl.py | 2 +- nose2/tests/unit/test_junitxml.py | 6 +++--- nose2/tests/unit/test_printhooks_plugin.py | 6 +++--- nose2/util.py | 2 +- 8 files changed, 32 insertions(+), 22 deletions(-) diff --git a/nose2/main.py b/nose2/main.py index d1de4ea3..1e9d8497 100644 --- a/nose2/main.py +++ b/nose2/main.py @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/nose2/plugins/coverage.py b/nose2/plugins/coverage.py index 2ea5e85a..544cbb98 100644 --- a/nose2/plugins/coverage.py +++ b/nose2/plugins/coverage.py @@ -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", diff --git a/nose2/tests/functional/test_layers_plugin.py b/nose2/tests/functional/test_layers_plugin.py index a533659b..566bc683 100644 --- a/nose2/tests/functional/test_layers_plugin.py +++ b/nose2/tests/functional/test_layers_plugin.py @@ -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) diff --git a/nose2/tests/functional/test_loadtests_plugin.py b/nose2/tests/functional/test_loadtests_plugin.py index def062e1..ddb25c28 100644 --- a/nose2/tests/functional/test_loadtests_plugin.py +++ b/nose2/tests/functional/test_loadtests_plugin.py @@ -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") @@ -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") diff --git a/nose2/tests/functional/test_such_dsl.py b/nose2/tests/functional/test_such_dsl.py index 95068cbc..91be869a 100644 --- a/nose2/tests/functional/test_such_dsl.py +++ b/nose2/tests/functional/test_such_dsl.py @@ -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()) diff --git a/nose2/tests/unit/test_junitxml.py b/nose2/tests/unit/test_junitxml.py index 63bd3d6e..88b571e2 100644 --- a/nose2/tests/unit/test_junitxml.py +++ b/nose2/tests/unit/test_junitxml.py @@ -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 " @@ -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" diff --git a/nose2/tests/unit/test_printhooks_plugin.py b/nose2/tests/unit/test_printhooks_plugin.py index c7e2c580..5af053a8 100644 --- a/nose2/tests/unit/test_printhooks_plugin.py +++ b/nose2/tests/unit/test_printhooks_plugin.py @@ -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(), ) @@ -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(), ) @@ -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(), ) diff --git a/nose2/util.py b/nose2/util.py index 8b08be41..78688371 100644 --- a/nose2/util.py +++ b/nose2/util.py @@ -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: