Use assertTrue/False instead of assertEqual(T/F)
The usage of assertEqual(True/False, ***) should be changed to a more meaningful format of assertTrue/False(***). Closes-Bug: #1510001 Change-Id: Ia16af467d5f5bfca029002d9d261540947b0be92
This commit is contained in:
parent
07a7dea318
commit
2eea193d77
@ -12,3 +12,5 @@ Magnum Specific Commandments
|
||||
- [M318] Change assertEqual(A, None) or assertEqual(None, A) by optimal assert
|
||||
like assertIsNone(A)
|
||||
- [M322] Method's default argument shouldn't be mutable.
|
||||
- [M323] Change assertEqual(True, A) or assertEqual(False, A) by optimal assert
|
||||
like assertTrue(A) or assertFalse(A)
|
||||
|
@ -37,6 +37,10 @@ asse_equal_end_with_none_re = re.compile(
|
||||
r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)")
|
||||
asse_equal_start_with_none_re = re.compile(
|
||||
r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
|
||||
assert_equal_with_true_re = re.compile(
|
||||
r"assertEqual\(True,")
|
||||
assert_equal_with_false_re = re.compile(
|
||||
r"assertEqual\(False,")
|
||||
|
||||
|
||||
def check_policy_enforce_decorator(logical_line,
|
||||
@ -68,7 +72,20 @@ def no_mutable_default_args(logical_line):
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
def assert_equal_true_or_false(logical_line):
|
||||
"""Check for assertEqual(True, A) or assertEqual(False, A) sentences
|
||||
|
||||
M323
|
||||
"""
|
||||
res = (assert_equal_with_true_re.search(logical_line) or
|
||||
assert_equal_with_false_re.search(logical_line))
|
||||
if res:
|
||||
yield (0, "M323: assertEqual(True, A) or assertEqual(False, A) "
|
||||
"sentences not allowed")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_policy_enforce_decorator)
|
||||
register(no_mutable_default_args)
|
||||
register(assert_equal_none)
|
||||
register(assert_equal_true_or_false)
|
||||
|
@ -272,7 +272,7 @@ class TestPatch(api_base.FunctionalTest):
|
||||
self.assertEqual(200, response.status_code)
|
||||
|
||||
response = self.get_json('/baymodels/%s' % self.baymodel.uuid)
|
||||
self.assertEqual(True, response['public'])
|
||||
self.assertTrue(response['public'])
|
||||
|
||||
@mock.patch.object(magnum_policy, 'enforce')
|
||||
def test_update_public_baymodel_fail(self, mock_policy):
|
||||
@ -668,7 +668,7 @@ class TestPost(api_base.FunctionalTest):
|
||||
'os_distro': 'fedora-atomic'}
|
||||
bdict = apiutils.baymodel_post_data(public=True)
|
||||
response = self.post_json('/baymodels', bdict)
|
||||
self.assertEqual(True, response.json['public'])
|
||||
self.assertTrue(response.json['public'])
|
||||
mock_policy.assert_called_with(mock.ANY, "baymodel:publish",
|
||||
None, do_raise=False)
|
||||
cc_mock.assert_called_once_with(mock.ANY)
|
||||
@ -706,7 +706,7 @@ class TestPost(api_base.FunctionalTest):
|
||||
'os_distro': 'fedora-atomic'}
|
||||
bdict = apiutils.baymodel_post_data(public=False)
|
||||
response = self.post_json('/baymodels', bdict)
|
||||
self.assertEqual(False, response.json['public'])
|
||||
self.assertFalse(response.json['public'])
|
||||
# policy enforcement is called only once for enforce_wsgi
|
||||
mock_policy.assert_called_once_with(mock.ANY, mock.ANY, None)
|
||||
cc_mock.assert_called_once_with(mock.ANY)
|
||||
|
@ -78,4 +78,4 @@ class ContextTestCase(base.TestCase):
|
||||
|
||||
def test_request_context_sets_is_admin(self):
|
||||
ctxt = magnum_context.make_admin_context()
|
||||
self.assertEqual(True, ctxt.is_admin)
|
||||
self.assertTrue(ctxt.is_admin)
|
||||
|
@ -21,4 +21,4 @@ class TestHandler(base.BaseTestCase):
|
||||
self.handler = conductor_listener.Handler()
|
||||
|
||||
def test_ping_conductor(self):
|
||||
self.assertEqual(True, self.handler.ping_conductor({}))
|
||||
self.assertTrue(self.handler.ping_conductor({}))
|
||||
|
@ -96,6 +96,21 @@ class HackingTestCase(base.TestCase):
|
||||
self.assertEqual(
|
||||
len(list(checks.assert_equal_none("self.assertIsNone()"))), 0)
|
||||
|
||||
def test_assert_equal_true_or_false(self):
|
||||
self.assertEqual(1, len(list(checks.assert_equal_true_or_false(
|
||||
"self.assertEqual(True, A)"))))
|
||||
|
||||
self.assertEqual(1, len(list(checks.assert_equal_true_or_false(
|
||||
"self.assertEqual(False, A)"))))
|
||||
|
||||
self.assertEqual(0,
|
||||
len(list(checks.assert_equal_true_or_false(
|
||||
"self.assertTrue()"))))
|
||||
|
||||
self.assertEqual(0,
|
||||
len(list(checks.assert_equal_true_or_false(
|
||||
"self.assertFalse()"))))
|
||||
|
||||
def test_no_mutable_default_args(self):
|
||||
self.assertEqual(1, len(list(checks.no_mutable_default_args(
|
||||
"def get_info_from_bdm(virt_type, bdm, mapping=[])"))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user