add hacking check for assertEquals(True/False)
Depends-On: Ia675c6d74ec947729d4520007eac1423cdf58ce9 Change-Id: Ie116bc25be0c84fb9c0ef7423dd3a52b6bad47f7
This commit is contained in:
parent
040fcef196
commit
26478fea19
@ -18,4 +18,5 @@ Vitrage Specific Commandments
|
||||
[V325] Use six.iterkeys() or dict.keys() instead of dict.iterkeys()
|
||||
[V326] Use six.itervalues() or dict.values instead of dict.itervalues()
|
||||
[V327] Method's default argument shouldn't be mutable
|
||||
[V328] Disallow LOG.warn
|
||||
[V328] Disallow LOG.warn
|
||||
[V329] Don't use assertEqual(True/False, observed).
|
@ -144,8 +144,29 @@ def no_log_warn(logical_line):
|
||||
yield(0, 'V328: Use LOG.warning() rather than LOG.warn()')
|
||||
|
||||
|
||||
def check_assert_true_false(logical_line):
|
||||
"""V329 - Don't use assertEqual(True/False, observed)."""
|
||||
if re.search(r"assertEqual\(\s*True,[^,]*(,[^,]*)?", logical_line):
|
||||
msg = ("V329: Use assertTrue(observed) instead of "
|
||||
"assertEqual(True, observed)")
|
||||
yield (0, msg)
|
||||
if re.search(r"assertEqual\([^,]*,\s*True(,[^,]*)?", logical_line):
|
||||
msg = ("V329: Use assertTrue(observed) instead of "
|
||||
"assertEqual(True, observed)")
|
||||
yield (0, msg)
|
||||
if re.search(r"assertEqual\(\s*False,[^,]*(,[^,]*)?", logical_line):
|
||||
msg = ("V329: Use assertFalse(observed) instead of "
|
||||
"assertEqual(False, observed)")
|
||||
yield (0, msg)
|
||||
if re.search(r"assertEqual\([^,]*,\s*False(,[^,]*)?", logical_line):
|
||||
msg = ("V329: Use assertFalse(observed) instead of "
|
||||
"assertEqual(False, observed)")
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(assert_true_instance)
|
||||
register(check_assert_true_false)
|
||||
register(assert_equal_type)
|
||||
register(assert_equal_none)
|
||||
register(no_translate_logs)
|
||||
|
@ -413,7 +413,7 @@ class TestApis(TestEntityGraphUnitBase):
|
||||
condition = condition and \
|
||||
(not tmp_project_id or
|
||||
(tmp_project_id and tmp_project_id == project_id))
|
||||
self.assertEqual(True, condition)
|
||||
self.assertTrue(condition)
|
||||
|
||||
def _check_resource_properties(self, resource, vitrage_id,
|
||||
resource_type, project_id=None):
|
||||
|
@ -548,8 +548,8 @@ class TestFilter(base.BaseTest):
|
||||
"HOST.NAME}",
|
||||
"host": "some_host_kukoo"
|
||||
}
|
||||
self.assertEqual(True, check_filter(data=event_properties,
|
||||
attr_filter=attr_filter))
|
||||
self.assertTrue(check_filter(data=event_properties,
|
||||
attr_filter=attr_filter))
|
||||
|
||||
def test_basic_regex_with_no_match(self):
|
||||
event_properties = {
|
||||
@ -566,5 +566,5 @@ class TestFilter(base.BaseTest):
|
||||
"HOST.NAME}",
|
||||
"host": "some_host_kukoo"
|
||||
}
|
||||
self.assertEqual(False, check_filter(data=event_properties,
|
||||
attr_filter=attr_filter))
|
||||
self.assertFalse(check_filter(data=event_properties,
|
||||
attr_filter=attr_filter))
|
||||
|
@ -157,13 +157,50 @@ class HackingTestCase(base.BaseTest):
|
||||
self.assertEqual(0, len(list(checks.no_log_warn('LOG.warning("bl")'))))
|
||||
self.assertEqual(1, len(list(checks.no_log_warn('LOG.warn("foo")'))))
|
||||
|
||||
def test_asserttruefalse(self):
|
||||
true_fail_code1 = """
|
||||
test_bool = True
|
||||
self.assertEqual(True, test_bool)
|
||||
"""
|
||||
true_fail_code2 = """
|
||||
test_bool = True
|
||||
self.assertEqual(test_bool, True)
|
||||
"""
|
||||
true_pass_code = """
|
||||
test_bool = True
|
||||
self.assertTrue(test_bool)
|
||||
"""
|
||||
false_fail_code1 = """
|
||||
test_bool = False
|
||||
self.assertEqual(False, test_bool)
|
||||
"""
|
||||
false_fail_code2 = """
|
||||
test_bool = False
|
||||
self.assertEqual(test_bool, False)
|
||||
"""
|
||||
false_pass_code = """
|
||||
test_bool = False
|
||||
self.assertFalse(test_bool)
|
||||
"""
|
||||
self.assertEqual(1, len(
|
||||
list(checks.check_assert_true_false(true_fail_code1))))
|
||||
self.assertEqual(1, len(
|
||||
list(checks.check_assert_true_false(true_fail_code2))))
|
||||
self.assertEqual(0, len(
|
||||
list(checks.check_assert_true_false(true_pass_code))))
|
||||
self.assertEqual(1, len(
|
||||
list(checks.check_assert_true_false(false_fail_code1))))
|
||||
self.assertEqual(1, len(
|
||||
list(checks.check_assert_true_false(false_fail_code2))))
|
||||
self.assertFalse(list(checks.check_assert_true_false(false_pass_code)))
|
||||
|
||||
def test_factory(self):
|
||||
class Register(object):
|
||||
def __init__(self):
|
||||
self.funcs = []
|
||||
|
||||
def __call__(self, func):
|
||||
self.funcs.append(func)
|
||||
def __call__(self, _func):
|
||||
self.funcs.append(_func)
|
||||
|
||||
register = Register()
|
||||
checks.factory(register)
|
||||
|
@ -382,7 +382,7 @@ class JaccardCorrelationTest(base.BaseTest):
|
||||
str(now) + "_correlations_test.out"
|
||||
is_file = os.path.isfile(file_path)
|
||||
|
||||
self.assertEqual(is_file, True)
|
||||
self.assertTrue(is_file)
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
os.remove(file_path)
|
||||
|
@ -69,8 +69,6 @@ class TestActionsBase(BaseVitrageTempest):
|
||||
g_utils.first_match(rca['nodes'], **expected_alarm),
|
||||
'expected_alarm is not in the rca %s' % str(expected_alarm))
|
||||
rca_inspected = rca['nodes'][rca['inspected_index']]
|
||||
self.assertEqual(
|
||||
True,
|
||||
g_utils.is_subset(inspected, rca_inspected),
|
||||
'Invalid inspected item \n%s\n%s' %
|
||||
(str(rca_inspected), str(inspected)))
|
||||
self.assertTrue(g_utils.is_subset(inspected, rca_inspected),
|
||||
'Invalid inspected item \n%s\n%s' %
|
||||
(str(rca_inspected), str(inspected)))
|
||||
|
@ -176,7 +176,7 @@ class TestBasicActions(TestActionsBase):
|
||||
alarms = TempestClients.vitrage().alarm.list(
|
||||
vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
|
||||
all_tenants=True)
|
||||
self.assertEqual(True, len(alarms) >= 2, 'alarms %s' % str(alarms))
|
||||
self.assertTrue(len(alarms) >= 2, 'alarms %s' % str(alarms))
|
||||
|
||||
deduced = g_utils.first_match(alarms, **DEDUCED_PROPS)
|
||||
trigger = g_utils.first_match(alarms, **TRIGGER_ALARM_2_PROPS)
|
||||
|
Loading…
Reference in New Issue
Block a user