Update assertTrue/False to Python 3 precise asserts (#8792)

* Update assertTrue/False to Python 3 precise asserts

* Fix test failures

* Fix test failures

* More replacements

* Update to Python 3 asserts in acme-module

* Fix Windows test failure

* Fix failures

* Fix test failure

* More replacements

* Don't include the semgrep rules

* Fix test failure
This commit is contained in:
Mads Jensen
2021-04-29 10:45:08 +10:00
committed by GitHub
parent f339d23e54
commit 2cf1775864
41 changed files with 444 additions and 452 deletions
+4 -4
View File
@@ -50,12 +50,12 @@ class CompleterTest(test_util.TempDirTestCase):
for i in range(num_paths):
completion = my_completer.complete(self.tempdir, i)
self.assertTrue(completion in self.paths)
self.assertIn(completion, self.paths)
self.paths.remove(completion)
self.assertFalse(self.paths)
self.assertEqual(len(self.paths), 0)
completion = my_completer.complete(self.tempdir, num_paths)
self.assertEqual(completion, None)
self.assertIsNone(completion)
@unittest.skipIf('readline' not in sys.modules,
reason='Not relevant if readline is not available.')
@@ -98,7 +98,7 @@ class CompleterTest(test_util.TempDirTestCase):
with completer.Completer():
pass
self.assertTrue(mock_readline.parse_and_bind.called)
self.assertIs(mock_readline.parse_and_bind.called, True)
def enable_tab_completion(unused_command):
+12 -14
View File
@@ -61,9 +61,9 @@ class GetEmailTest(unittest.TestCase):
with mock.patch("certbot.display.ops.util.safe_email") as mock_safe_email:
mock_safe_email.return_value = True
self._call()
self.assertTrue(invalid_txt not in mock_input.call_args[0][0])
self.assertNotIn(invalid_txt, mock_input.call_args[0][0])
self._call(invalid=True)
self.assertTrue(invalid_txt in mock_input.call_args[0][0])
self.assertIn(invalid_txt, mock_input.call_args[0][0])
@test_util.patch_get_utility("certbot.display.ops.z_util")
def test_optional_flag(self, mock_get_utility):
@@ -73,8 +73,7 @@ class GetEmailTest(unittest.TestCase):
mock_safe_email.side_effect = [False, True]
self._call(optional=False)
for call in mock_input.call_args_list:
self.assertTrue(
"--register-unsafely-without-email" not in call[0][0])
self.assertNotIn("--register-unsafely-without-email", call[0][0])
@test_util.patch_get_utility("certbot.display.ops.z_util")
def test_optional_invalid_unsafe(self, mock_get_utility):
@@ -84,7 +83,7 @@ class GetEmailTest(unittest.TestCase):
with mock.patch("certbot.display.ops.util.safe_email") as mock_safe_email:
mock_safe_email.side_effect = [False, True]
self._call(invalid=True)
self.assertTrue(invalid_txt in mock_input.call_args[0][0])
self.assertIn(invalid_txt, mock_input.call_args[0][0])
class ChooseAccountTest(test_util.TempDirTestCase):
@@ -128,7 +127,7 @@ class ChooseAccountTest(test_util.TempDirTestCase):
@test_util.patch_get_utility("certbot.display.ops.z_util")
def test_cancel(self, mock_util):
mock_util().menu.return_value = (display_util.CANCEL, 1)
self.assertTrue(self._call([self.acc1, self.acc2]) is None)
self.assertIsNone(self._call([self.acc1, self.acc2]))
class GenHttpsNamesTest(unittest.TestCase):
@@ -210,8 +209,7 @@ class ChooseNamesTest(unittest.TestCase):
actual_doms = self._call(self.mock_install)
self.assertEqual(mock_util().input.call_count, 1)
self.assertEqual(actual_doms, [domain])
self.assertTrue(
"configuration files" in mock_util().input.call_args[0][0])
self.assertIn("configuration files", mock_util().input.call_args[0][0])
def test_sort_names_trivial(self):
from certbot.display.ops import _sort_names
@@ -353,7 +351,7 @@ class SuccessInstallationTest(unittest.TestCase):
arg = mock_util().notification.call_args_list[0][0][0]
for name in names:
self.assertTrue(name in arg)
self.assertIn(name, arg)
class SuccessRenewalTest(unittest.TestCase):
@@ -374,7 +372,7 @@ class SuccessRenewalTest(unittest.TestCase):
arg = mock_util().notification.call_args_list[0][0][0]
for name in names:
self.assertTrue(name in arg)
self.assertIn(name, arg)
class SuccessRevocationTest(unittest.TestCase):
"""Test the success revocation message."""
@@ -478,8 +476,8 @@ class ChooseValuesTest(unittest.TestCase):
mock_util().checklist.return_value = (display_util.OK, [items[2]])
result = self._call(items, None)
self.assertEqual(result, [items[2]])
self.assertTrue(mock_util().checklist.called)
self.assertEqual(mock_util().checklist.call_args[0][0], None)
self.assertIs(mock_util().checklist.called, True)
self.assertIsNone(mock_util().checklist.call_args[0][0])
@test_util.patch_get_utility("certbot.display.ops.z_util")
def test_choose_names_success_question(self, mock_util):
@@ -488,7 +486,7 @@ class ChooseValuesTest(unittest.TestCase):
mock_util().checklist.return_value = (display_util.OK, [items[1]])
result = self._call(items, question)
self.assertEqual(result, [items[1]])
self.assertTrue(mock_util().checklist.called)
self.assertIs(mock_util().checklist.called, True)
self.assertEqual(mock_util().checklist.call_args[0][0], question)
@test_util.patch_get_utility("certbot.display.ops.z_util")
@@ -498,7 +496,7 @@ class ChooseValuesTest(unittest.TestCase):
mock_util().checklist.return_value = (display_util.CANCEL, [])
result = self._call(items, question)
self.assertEqual(result, [])
self.assertTrue(mock_util().checklist.called)
self.assertIs(mock_util().checklist.called, True)
self.assertEqual(mock_util().checklist.call_args[0][0], question)
+11 -10
View File
@@ -74,7 +74,7 @@ class FileOutputDisplayTest(unittest.TestCase):
self.displayer.notification("message", False)
string = self.mock_stdout.write.call_args[0][0]
self.assertTrue("message" in string)
self.assertIn("message", string)
mock_logger.debug.assert_called_with("Notifying user: %s", "message")
def test_notification_pause(self):
@@ -82,25 +82,25 @@ class FileOutputDisplayTest(unittest.TestCase):
with mock.patch(input_with_timeout, return_value="enter"):
self.displayer.notification("message", force_interactive=True)
self.assertTrue("message" in self.mock_stdout.write.call_args[0][0])
self.assertIn("message", self.mock_stdout.write.call_args[0][0])
def test_notification_noninteractive(self):
self._force_noninteractive(self.displayer.notification, "message")
string = self.mock_stdout.write.call_args[0][0]
self.assertTrue("message" in string)
self.assertIn("message", string)
def test_notification_noninteractive2(self):
# The main purpose of this test is to make sure we only call
# logger.warning once which _force_noninteractive checks internally
self._force_noninteractive(self.displayer.notification, "message")
string = self.mock_stdout.write.call_args[0][0]
self.assertTrue("message" in string)
self.assertIn("message", string)
self.assertTrue(self.displayer.skipped_interaction)
self._force_noninteractive(self.displayer.notification, "message2")
string = self.mock_stdout.write.call_args[0][0]
self.assertTrue("message2" in string)
self.assertIn("message2", string)
def test_notification_decoration(self):
from certbot.compat import os
@@ -110,7 +110,8 @@ class FileOutputDisplayTest(unittest.TestCase):
self.displayer.notification("message2", pause=False)
string = self.mock_stdout.write.call_args[0][0]
self.assertTrue("- - - " in string and ("message2" + os.linesep) in string)
self.assertIn("- - - ", string)
self.assertIn("message2" + os.linesep, string)
@mock.patch("certbot.display.util."
"FileDisplay._get_valid_int_ans")
@@ -265,7 +266,7 @@ class FileOutputDisplayTest(unittest.TestCase):
result = func(*args, **kwargs)
if skipped_interaction:
self.assertFalse(mock_logger.warning.called)
self.assertIs(mock_logger.warning.called, False)
else:
self.assertEqual(mock_logger.warning.call_count, 1)
@@ -331,7 +332,7 @@ class FileOutputDisplayTest(unittest.TestCase):
# force_interactive to prevent workflow regressions.
for name in interfaces.IDisplay.names():
arg_spec = inspect.getfullargspec(getattr(self.displayer, name))
self.assertTrue("force_interactive" in arg_spec.args)
self.assertIn("force_interactive", arg_spec.args)
class NoninteractiveDisplayTest(unittest.TestCase):
@@ -345,7 +346,7 @@ class NoninteractiveDisplayTest(unittest.TestCase):
self.displayer.notification("message", 10)
string = self.mock_stdout.write.call_args[0][0]
self.assertTrue("message" in string)
self.assertIn("message", string)
mock_logger.debug.assert_called_with("Notifying user: %s", "message")
def test_notification_decoration(self):
@@ -401,7 +402,7 @@ class NoninteractiveDisplayTest(unittest.TestCase):
method = getattr(self.displayer, name)
# asserts method accepts arbitrary keyword arguments
result = inspect.getfullargspec(method).varkw
self.assertFalse(result is None)
self.assertIsNotNone(result)
class SeparateListInputTest(unittest.TestCase):