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
+20 -20
View File
@@ -157,17 +157,17 @@ class UmaskTest(TempDirTestCase):
try:
dir1 = os.path.join(self.tempdir, 'probe1')
filesystem.mkdir(dir1)
self.assertTrue(filesystem.check_mode(dir1, 0o755))
self.assertIs(filesystem.check_mode(dir1, 0o755), True)
filesystem.umask(0o077)
dir2 = os.path.join(self.tempdir, 'dir2')
filesystem.mkdir(dir2)
self.assertTrue(filesystem.check_mode(dir2, 0o700))
self.assertIs(filesystem.check_mode(dir2, 0o700), True)
dir3 = os.path.join(self.tempdir, 'dir3')
filesystem.mkdir(dir3, mode=0o777)
self.assertTrue(filesystem.check_mode(dir3, 0o700))
self.assertIs(filesystem.check_mode(dir3, 0o700), True)
finally:
filesystem.umask(previous_umask)
@@ -177,17 +177,17 @@ class UmaskTest(TempDirTestCase):
try:
file1 = os.path.join(self.tempdir, 'probe1')
UmaskTest._create_file(file1)
self.assertTrue(filesystem.check_mode(file1, 0o755))
self.assertIs(filesystem.check_mode(file1, 0o755), True)
filesystem.umask(0o077)
file2 = os.path.join(self.tempdir, 'probe2')
UmaskTest._create_file(file2)
self.assertTrue(filesystem.check_mode(file2, 0o700))
self.assertIs(filesystem.check_mode(file2, 0o700), True)
file3 = os.path.join(self.tempdir, 'probe3')
UmaskTest._create_file(file3)
self.assertTrue(filesystem.check_mode(file3, 0o700))
self.assertIs(filesystem.check_mode(file3, 0o700), True)
finally:
filesystem.umask(previous_umask)
@@ -400,7 +400,7 @@ class CopyOwnershipAndModeTest(test_util.TempDirTestCase):
util.safe_open(path1, 'w').close()
util.safe_open(path2, 'w').close()
self.assertTrue(filesystem.has_same_ownership(path1, path2))
self.assertIs(filesystem.has_same_ownership(path1, path2), True)
@unittest.skipIf(POSIX_MODE, reason='Test specific to Windows security')
def test_copy_ownership_and_mode_windows(self):
@@ -408,8 +408,8 @@ class CopyOwnershipAndModeTest(test_util.TempDirTestCase):
dst = _create_probe(self.tempdir, name='dst')
filesystem.chmod(src, 0o700)
self.assertTrue(filesystem.check_mode(src, 0o700))
self.assertTrue(filesystem.check_mode(dst, 0o744))
self.assertIs(filesystem.check_mode(src, 0o700), True)
self.assertIs(filesystem.check_mode(dst, 0o744), True)
# Checking an actual change of owner is tricky during a unit test, since we do not know
# if any user exists beside the current one. So we mock _copy_win_ownership. It's behavior
@@ -418,7 +418,7 @@ class CopyOwnershipAndModeTest(test_util.TempDirTestCase):
filesystem.copy_ownership_and_mode(src, dst)
mock_copy_owner.assert_called_once_with(src, dst)
self.assertTrue(filesystem.check_mode(dst, 0o700))
self.assertIs(filesystem.check_mode(dst, 0o700), True)
class CheckPermissionsTest(test_util.TempDirTestCase):
@@ -428,14 +428,14 @@ class CheckPermissionsTest(test_util.TempDirTestCase):
self.probe_path = _create_probe(self.tempdir)
def test_check_mode(self):
self.assertTrue(filesystem.check_mode(self.probe_path, 0o744))
self.assertIs(filesystem.check_mode(self.probe_path, 0o744), True)
filesystem.chmod(self.probe_path, 0o700)
self.assertFalse(filesystem.check_mode(self.probe_path, 0o744))
@unittest.skipIf(POSIX_MODE, reason='Test specific to Windows security')
def test_check_owner_windows(self):
self.assertTrue(filesystem.check_owner(self.probe_path))
self.assertIs(filesystem.check_owner(self.probe_path), True)
system = win32security.ConvertStringSidToSid(SYSTEM_SID)
security = win32security.SECURITY_ATTRIBUTES().SECURITY_DESCRIPTOR
@@ -447,7 +447,7 @@ class CheckPermissionsTest(test_util.TempDirTestCase):
@unittest.skipUnless(POSIX_MODE, reason='Test specific to Linux security')
def test_check_owner_linux(self):
self.assertTrue(filesystem.check_owner(self.probe_path))
self.assertIs(filesystem.check_owner(self.probe_path), True)
import os as std_os # pylint: disable=os-module-forbidden
# See related inline comment in certbot.compat.filesystem.check_owner method
@@ -459,7 +459,7 @@ class CheckPermissionsTest(test_util.TempDirTestCase):
self.assertFalse(filesystem.check_owner(self.probe_path))
def test_check_permissions(self):
self.assertTrue(filesystem.check_permissions(self.probe_path, 0o744))
self.assertIs(filesystem.check_permissions(self.probe_path, 0o744), True)
with mock.patch('certbot.compat.filesystem.check_mode') as mock_mode:
mock_mode.return_value = False
@@ -471,7 +471,7 @@ class CheckPermissionsTest(test_util.TempDirTestCase):
def test_check_min_permissions(self):
filesystem.chmod(self.probe_path, 0o744)
self.assertTrue(filesystem.has_min_permissions(self.probe_path, 0o744))
self.assertIs(filesystem.has_min_permissions(self.probe_path, 0o744), True)
filesystem.chmod(self.probe_path, 0o700)
self.assertFalse(filesystem.has_min_permissions(self.probe_path, 0o744))
@@ -481,7 +481,7 @@ class CheckPermissionsTest(test_util.TempDirTestCase):
def test_is_world_reachable(self):
filesystem.chmod(self.probe_path, 0o744)
self.assertTrue(filesystem.has_world_permissions(self.probe_path))
self.assertIs(filesystem.has_world_permissions(self.probe_path), True)
filesystem.chmod(self.probe_path, 0o700)
self.assertFalse(filesystem.has_world_permissions(self.probe_path))
@@ -500,7 +500,7 @@ class OsReplaceTest(test_util.TempDirTestCase):
filesystem.replace(src, dst)
self.assertFalse(os.path.exists(src))
self.assertTrue(os.path.exists(dst))
self.assertIs(os.path.exists(dst), True)
class RealpathTest(test_util.TempDirTestCase):
@@ -542,7 +542,7 @@ class RealpathTest(test_util.TempDirTestCase):
with self.assertRaises(RuntimeError) as error:
filesystem.realpath(link1_path)
self.assertTrue('link1 is a loop!' in str(error.exception))
self.assertIn('link1 is a loop!', str(error.exception))
class IsExecutableTest(test_util.TempDirTestCase):
@@ -578,7 +578,7 @@ class IsExecutableTest(test_util.TempDirTestCase):
with _fix_windows_runtime():
mock_access.return_value = True
mock_isfile.return_value = True
self.assertTrue(filesystem.is_executable("/path/to/exe"))
self.assertIs(filesystem.is_executable("/path/to/exe"), True)
@mock.patch("certbot.compat.filesystem.os.path.isfile")
@mock.patch("certbot.compat.filesystem.os.access")
@@ -586,7 +586,7 @@ class IsExecutableTest(test_util.TempDirTestCase):
with _fix_windows_runtime():
mock_access.return_value = True
mock_isfile.return_value = True
self.assertTrue(filesystem.is_executable("exe"))
self.assertIs(filesystem.is_executable("exe"), True)
@mock.patch("certbot.compat.filesystem.os.path.isfile")
@mock.patch("certbot.compat.filesystem.os.access")
+1 -1
View File
@@ -45,4 +45,4 @@ class ExecuteTest(unittest.TestCase):
mock_logger.info.assert_any_call(mock.ANY, mock.ANY,
mock.ANY, stdout)
if stderr or returncode:
self.assertTrue(mock_logger.error.called)
self.assertIs(mock_logger.error.called, True)