2017-04-12 10:58:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
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
|
|
|
|
|
|
|
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')
|
2017-06-01 07:59:41 +00:00
|
|
|
COMPS_FILE_WITH_TYPO = os.path.join(FIXTURE_DIR, 'comps-typo.xml')
|
2018-06-14 13:37:23 +00:00
|
|
|
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):
|
|
|
|
self.file = tempfile.NamedTemporaryFile(prefix='comps-wrapper-test-')
|
|
|
|
|
|
|
|
def test_get_groups(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
2018-03-29 14:34:52 +00:00
|
|
|
self.assertEqual(
|
|
|
|
sorted(comps.get_comps_groups()),
|
|
|
|
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(
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
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):
|
|
|
|
comps.get_packages('foo')
|
|
|
|
|
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)
|
|
|
|
unmatched = comps.filter_groups([
|
|
|
|
{"name": "core", "glob": False, "default": False, "uservisible": True},
|
|
|
|
{"name": "*a*", "glob": True, "default": None, "uservisible": None},
|
|
|
|
])
|
|
|
|
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)
|
|
|
|
unmatched = comps.filter_groups([
|
|
|
|
{"name": "boom", "glob": False, "default": False, "uservisible": True},
|
|
|
|
])
|
|
|
|
self.assertEqual(unmatched, set(["boom"]))
|
|
|
|
|
|
|
|
def test_filter_environments(self):
|
|
|
|
comps = CompsWrapper(COMPS_FILE)
|
|
|
|
comps.filter_environments([
|
|
|
|
{"name": "minimal", "display_order": 10}
|
|
|
|
])
|
|
|
|
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)
|
|
|
|
groups = [
|
|
|
|
{"name": "minimal", "display_order": None}
|
|
|
|
]
|
|
|
|
comps.filter_environments(groups)
|
|
|
|
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(
|
|
|
|
'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
|
|
|
|
|
|
|
COMPS_IN_FILE = os.path.join(FIXTURE_DIR, 'comps.xml.in')
|
|
|
|
|
|
|
|
|
|
|
|
class CompsFilterTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.filter = CompsFilter(COMPS_IN_FILE, reindent=True)
|
|
|
|
self.output = tempfile.NamedTemporaryFile(prefix='comps-filter-test-')
|
|
|
|
|
|
|
|
def assertOutput(self, filepath):
|
|
|
|
self.filter.write(self.output)
|
|
|
|
self.output.flush()
|
|
|
|
with open(self.output.name, 'r') as f:
|
2018-05-02 14:32:18 +00:00
|
|
|
actual = f.read().strip().replace('utf-8', 'UTF-8')
|
2018-04-06 08:10:17 +00:00
|
|
|
with open(filepath, 'r') as f:
|
|
|
|
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):
|
2018-04-09 12:55:24 +00:00
|
|
|
self.filter.filter_packages('ppc64le', None)
|
2018-04-06 08:10:17 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages.xml'))
|
|
|
|
|
2018-04-09 12:55:24 +00:00
|
|
|
def test_filter_packages_with_variant(self):
|
|
|
|
self.filter.filter_packages('ppc64le', 'Server')
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages-variant.xml'))
|
|
|
|
|
2018-04-06 08:10:17 +00:00
|
|
|
def test_filter_groups(self):
|
2018-04-09 12:55:24 +00:00
|
|
|
self.filter.filter_groups('ppc64le', None)
|
2018-04-06 08:10:17 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups.xml'))
|
|
|
|
|
2018-04-09 12:55:24 +00:00
|
|
|
def test_filter_groups_with_variant(self):
|
|
|
|
self.filter.filter_groups('ppc64le', 'Server')
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups-variant.xml'))
|
|
|
|
|
2018-04-06 08:10:17 +00:00
|
|
|
def test_filter_environments(self):
|
2018-04-09 12:55:24 +00:00
|
|
|
self.filter.filter_environments('ppc64le', None)
|
2018-04-06 08:10:17 +00:00
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments.xml'))
|
|
|
|
|
2018-04-09 12:55:24 +00:00
|
|
|
def test_filter_environments_variant(self):
|
|
|
|
self.filter.filter_environments('ppc64le', 'Client')
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments-variant.xml'))
|
|
|
|
|
2018-04-06 08:10:17 +00:00
|
|
|
def test_remove_categories(self):
|
|
|
|
self.filter.remove_categories()
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-categories.xml'))
|
|
|
|
|
|
|
|
def test_remove_langpacks(self):
|
|
|
|
self.filter.remove_langpacks()
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-langpacks.xml'))
|
|
|
|
|
|
|
|
def test_remove_translations(self):
|
|
|
|
self.filter.remove_translations()
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-translations.xml'))
|
|
|
|
|
|
|
|
def test_remove_environments(self):
|
|
|
|
self.filter.remove_environments()
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-environments.xml'))
|
|
|
|
|
|
|
|
def test_cleanup(self):
|
|
|
|
self.filter.cleanup()
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup.xml'))
|
|
|
|
|
|
|
|
def test_cleanup_after_filter(self):
|
2018-04-09 12:55:24 +00:00
|
|
|
self.filter.filter_packages('ppc64le', None)
|
2018-04-06 08:10:17 +00:00
|
|
|
self.filter.cleanup()
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-filter.xml'))
|
|
|
|
|
|
|
|
def test_cleanup_after_filter_keep_group(self):
|
2018-04-09 12:55:24 +00:00
|
|
|
self.filter.filter_packages('ppc64le', None)
|
2018-04-06 08:10:17 +00:00
|
|
|
self.filter.cleanup(['standard'])
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-keep.xml'))
|
|
|
|
|
|
|
|
def test_cleanup_all(self):
|
2018-04-09 12:55:24 +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()
|
|
|
|
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-all.xml'))
|