Browse Source

Fix hacking rule of assert_equal_or_not_none

The rule is not robust enough result in error code existing.
Fix the code and the rule.

Change-Id: I68934d4931a6e7857a824d0af5ed571a9c3e6480
Closes-bug: #1280522
tags/0.8.0
Bo Wang 3 years ago
parent
commit
15fdc0ea7b

+ 4
- 6
octavia/hacking/checks.py View File

@@ -67,14 +67,12 @@ assert_equal_with_true_re = re.compile(
67 67
 assert_equal_with_false_re = re.compile(
68 68
     r"assertEqual\(False,")
69 69
 mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
70
-assert_equal_end_with_none_re = re.compile(
71
-    r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)")
72
-assert_equal_start_with_none_re = re.compile(
73
-    r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
70
+assert_equal_end_with_none_re = re.compile(r"(.)*assertEqual\(.+, None\)")
71
+assert_equal_start_with_none_re = re.compile(r".*assertEqual\(None, .+\)")
74 72
 assert_not_equal_end_with_none_re = re.compile(
75
-    r"(.)*assertNotEqual\((\w|\.|\'|\"|\[|\])+, None\)")
73
+    r"(.)*assertNotEqual\(.+, None\)")
76 74
 assert_not_equal_start_with_none_re = re.compile(
77
-    r"(.)*assertNotEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
75
+    r"(.)*assertNotEqual\(None, .+\)")
78 76
 
79 77
 
80 78
 def _directory_to_check_translation(filename):

+ 1
- 1
octavia/tests/unit/cmd/test_house_keeping.py View File

@@ -110,7 +110,7 @@ class TestHouseKeepingCMD(base.TestCase):
110 110
         cert_rotate_event_mock.is_set = mock.MagicMock()
111 111
         cert_rotate_event_mock.is_set.side_effect = [True, None]
112 112
 
113
-        self.assertEqual(None, house_keeping.cert_rotation())
113
+        self.assertIsNone(house_keeping.cert_rotation())
114 114
 
115 115
         mock_CertRotation.assert_called_once_with()
116 116
         self.assertEqual(1, cert_rotate_mock.rotate.call_count)

+ 1
- 1
octavia/tests/unit/controller/housekeeping/test_house_keeping.py View File

@@ -175,7 +175,7 @@ class TestCertRotation(base.TestCase):
175 175
 
176 176
         cr = house_keeping.CertRotation()
177 177
 
178
-        self.assertEqual(None, cr.rotate())
178
+        self.assertIsNone(cr.rotate())
179 179
         amp_cert_mock.assert_called_once_with(AMPHORA_ID)
180 180
 
181 181
     @mock.patch('octavia.controller.worker.controller_worker.'

Loading…
Cancel
Save