diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index bae04033a..f05e529dd 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -585,10 +585,10 @@ class AllPlatformTests(BasePlatformTests): self._run, self.mtest_command + ['--setup=valgrind']) with open(os.path.join(self.logdir, 'testlog-valgrind.txt'), encoding='utf-8') as f: vg_log = f.read() - self.assertFalse('TEST_ENV is set' in basic_log) - self.assertFalse('Memcheck' in basic_log) - self.assertTrue('TEST_ENV is set' in vg_log) - self.assertTrue('Memcheck' in vg_log) + self.assertNotIn('TEST_ENV is set', basic_log) + self.assertNotIn('Memcheck', basic_log) + self.assertIn('TEST_ENV is set', vg_log) + self.assertIn('Memcheck', vg_log) # Run buggy test with setup without env that will pass self._run(self.mtest_command + ['--setup=wrapper']) # Setup with no properties works @@ -605,12 +605,12 @@ class AllPlatformTests(BasePlatformTests): self._run(self.mtest_command + ['--setup=good']) with open(os.path.join(self.logdir, 'testlog-good.txt'), encoding='utf-8') as f: exclude_suites_log = f.read() - self.assertFalse('buggy' in exclude_suites_log) + self.assertNotIn('buggy', exclude_suites_log) # --suite overrides add_test_setup(xclude_suites) self._run(self.mtest_command + ['--setup=good', '--suite', 'buggy']) with open(os.path.join(self.logdir, 'testlog-good.txt'), encoding='utf-8') as f: include_suites_log = f.read() - self.assertTrue('buggy' in include_suites_log) + self.assertIn('buggy', include_suites_log) def test_testsetup_selection(self): testdir = os.path.join(self.unit_test_dir, '14 testsetup selection') @@ -657,17 +657,17 @@ class AllPlatformTests(BasePlatformTests): with open(os.path.join(self.logdir, 'testlog-other.txt'), encoding='utf-8') as f: other_log = f.read() - self.assertTrue('ENV_A is 1' in default_log) - self.assertTrue('ENV_B is 2' in default_log) - self.assertTrue('ENV_C is 2' in default_log) + self.assertIn('ENV_A is 1', default_log) + self.assertIn('ENV_B is 2', default_log) + self.assertIn('ENV_C is 2', default_log) - self.assertTrue('ENV_A is 1' in mydefault_log) - self.assertTrue('ENV_B is 2' in mydefault_log) - self.assertTrue('ENV_C is 2' in mydefault_log) + self.assertIn('ENV_A is 1', mydefault_log) + self.assertIn('ENV_B is 2', mydefault_log) + self.assertIn('ENV_C is 2', mydefault_log) - self.assertTrue('ENV_A is 1' in other_log) - self.assertTrue('ENV_B is 3' in other_log) - self.assertTrue('ENV_C is 2' in other_log) + self.assertIn('ENV_A is 1', other_log) + self.assertIn('ENV_B is 3', other_log) + self.assertIn('ENV_C is 2', other_log) def assertFailedTestCount(self, failure_count, command): try: @@ -1372,7 +1372,7 @@ class AllPlatformTests(BasePlatformTests): self.assertTrue(rpath.startswith('/usr/lib/gcc')) self.assertEqual(len(rpath.split(':')), 1) else: - self.assertTrue(rpath is None) + self.assertIsNone(rpath) def test_dash_d_dedup(self): testdir = os.path.join(self.unit_test_dir, '9 d dedup') diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index 81cca06dd..75888b3ba 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -263,7 +263,7 @@ class LinuxlikeTests(BasePlatformTests): self.init(testdir) with open(os.path.join(self.privatedir, 'somename.pc'), encoding='utf-8') as f: pcfile = f.read() - self.assertFalse('blub_blob_blib' in pcfile) + self.assertNotIn('blub_blob_blib', pcfile) def test_symlink_builddir(self) -> None: ''' @@ -1072,10 +1072,10 @@ class LinuxlikeTests(BasePlatformTests): myenv['PKG_CONFIG_PATH'] = pkg_dir # Private internal libraries must not leak out. pkg_out = subprocess.check_output(['pkg-config', '--static', '--libs', 'libpkgdep'], env=myenv) - self.assertFalse(b'libpkgdep-int' in pkg_out, 'Internal library leaked out.') + self.assertNotIn(b'libpkgdep-int', pkg_out, 'Internal library leaked out.') # Dependencies must not leak to cflags when building only a shared library. pkg_out = subprocess.check_output(['pkg-config', '--cflags', 'libpkgdep'], env=myenv) - self.assertFalse(b'glib' in pkg_out, 'Internal dependency leaked to headers.') + self.assertNotIn(b'glib', pkg_out, 'Internal dependency leaked to headers.') # Test that the result is usable. self.init(testdir2, override_envvars=myenv) self.build(override_envvars=myenv) @@ -1093,7 +1093,7 @@ class LinuxlikeTests(BasePlatformTests): def test_pkgconfig_relative_paths(self): testdir = os.path.join(self.unit_test_dir, '62 pkgconfig relative paths') pkg_dir = os.path.join(testdir, 'pkgconfig') - self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'librelativepath.pc'))) + self.assertPathExists(os.path.join(pkg_dir, 'librelativepath.pc')) env = get_fake_env(testdir, self.builddir, self.prefix) env.coredata.set_options({OptionKey('pkg_config_path'): pkg_dir}, subproject='') @@ -1116,7 +1116,7 @@ class LinuxlikeTests(BasePlatformTests): PkgConfigDependency.setup_env({}, env, MachineChoice.HOST, pkg_dir) pkg_config_path = env.coredata.options[OptionKey('pkg_config_path')].value - self.assertTrue(len(pkg_config_path) == 1) + self.assertEqual(len(pkg_config_path), 1) @skipIfNoPkgconfig def test_pkgconfig_internal_libraries(self): @@ -1201,7 +1201,7 @@ class LinuxlikeTests(BasePlatformTests): myenv['PKG_CONFIG_PATH'] = self.privatedir stdo = subprocess.check_output(['pkg-config', '--libs', 'libsomething'], env=myenv) deps = stdo.split() - self.assertTrue(deps.index(b'-lsomething') < deps.index(b'-ldependency')) + self.assertLess(deps.index(b'-lsomething'), deps.index(b'-ldependency')) def test_deterministic_dep_order(self): ''' @@ -1688,8 +1688,8 @@ class LinuxlikeTests(BasePlatformTests): self.build() outlib = os.path.join(self.builddir, 'libprelinked.a') ar = shutil.which('ar') - self.assertTrue(os.path.exists(outlib)) - self.assertTrue(ar is not None) + self.assertPathExists(outlib) + self.assertIsNotNone(ar) p = subprocess.run([ar, 't', outlib], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, diff --git a/unittests/windowstests.py b/unittests/windowstests.py index 1e5964c78..bd75c7479 100644 --- a/unittests/windowstests.py +++ b/unittests/windowstests.py @@ -318,7 +318,7 @@ class WindowsTests(BasePlatformTests): def sanitycheck_vscrt(vscrt): checks = self.get_meson_log_sanitychecks() - self.assertTrue(len(checks) > 0) + self.assertGreater(len(checks), 0) for check in checks: self.assertIn(vscrt, check)