Add check for deprecated method assert_

The proper one is assertTrue, assert_ is deprecated as of 2.7.

There were some projects using assert_().
https://review.openstack.org/#/c/44456/

This patch will prevent code from deteriorating.

Change-Id: Id6f0ed85eb62d6ea9a1f352427882743cc3a7101
This commit is contained in:
Zhongyue Luo 2013-09-10 10:14:17 +08:00
parent 745d188372
commit a83cdc6df3
2 changed files with 17 additions and 0 deletions

View File

@ -687,6 +687,22 @@ def hacking_no_assert_equals(logical_line, tokens):
"H602: assertEquals is deprecated, use assertEqual")
@flake8ext
def hacking_no_assert_underscore(logical_line, tokens):
r"""assert_() is deprecated, use assertTrue instead.
Okay: self.assertTrue(foo)
H603: self.assert_(foo)
"""
for token_type, text, start_index, _, _ in tokens:
if token_type == tokenize.NAME and text == "assert_":
yield (
start_index[1],
"H603: assert_ is deprecated, use assertTrue")
FORMAT_RE = re.compile("%(?:"
"%|" # Ignore plain percents
"(\(\w+\))?" # mapping key

View File

@ -40,6 +40,7 @@ flake8.extension =
H501 = hacking.core:hacking_no_locals
H601 = hacking.core:hacking_no_cr
H602 = hacking.core:hacking_no_assert_equals
H603 = hacking.core:hacking_no_assert_underscore
H700 = hacking.core:hacking_localization_strings
H801 = hacking.core:OnceGitCheckCommitTitleBug
H802 = hacking.core:OnceGitCheckCommitTitleLength