Merge "Use _assert_has_(no)_errors() in hacking tests"

This commit is contained in:
Jenkins 2015-11-04 19:15:56 +00:00 committed by Gerrit Code Review
commit d90bc0ef7d

View File

@ -87,88 +87,103 @@ class HackingTestCase(base.TestCase):
expected_errors=[(2, 0, "M301")]) expected_errors=[(2, 0, "M301")])
def test_assert_equal_in(self): def test_assert_equal_in(self):
self.assertEqual(1, len(list(checks.assert_equal_in( errors = [(1, 0, "M338")]
"self.assertEqual(a in b, True)")))) check = checks.assert_equal_in
self.assertEqual(1, len(list(checks.assert_equal_in( code = "self.assertEqual(a in b, True)"
"self.assertEqual('str' in 'string', True)")))) self._assert_has_errors(code, check, errors)
self.assertEqual(0, len(list(checks.assert_equal_in( code = "self.assertEqual('str' in 'string', True)"
"self.assertEqual(any(a==1 for a in b), True)")))) self._assert_has_errors(code, check, errors)
self.assertEqual(1, len(list(checks.assert_equal_in( code = "self.assertEqual(any(a==1 for a in b), True)"
"self.assertEqual(True, a in b)")))) self._assert_has_no_errors(code, check)
self.assertEqual(1, len(list(checks.assert_equal_in( code = "self.assertEqual(True, a in b)"
"self.assertEqual(True, 'str' in 'string')")))) self._assert_has_errors(code, check, errors)
self.assertEqual(0, len(list(checks.assert_equal_in( code = "self.assertEqual(True, 'str' in 'string')"
"self.assertEqual(True, any(a==1 for a in b))")))) self._assert_has_errors(code, check, errors)
self.assertEqual(1, len(list(checks.assert_equal_in( code = "self.assertEqual(True, any(a==1 for a in b))"
"self.assertEqual(a in b, False)")))) self._assert_has_no_errors(code, check)
self.assertEqual(1, len(list(checks.assert_equal_in( code = "self.assertEqual(a in b, False)"
"self.assertEqual('str' in 'string', False)")))) self._assert_has_errors(code, check, errors)
self.assertEqual(0, len(list(checks.assert_equal_in( code = "self.assertEqual('str' in 'string', False)"
"self.assertEqual(any(a==1 for a in b), False)")))) self._assert_has_errors(code, check, errors)
self.assertEqual(1, len(list(checks.assert_equal_in( code = "self.assertEqual(any(a==1 for a in b), False)"
"self.assertEqual(False, a in b)")))) self._assert_has_no_errors(code, check)
self.assertEqual(1, len(list(checks.assert_equal_in( code = "self.assertEqual(False, a in b)"
"self.assertEqual(False, 'str' in 'string')")))) self._assert_has_errors(code, check, errors)
self.assertEqual(0, len(list(checks.assert_equal_in( code = "self.assertEqual(False, 'str' in 'string')"
"self.assertEqual(False, any(a==1 for a in b))")))) self._assert_has_errors(code, check, errors)
code = "self.assertEqual(False, any(a==1 for a in b))"
self._assert_has_no_errors(code, check)
def test_assert_equal_none(self): def test_assert_equal_none(self):
self.assertEqual(len(list(checks.assert_equal_none( errors = [(1, 0, "M318")]
"self.assertEqual(A, None)"))), 1) check = checks.assert_equal_none
self.assertEqual(len(list(checks.assert_equal_none( code = "self.assertEqual(A, None)"
"self.assertEqual(None, A)"))), 1) self._assert_has_errors(code, check, errors)
self.assertEqual( code = "self.assertEqual(None, A)"
len(list(checks.assert_equal_none("self.assertIsNone()"))), 0) self._assert_has_errors(code, check, errors)
code = "self.assertIsNone()"
self._assert_has_no_errors(code, check)
def test_assert_equal_true_or_false(self): def test_assert_equal_true_or_false(self):
self.assertEqual(1, len(list(checks.assert_equal_true_or_false( errors = [(1, 0, "M323")]
"self.assertEqual(True, A)")))) check = checks.assert_equal_true_or_false
self.assertEqual(1, len(list(checks.assert_equal_true_or_false( code = "self.assertEqual(True, A)"
"self.assertEqual(False, A)")))) self._assert_has_errors(code, check, errors)
self.assertEqual(0, code = "self.assertEqual(False, A)"
len(list(checks.assert_equal_true_or_false( self._assert_has_errors(code, check, errors)
"self.assertTrue()"))))
self.assertEqual(0, code = "self.assertTrue()"
len(list(checks.assert_equal_true_or_false( self._assert_has_no_errors(code, check)
"self.assertFalse()"))))
code = "self.assertFalse()"
self._assert_has_no_errors(code, check)
def test_no_mutable_default_args(self): def test_no_mutable_default_args(self):
self.assertEqual(1, len(list(checks.no_mutable_default_args( errors = [(1, 0, "M322")]
"def get_info_from_bdm(virt_type, bdm, mapping=[])")))) check = checks.no_mutable_default_args
self.assertEqual(0, len(list(checks.no_mutable_default_args( code = "def get_info_from_bdm(virt_type, bdm, mapping=[])"
"defined = []")))) self._assert_has_errors(code, check, errors)
self.assertEqual(0, len(list(checks.no_mutable_default_args( code = "defined = []"
"defined, undefined = [], {}")))) self._assert_has_no_errors(code, check)
code = "defined, undefined = [], {}"
self._assert_has_no_errors(code, check)
def test_assert_is_not_none(self): def test_assert_is_not_none(self):
self.assertEqual(1, len(list(checks.assert_equal_not_none( errors = [(1, 0, "M302")]
"self.assertEqual(A is not None)")))) check = checks.assert_equal_not_none
self.assertEqual(0, len(list(checks.assert_equal_not_none( code = "self.assertEqual(A is not None)"
"self.assertIsNone()")))) self._assert_has_errors(code, check, errors)
code = "self.assertIsNone()"
self._assert_has_no_errors(code, check)
def test_assert_true_isinstance(self): def test_assert_true_isinstance(self):
self.assertEqual(1, len(list(checks.assert_true_isinstance( errors = [(1, 0, "M316")]
"self.assertTrue(isinstance(e, " check = checks.assert_true_isinstance
"exception.BuildAbortException))"))))
self.assertEqual(0, len(list(checks.assert_true_isinstance( code = "self.assertTrue(isinstance(e, exception.BuilAbortException))"
"self.assertTrue()")))) self._assert_has_errors(code, check, errors)
code = "self.assertTrue()"
self._assert_has_no_errors(code, check)