From f21e3a2d6d34c60a7ee1a60354475645fa9bed61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 30 Oct 2017 09:16:18 +0100 Subject: [PATCH] tests: Work with older unittest2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RHEL has an older version of the library which does not backport all the assertions that we used. In order for the tests to pass there we need to use names that exist everywhere. Signed-off-by: Lubomír Sedlář --- tests/test_checks.py | 34 ++++++++++++++++----------------- tests/test_createrepophase.py | 10 ++++++---- tests/test_extra_files_phase.py | 2 +- tests/test_osbs_phase.py | 2 +- tests/test_pkgset_pkgsets.py | 10 ++++++---- tests/test_scm.py | 4 ++-- tests/test_unified_isos.py | 8 ++++---- 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/tests/test_checks.py b/tests/test_checks.py index 00f0e597..06c36ae3 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -102,7 +102,7 @@ class CheckDependenciesTestCase(unittest.TestCase): exists.side_effect = self.dont_find(['/usr/bin/isohybrid']) result = checks.check(conf) - self.assertRegex(out.getvalue(), r'^Not checking.*Expect failures.*$') + self.assertRegexpMatches(out.getvalue(), r'^Not checking.*Expect failures.*$') self.assertTrue(result) def test_isohybrid_not_needed_in_runroot(self): @@ -227,7 +227,7 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 1) - self.assertRegex(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") self.assertEqual(config.get("release_name", None), "dummy product") @mock.patch('pungi.checks.make_schema') @@ -275,7 +275,7 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 1) - self.assertRegex(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") self.assertEqual(config.get("release_name", None), "dummy product") @mock.patch('pungi.checks.make_schema') @@ -299,9 +299,9 @@ class TestSchemaValidator(unittest.TestCase): config = self._load_conf_from_string(string) errors, warnings = checks.validate(config) self.assertEqual(len(errors), 1) - self.assertRegex(errors[0], r"^ERROR: Config option 'product_name' is an alias of 'release_name', only one can be used.*") + self.assertRegexpMatches(errors[0], r"^ERROR: Config option 'product_name' is an alias of 'release_name', only one can be used.*") self.assertEqual(len(warnings), 1) - self.assertRegex(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") self.assertEqual(config.get("release_name", None), "dummy product") @mock.patch('pungi.checks.make_schema') @@ -340,8 +340,8 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegex(warnings[0], r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*") - self.assertRegex(warnings[1], r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*") + self.assertRegexpMatches(warnings[1], r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*") self.assertEqual(config.get("release_name", None), "dummy product") self.assertEqual(config.get("foophase", {}).get("repo", None), "http://www.exampe.com/os") @@ -380,8 +380,8 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegex(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegex(warnings[1], r"^WARNING: Value from config option 'repo_from' is now appended to option 'repo'") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") + self.assertRegexpMatches(warnings[1], r"^WARNING: Value from config option 'repo_from' is now appended to option 'repo'") self.assertEqual(config.get("release_name", None), "dummy product") self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"]) @@ -419,8 +419,8 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegex(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegex(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") + self.assertRegexpMatches(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,") self.assertEqual(config.get("release_name", None), "dummy product") self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"]) @@ -462,10 +462,10 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 4) - self.assertRegex(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegex(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,") - self.assertRegex(warnings[2], r"^WARNING: Config option 'source_repo_from' is deprecated, its value will be appended to option 'repo'") - self.assertRegex(warnings[3], r"^WARNING: Value from config option 'source_repo_from' is now appended to option 'repo'.") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") + self.assertRegexpMatches(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,") + self.assertRegexpMatches(warnings[2], r"^WARNING: Config option 'source_repo_from' is deprecated, its value will be appended to option 'repo'") + self.assertRegexpMatches(warnings[3], r"^WARNING: Value from config option 'source_repo_from' is now appended to option 'repo'.") self.assertEqual(config.get("release_name", None), "dummy product") self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server", "Client"]) @@ -515,8 +515,8 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegex(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegex(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified, value from 'repo_from' is now added as 'repo'.*") + self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") + self.assertRegexpMatches(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified, value from 'repo_from' is now added as 'repo'.*") self.assertEqual(config.get("live_images")[0][1]['armhfp']['repo'], 'Everything') diff --git a/tests/test_createrepophase.py b/tests/test_createrepophase.py index 6eaecfe9..53296e7f 100644 --- a/tests/test_createrepophase.py +++ b/tests/test_createrepophase.py @@ -801,8 +801,9 @@ class TestGetProductIds(PungiTestCase): get_productids_from_scm(self.compose) self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, ANY)]) - self.assertRegex(str(ctx.exception), - r'No product certificate found \(arch: amd64, variant: (Everything|Client)\)') + self.assertRegexpMatches( + str(ctx.exception), + r'No product certificate found \(arch: amd64, variant: (Everything|Client)\)') @mock.patch('pungi.phases.createrepo.get_dir_from_scm') def test_multiple_matching(self, get_dir_from_scm): @@ -823,8 +824,9 @@ class TestGetProductIds(PungiTestCase): get_productids_from_scm(self.compose) self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, ANY)]) - self.assertRegex(str(ctx.exception), - 'Multiple product certificates found.+') + self.assertRegexpMatches( + str(ctx.exception), + 'Multiple product certificates found.+') if __name__ == "__main__": diff --git a/tests/test_extra_files_phase.py b/tests/test_extra_files_phase.py index 6a0fd618..54daedb3 100644 --- a/tests/test_extra_files_phase.py +++ b/tests/test_extra_files_phase.py @@ -159,7 +159,7 @@ class TestCopyFiles(helpers.PungiTestCase): extra_files.copy_extra_files( compose, [cfg], 'x86_64', compose.variants['Server'], package_sets) - self.assertRegex(str(ctx.exception), 'No.*package.*matching bad-server\*.*') + self.assertRegexpMatches(str(ctx.exception), 'No.*package.*matching bad-server\*.*') self.assertEqual(len(get_file_from_scm.call_args_list), 0) self.assertEqual(get_dir_from_scm.call_args_list, []) diff --git a/tests/test_osbs_phase.py b/tests/test_osbs_phase.py index 110b515d..4d16cc00 100644 --- a/tests/test_osbs_phase.py +++ b/tests/test_osbs_phase.py @@ -443,7 +443,7 @@ class OSBSThreadTest(helpers.PungiTestCase): with self.assertRaises(RuntimeError) as ctx: self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) - self.assertRegex(str(ctx.exception), r"task 12345 failed: see .+ for details") + self.assertRegexpMatches(str(ctx.exception), r"task 12345 failed: see .+ for details") @mock.patch('pungi.util.resolve_git_url') @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') diff --git a/tests/test_pkgset_pkgsets.py b/tests/test_pkgset_pkgsets.py index 40ed93a7..7850619b 100644 --- a/tests/test_pkgset_pkgsets.py +++ b/tests/test_pkgset_pkgsets.py @@ -259,8 +259,9 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase): self.koji_wrapper.koji_proxy.mock_calls, [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) - self.assertRegex(str(ctx.exception), - r'^RPM\(s\) not found for sigs: .+Check log for details.+') + self.assertRegexpMatches( + str(ctx.exception), + r'^RPM\(s\) not found for sigs: .+Check log for details.+') def test_can_not_find_any_package(self): pkgset = pkgsets.KojiPackageSet(self.koji_wrapper, ['cafebabe', None], arches=['x86_64']) @@ -272,8 +273,9 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase): self.koji_wrapper.koji_proxy.mock_calls, [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) - self.assertRegex(str(ctx.exception), - r'^RPM\(s\) not found for sigs: .+Check log for details.+') + self.assertRegexpMatches( + str(ctx.exception), + r'^RPM\(s\) not found for sigs: .+Check log for details.+') def test_packages_attribute(self): self._touch_files([ diff --git a/tests/test_scm.py b/tests/test_scm.py index 64f3961a..3ad54ede 100644 --- a/tests/test_scm.py +++ b/tests/test_scm.py @@ -213,7 +213,7 @@ class GitSCMTestCase(SCMBaseTest): self.destdir) self.assertStructure(retval, ['some_file.txt']) self.assertEqual(1, len(commands)) - self.assertRegex( + self.assertRegexpMatches( commands[0], r'/usr/bin/git clone --depth 1 --branch=master https://example.com/git/repo.git /tmp/.+') @@ -308,7 +308,7 @@ class GitSCMTestCase(SCMBaseTest): self.destdir) self.assertStructure(retval, ['first', 'second']) - self.assertRegex( + self.assertRegexpMatches( commands[0], r'/usr/bin/git clone --depth 1 --branch=master https://example.com/git/repo.git /tmp/.+') self.assertEqual(commands[1:], ['make']) diff --git a/tests/test_unified_isos.py b/tests/test_unified_isos.py index 01a2f5c5..8e16540c 100755 --- a/tests/test_unified_isos.py +++ b/tests/test_unified_isos.py @@ -26,14 +26,14 @@ class TestUnifiedIsos(PungiTestCase): compose_path = os.path.join(self.topdir, COMPOSE_ID, 'compose') isos = unified_isos.UnifiedISO(compose_path) self.assertEqual(isos.compose_path, compose_path) - self.assertRegex(isos.temp_dir, - '^%s/' % os.path.join(self.topdir, COMPOSE_ID, 'work')) + self.assertRegexpMatches( + isos.temp_dir, '^%s/' % os.path.join(self.topdir, COMPOSE_ID, 'work')) def test_can_find_compose_subdir(self): isos = unified_isos.UnifiedISO(os.path.join(self.topdir, COMPOSE_ID)) self.assertEqual(isos.compose_path, os.path.join(self.topdir, COMPOSE_ID, 'compose')) - self.assertRegex(isos.temp_dir, - '^%s/' % os.path.join(self.topdir, COMPOSE_ID, 'work')) + self.assertRegexpMatches(isos.temp_dir, + '^%s/' % os.path.join(self.topdir, COMPOSE_ID, 'work')) @mock.patch('os.rename') def test_dump_manifest(self, rename):