summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-09-29 11:20:58 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-09-29 11:23:29 +0200
commita0dfabc4206d100d92dffd6f15e48c7b5e98b8e9 (patch)
treed3bb7bb82f9081163bc72f7adbc1f63f5a0c3f44
parentfd786ca1b81e2de9b05d3a6d8221bd08217ce310 (diff)
downloadpylint-git-a0dfabc4206d100d92dffd6f15e48c7b5e98b8e9.tar.gz
``deprecated-method`` is correctly emitted for ``assertEquals`` and friends.
Close #2226
-rw-r--r--ChangeLog7
-rw-r--r--pylint/checkers/stdlib.py9
-rw-r--r--pylint/test/functional/deprecated_methods_py2.py13
-rw-r--r--pylint/test/functional/deprecated_methods_py2.txt13
4 files changed, 34 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 836cb4421..562ec2c9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,8 +7,11 @@ What's New in Pylint 1.9.4?
Release date: |TBA|
- * Fixed false positive when a numpy Attributes section follows a Parameters
- section
+ * ``deprecated-method`` is correctly emitted for ``assertEquals`` and friends.
+
+ Close #2226
+
+ * Fixed false positive when a numpy Attributes section follows a Parameters section
Close #1867
diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py
index 37619cbb4..87124b43d 100644
--- a/pylint/checkers/stdlib.py
+++ b/pylint/checkers/stdlib.py
@@ -132,6 +132,13 @@ class StdlibChecker(BaseChecker):
'distutils.command.sdist.sdist.check_metadata',
'tkinter.Misc.tk_menuBar',
'tkinter.Menu.tk_bindForTraversal',
+
+ # These are aliases for `assertEqual` et al.
+ 'assertEquals',
+ 'assertNotEquals',
+ 'assertAlmostEquals',
+ 'assertNotAlmostEquals',
+ 'assert_',
],
2: {
(2, 6, 0): [
@@ -270,7 +277,7 @@ class StdlibChecker(BaseChecker):
return
qname = inferred.qname()
- if qname in self.deprecated[0]:
+ if any(name in self.deprecated[0] for name in (qname, func_name)):
self.add_message('deprecated-method', node=node,
args=(func_name, ))
else:
diff --git a/pylint/test/functional/deprecated_methods_py2.py b/pylint/test/functional/deprecated_methods_py2.py
index ceba1e4f9..08f80aeba 100644
--- a/pylint/test/functional/deprecated_methods_py2.py
+++ b/pylint/test/functional/deprecated_methods_py2.py
@@ -1,9 +1,20 @@
""" Functional test for deprecated methods in Python 2 """
-# pylint: disable=no-member
+# pylint: disable=no-member,missing-docstring
import os
import xml.etree.ElementTree
+import unittest
os.popen2('') # [deprecated-method]
os.popen3('') # [deprecated-method]
os.popen4('') # [deprecated-method]
xml.etree.ElementTree.Element('elem').getchildren() # [deprecated-method]
+
+
+class Tests(unittest.TestCase):
+
+ def test_foo(self):
+ self.assertEquals(2 + 2, 4) # [deprecated-method]
+ self.assertNotEquals(2 + 2, 4) # [deprecated-method]
+ self.assertAlmostEquals(2 + 2, 4) # [deprecated-method]
+ self.assertNotAlmostEquals(2 + 2, 4) # [deprecated-method]
+ self.assert_("abc" == "2") # [deprecated-method]
diff --git a/pylint/test/functional/deprecated_methods_py2.txt b/pylint/test/functional/deprecated_methods_py2.txt
index e1038185c..a09f4bd0a 100644
--- a/pylint/test/functional/deprecated_methods_py2.txt
+++ b/pylint/test/functional/deprecated_methods_py2.txt
@@ -1,4 +1,9 @@
-deprecated-method:6::Using deprecated method popen2()
-deprecated-method:7::Using deprecated method popen3()
-deprecated-method:8::Using deprecated method popen4()
-deprecated-method:9::Using deprecated method getchildren()
+deprecated-method:7::Using deprecated method popen2()
+deprecated-method:8::Using deprecated method popen3()
+deprecated-method:9::Using deprecated method popen4()
+deprecated-method:10::Using deprecated method getchildren()
+deprecated-method:16:Tests.test_foo:Using deprecated method assertEquals()
+deprecated-method:17:Tests.test_foo:Using deprecated method assertNotEquals()
+deprecated-method:18:Tests.test_foo:Using deprecated method assertAlmostEquals()
+deprecated-method:19:Tests.test_foo:Using deprecated method assertNotAlmostEquals()
+deprecated-method:20:Tests.test_foo:Using deprecated method assert_()