2017-04-12 10:58:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2018-06-14 13:37:23 +00:00
|
|
|
from pungi.wrappers.comps import CompsWrapper, CompsFilter, CompsValidationError
|
2018-10-11 08:07:35 +00:00
|
|
|
from tests.helpers import BaseTestCase, FIXTURE_DIR
|
2017-04-12 10:58:01 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
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")
|
|
|
|
COMPS_FILE_WITH_WHITESPACE = os.path.join(FIXTURE_DIR, "comps-ws.xml")
|
2017-04-12 10:58:01 +00:00
|
|
|
|
|
|
|
|
2018-10-11 08:07:35 +00:00
|
|
|
class CompsWrapperTest(BaseTestCase):
|
2017-04-12 10:58:01 +00:00
|
|
|
def setUp(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.file = tempfile.NamedTemporaryFile(prefix="comps-wrapper-test-")
|
2017-04-12 10:58:01 +00:00
|
|
|
|
|
|
|
def test_get_groups(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
2018-03-29 14:34:52 +00:00
|
|
|
self.assertEqual(
|
|
|
|
sorted(comps.get_comps_groups()),
|
2020-01-22 10:02:22 +00:00
|
|
|
sorted(
|
|
|
|
[
|
|
|
|
"core",
|
|
|
|
"standard",
|
|
|
|
"text-internet",
|
|
|
|
"firefox",
|
|
|
|
"resilient-storage",
|
|
|
|
"basic-desktop",
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|
2017-04-12 10:58:01 +00:00
|
|
|
|
2017-06-21 11:35:36 +00:00
|
|
|
def test_get_packages(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
2018-03-29 14:34:52 +00:00
|
|
|
self.assertEqual(
|
2020-01-22 10:02:22 +00:00
|
|
|
sorted(comps.get_packages("text-internet")),
|
|
|
|
sorted(["dummy-elinks", "dummy-tftp"]),
|
|
|
|
)
|
2017-06-21 11:35:36 +00:00
|
|
|
|
2018-07-17 11:11:13 +00:00
|
|
|
def test_get_langpacks(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
|
|
|
self.assertEqual(
|
|
|
|
comps.get_langpacks(),
|
|
|
|
{
|
|
|
|
"aspell": "aspell-%s",
|
|
|
|
"firefox": "firefox-langpack-%s",
|
|
|
|
"kdelibs": "kde-l10n-%s",
|
2020-01-22 10:02:22 +00:00
|
|
|
},
|
2018-07-17 11:11:13 +00:00
|
|
|
)
|
|
|
|
|
2017-06-21 11:35:36 +00:00
|
|
|
def test_get_packages_for_non_existing_group(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
|
|
|
with self.assertRaises(KeyError):
|
2020-01-22 10:02:22 +00:00
|
|
|
comps.get_packages("foo")
|
2017-06-21 11:35:36 +00:00
|
|
|
|
2017-04-12 10:58:01 +00:00
|
|
|
def test_write_comps(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
|
|
|
comps.write_comps(target_file=self.file.name)
|
|
|
|
self.assertFilesEqual(COMPS_FORMATTED_FILE, self.file.name)
|
|
|
|
|
|
|
|
def test_filter_groups(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
2020-01-22 10:02:22 +00:00
|
|
|
unmatched = comps.filter_groups(
|
|
|
|
[
|
|
|
|
{"name": "core", "glob": False, "default": False, "uservisible": True},
|
|
|
|
{"name": "*a*", "glob": True, "default": None, "uservisible": None},
|
|
|
|
]
|
|
|
|
)
|
2017-04-12 10:58:01 +00:00
|
|
|
self.assertEqual(unmatched, set())
|
|
|
|
comps.write_comps(target_file=self.file.name)
|
|
|
|
self.assertFilesEqual(COMPS_GROUP_FILE, self.file.name)
|
|
|
|
|
|
|
|
def test_filter_groups_unused_filter(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
2020-01-22 10:02:22 +00:00
|
|
|
unmatched = comps.filter_groups(
|
|
|
|
[{"name": "boom", "glob": False, "default": False, "uservisible": True}]
|
|
|
|
)
|
2017-04-12 10:58:01 +00:00
|
|
|
self.assertEqual(unmatched, set(["boom"]))
|
|
|
|
|
|
|
|
def test_filter_environments(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
2020-01-22 10:02:22 +00:00
|
|
|
comps.filter_environments([{"name": "minimal", "display_order": 10}])
|
2017-04-12 10:58:01 +00:00
|
|
|
comps.write_comps(target_file=self.file.name)
|
|
|
|
self.assertFilesEqual(COMPS_ENVIRONMENT_FILE, self.file.name)
|
|
|
|
|
|
|
|
def test_read_display_order(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
2020-01-22 10:02:22 +00:00
|
|
|
groups = [{"name": "minimal", "display_order": None}]
|
2017-04-12 10:58:01 +00:00
|
|
|
comps.filter_environments(groups)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
groups, [{"name": "minimal", "display_order": 99, "groups": ["core"]}]
|
|
|
|
)
|
2017-06-01 07:59:41 +00:00
|
|
|
|
|
|
|
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(
|
2020-01-22 10:02:22 +00:00
|
|
|
"Package dummy-bash in group core has unknown type", str(ctx.exception)
|
|
|
|
)
|
2018-04-06 08:10:17 +00:00
|
|
|
|
2018-06-14 13:37:23 +00:00
|
|
|
def test_validate_correct(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
|
|
|
comps.validate()
|
|
|
|
|
|
|
|
def test_validate_with_whitespace(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE_WITH_WHITESPACE)
|
|
|
|
with self.assertRaises(CompsValidationError) as ctx:
|
|
|
|
comps.validate()
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
"Package name foo in group 'core' contains leading or trailing whitespace",
|
|
|
|
str(ctx.exception),
|
|
|
|
)
|
|
|
|
self.assertIn(
|
|
|
|
"Package name bar in group 'core' contains leading or trailing whitespace",
|
|
|
|
str(ctx.exception),
|
|
|
|
)
|
|
|
|
self.assertIn(
|
|
|
|
"Package name baz in group 'core' contains leading or trailing whitespace",
|
|
|
|
str(ctx.exception),
|
|
|
|
)
|
|
|
|
|
2018-04-06 08:10:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
COMPS_IN_FILE = os.path.join(FIXTURE_DIR, "comps.xml.in")
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CompsFilterTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.filter = CompsFilter(COMPS_IN_FILE, reindent=True)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.output = tempfile.NamedTemporaryFile(prefix="comps-filter-test-")
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def assertOutput(self, filepath):
|
|
|
|
self.filter.write(self.output)
|
|
|
|
self.output.flush()
|
2020-01-22 10:02:22 +00:00
|
|
|
with open(self.output.name, "r") as f:
|
|
|
|
actual = f.read().strip().replace("utf-8", "UTF-8")
|
|
|
|
with open(filepath, "r") as f:
|
2018-04-06 08:10:17 +00:00
|
|
|
expected = f.read().strip()
|
2018-04-09 12:55:24 +00:00
|
|
|
self.maxDiff = None
|
2018-04-06 08:10:17 +00:00
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
def test_filter_packages(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_packages("ppc64le", None)
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-filtered-packages.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
2018-04-09 12:55:24 +00:00
|
|
|
def test_filter_packages_with_variant(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_packages("ppc64le", "Server")
|
|
|
|
self.assertOutput(
|
|
|
|
os.path.join(FIXTURE_DIR, "comps-filtered-packages-variant.xml")
|
|
|
|
)
|
2018-04-09 12:55:24 +00:00
|
|
|
|
2018-04-06 08:10:17 +00:00
|
|
|
def test_filter_groups(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_groups("ppc64le", None)
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-filtered-groups.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
2018-04-09 12:55:24 +00:00
|
|
|
def test_filter_groups_with_variant(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_groups("ppc64le", "Server")
|
|
|
|
self.assertOutput(
|
|
|
|
os.path.join(FIXTURE_DIR, "comps-filtered-groups-variant.xml")
|
|
|
|
)
|
2018-04-09 12:55:24 +00:00
|
|
|
|
2018-04-06 08:10:17 +00:00
|
|
|
def test_filter_environments(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_environments("ppc64le", None)
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-filtered-environments.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
2018-04-09 12:55:24 +00:00
|
|
|
def test_filter_environments_variant(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_environments("ppc64le", "Client")
|
|
|
|
self.assertOutput(
|
|
|
|
os.path.join(FIXTURE_DIR, "comps-filtered-environments-variant.xml")
|
|
|
|
)
|
2018-04-09 12:55:24 +00:00
|
|
|
|
2018-04-06 08:10:17 +00:00
|
|
|
def test_remove_categories(self):
|
|
|
|
self.filter.remove_categories()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-categories.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def test_remove_langpacks(self):
|
|
|
|
self.filter.remove_langpacks()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-langpacks.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def test_remove_translations(self):
|
|
|
|
self.filter.remove_translations()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-translations.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def test_remove_environments(self):
|
|
|
|
self.filter.remove_environments()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-environments.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def test_cleanup(self):
|
|
|
|
self.filter.cleanup()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def test_cleanup_after_filter(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_packages("ppc64le", None)
|
2018-04-06 08:10:17 +00:00
|
|
|
self.filter.cleanup()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-filter.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def test_cleanup_after_filter_keep_group(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_packages("ppc64le", None)
|
|
|
|
self.filter.cleanup(["standard"])
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-keep.xml"))
|
2018-04-06 08:10:17 +00:00
|
|
|
|
|
|
|
def test_cleanup_all(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.filter.filter_packages("ppc64le", None)
|
|
|
|
self.filter.filter_groups("ppc64le", None)
|
|
|
|
self.filter.filter_environments("ppc64le", None)
|
2018-04-06 08:10:17 +00:00
|
|
|
self.filter.cleanup()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-all.xml"))
|