From 9679b5707d6a7825ab4666e994c274669945f4b3 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 6 Jul 2013 15:15:31 -0400 Subject: [PATCH] Add check for deprecated method assertEquals The proper one is assertEqual, assertEquals is deprecated as of 2.7. Of course, remembering which one is good and which one is bad is absolutely impossible. Change-Id: I79c5417ea2d11091ed7d73cf28c534feef6f7ba9 --- hacking/core.py | 16 ++++++++++++++++ setup.cfg | 1 + 2 files changed, 17 insertions(+) diff --git a/hacking/core.py b/hacking/core.py index b8b176d..69db6c2 100755 --- a/hacking/core.py +++ b/hacking/core.py @@ -639,6 +639,22 @@ def hacking_no_cr(physical_line): return (pos, "H601: Windows style line endings not allowed in code") +@flake8ext +def hacking_no_assert_equals(logical_line, tokens): + r"""assertEquals() is deprecated, use assertEqual instead. + + Okay: self.assertEqual(0, 0) + H602: self.assertEquals(0, 0) + """ + + for token_type, text, start_index, _, _ in tokens: + + if token_type == tokenize.NAME and text == "assertEquals": + yield ( + start_index[1], + "H602: assertEquals is deprecated, use assertEqual") + + FORMAT_RE = re.compile("%(?:" "%|" # Ignore plain percents "(\(\w+\))?" # mapping key diff --git a/setup.cfg b/setup.cfg index 00da505..7fa6974 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,7 @@ flake8.extension = H404 = hacking.core:hacking_docstring_multiline_start H501 = hacking.core:hacking_no_locals H601 = hacking.core:hacking_no_cr + H602 = hacking.core:hacking_no_assert_equals H700 = hacking.core:hacking_localization_strings H801 = hacking.core:OnceGitCheckCommitTitleBug H802 = hacking.core:OnceGitCheckCommitTitleLength