From 8c237b78c240d1f5961f42ec3fe09f59eedf1bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 1 Jun 2017 09:59:41 +0200 Subject: [PATCH] comps-wrapper: Report unknown package types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When there is a typo in the comps file, instead of crashing with a non-descript KeyError we should raise a nice error with details about the problem. Signed-off-by: Lubomír Sedlář --- pungi/wrappers/comps.py | 5 +++++ tests/fixtures/comps-typo.xml | 14 ++++++++++++++ tests/test_comps_wrapper.py | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/fixtures/comps-typo.xml diff --git a/pungi/wrappers/comps.py b/pungi/wrappers/comps.py index 5c14b153..6c43e5fa 100644 --- a/pungi/wrappers/comps.py +++ b/pungi/wrappers/comps.py @@ -88,6 +88,11 @@ class CompsWrapper(object): packages_by_type = collections.defaultdict(list) for pkg in group.packages: + if pkg.type == libcomps.PACKAGE_TYPE_UNKNOWN: + raise RuntimeError( + 'Failed to process comps file. Package %s in group %s has unknown type' + % (pkg.name, group.id)) + packages_by_type[TYPE_MAPPING[pkg.type]].append(pkg) for type_name in TYPE_MAPPING.values(): diff --git a/tests/fixtures/comps-typo.xml b/tests/fixtures/comps-typo.xml new file mode 100644 index 00000000..6f83a105 --- /dev/null +++ b/tests/fixtures/comps-typo.xml @@ -0,0 +1,14 @@ + + + + + core + Core + Smallest possible installation + true + false + + dummy-bash + + + diff --git a/tests/test_comps_wrapper.py b/tests/test_comps_wrapper.py index 985fefe6..c433259d 100644 --- a/tests/test_comps_wrapper.py +++ b/tests/test_comps_wrapper.py @@ -19,6 +19,7 @@ COMPS_FILE = os.path.join(FIXTURE_DIR, 'comps.xml') COMPS_FORMATTED_FILE = os.path.join(FIXTURE_DIR, 'comps-formatted.xml') COMPS_GROUP_FILE = os.path.join(FIXTURE_DIR, 'comps-group.xml') COMPS_ENVIRONMENT_FILE = os.path.join(FIXTURE_DIR, 'comps-env.xml') +COMPS_FILE_WITH_TYPO = os.path.join(FIXTURE_DIR, 'comps-typo.xml') class CompsWrapperTest(unittest.TestCase): @@ -77,3 +78,11 @@ class CompsWrapperTest(unittest.TestCase): ] comps.filter_environments(groups) self.assertEqual(groups, [{"name": "minimal", "display_order": 99, "groups": ["core"]}]) + + def test_report_typo_in_package_type(self): + comps = CompsWrapper(COMPS_FILE_WITH_TYPO) + with self.assertRaises(RuntimeError) as ctx: + comps.write_comps(target_file=self.file.name) + self.assertIn( + 'Package dummy-bash in group core has unknown type', + str(ctx.exception))