From 8ec9fc6b890437cc0f0c1aec39b0d1720c7e4248 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 16 Nov 2019 10:28:22 +0000 Subject: [PATCH 1/3] Fix some unused functions in tests Whilst developing https://github.com/PyCQA/pyflakes/pull/485 I ran it against the CPython code base and found these examples of unused functions that I think need fixing. --- Lib/distutils/tests/support.py | 2 -- Lib/test/test_asynchat.py | 14 +++++++------- Lib/test/test_buffer.py | 2 -- Lib/test/test_builtin.py | 1 + Lib/test/test_code.py | 2 +- .../import_/test_relative_imports.py | 1 + Lib/unittest/test/testmock/testasync.py | 1 + Tools/ccbench/ccbench.py | 7 ------- 8 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py index 041309851d0f39..259af882ec0e96 100644 --- a/Lib/distutils/tests/support.py +++ b/Lib/distutils/tests/support.py @@ -39,8 +39,6 @@ def _log(self, level, msg, args): self.logs.append((level, msg, args)) def get_logs(self, *levels): - def _format(msg, args): - return msg % args return [msg % args for level, msg, args in self.logs if level in levels] diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py index 14c0ec43d422ea..74041ed58ef702 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -73,14 +73,14 @@ def __init__(self, terminator, server_port): self.set_terminator(terminator) self.buffer = b"" - def handle_connect(self): - pass + def handle_connect(self): + pass - if sys.platform == 'darwin': - # select.poll returns a select.POLLHUP at the end of the tests - # on darwin, so just ignore it - def handle_expt(self): - pass + if sys.platform == 'darwin': + # select.poll returns a select.POLLHUP at the end of the tests + # on darwin, so just ignore it + def handle_expt(self): + pass def collect_incoming_data(self, data): self.buffer += data diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index 5fa52bffc22be7..0aa78016f5d1ac 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -969,8 +969,6 @@ def check_memoryview(m, expected_readonly=readonly): m.tobytes() # Releasing mm didn't release m def verify_getbuf(self, orig_ex, ex, req, sliced=False): - def simple_fmt(ex): - return ex.format == '' or ex.format == 'B' def match(req, flag): return ((req&flag) == flag) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index abccf322274448..6a88454289d347 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -765,6 +765,7 @@ def test_hash(self): self.assertEqual(hash('spam'), hash(b'spam')) hash((0,1,2,3)) def f(): pass + hash(f) self.assertRaises(TypeError, hash, []) self.assertRaises(TypeError, hash, {}) # Bug 1536021: Allow hash to return long objects diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 0d80af44d9f1ff..656c46cfaa757a 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -241,7 +241,7 @@ def func(): def func2(): y = 2 return y - code2 = func.__code__ + code2 = func2.__code__ for attr, value in ( ("co_argcount", 0), diff --git a/Lib/test/test_importlib/import_/test_relative_imports.py b/Lib/test/test_importlib/import_/test_relative_imports.py index 586a9bf4bc1215..41aa18269952fa 100644 --- a/Lib/test/test_importlib/import_/test_relative_imports.py +++ b/Lib/test/test_importlib/import_/test_relative_imports.py @@ -133,6 +133,7 @@ def callback(global_): self.assertEqual(module.__name__, 'pkg') self.assertTrue(hasattr(module, 'subpkg2')) self.assertEqual(module.subpkg2.attr, 'pkg.subpkg2.__init__') + self.relative_import_test(create, globals_, callback) def test_deep_import(self): # [deep import] diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py index 6b2d49d3e44d27..0d2cdb0069ff7d 100644 --- a/Lib/unittest/test/testmock/testasync.py +++ b/Lib/unittest/test/testmock/testasync.py @@ -335,6 +335,7 @@ def test_is_AsyncMock_patch(self): @patch.object(AsyncClass, 'async_method', spec_set=True) def test_async(async_method): self.assertIsInstance(async_method, AsyncMock) + test_async() def test_is_async_AsyncMock(self): mock = AsyncMock(spec_set=AsyncClass.async_method) diff --git a/Tools/ccbench/ccbench.py b/Tools/ccbench/ccbench.py index 4f77a65f4d779b..ab1465a2760923 100644 --- a/Tools/ccbench/ccbench.py +++ b/Tools/ccbench/ccbench.py @@ -84,13 +84,6 @@ def task_regex(): pat = re.compile(r'^(\s*def\s)|(.*(? Date: Mon, 18 Nov 2019 22:10:56 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst diff --git a/Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst b/Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst new file mode 100644 index 00000000000000..d207d534465797 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst @@ -0,0 +1 @@ +Fix some unused functions in tests \ No newline at end of file From 41b62c455a8038439b3b1deaa9ce2c47a2ea5df2 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 18 Nov 2019 22:49:00 +0000 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst Co-Authored-By: Brett Cannon <54418+brettcannon@users.noreply.github.com> --- Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst b/Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst index d207d534465797..80c5a5bdfbba65 100644 --- a/Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst +++ b/Misc/NEWS.d/next/Tests/2019-11-18-22-10-55.bpo-38839.di6tXv.rst @@ -1 +1 @@ -Fix some unused functions in tests \ No newline at end of file +Fix some unused functions in tests. Patch by Adam Johnson.