From de231064b7f94455e6419d1c6f7f55403b10c22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Fri, 6 Apr 2018 10:10:17 +0200 Subject: [PATCH] comps: Add tests for CompsFilter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All use cases that are actually used by pungi-koji are tested. There is missing coverage for * keeping only items with matching arch * not reindenting the file These aren't currently used and should be removed in the future, but there may be other tools depending on the comps_filter executable. Signed-off-by: Lubomír Sedlář --- bin/comps_filter | 6 +- pungi/wrappers/comps.py | 11 +++ tests/fixtures/comps-cleanup-all.xml | 19 +++++ tests/fixtures/comps-cleanup-filter.xml | 43 ++++++++++ tests/fixtures/comps-cleanup-keep.xml | 60 ++++++++++++++ tests/fixtures/comps-cleanup.xml | 63 ++++++++++++++ .../fixtures/comps-filtered-environments.xml | 69 ++++++++++++++++ tests/fixtures/comps-filtered-groups.xml | 71 ++++++++++++++++ tests/fixtures/comps-filtered-packages.xml | 79 ++++++++++++++++++ tests/fixtures/comps-removed-categories.xml | 63 ++++++++++++++ tests/fixtures/comps-removed-environments.xml | 60 ++++++++++++++ tests/fixtures/comps-removed-langpacks.xml | 79 ++++++++++++++++++ tests/fixtures/comps-removed-translations.xml | 76 +++++++++++++++++ tests/fixtures/comps.xml.in | 82 +++++++++++++++++++ tests/test_comps_wrapper.py | 69 +++++++++++++++- 15 files changed, 844 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/comps-cleanup-all.xml create mode 100644 tests/fixtures/comps-cleanup-filter.xml create mode 100644 tests/fixtures/comps-cleanup-keep.xml create mode 100644 tests/fixtures/comps-cleanup.xml create mode 100644 tests/fixtures/comps-filtered-environments.xml create mode 100644 tests/fixtures/comps-filtered-groups.xml create mode 100644 tests/fixtures/comps-filtered-packages.xml create mode 100644 tests/fixtures/comps-removed-categories.xml create mode 100644 tests/fixtures/comps-removed-environments.xml create mode 100644 tests/fixtures/comps-removed-langpacks.xml create mode 100644 tests/fixtures/comps-removed-translations.xml create mode 100644 tests/fixtures/comps.xml.in diff --git a/bin/comps_filter b/bin/comps_filter index 63b6516f..dee907fd 100755 --- a/bin/comps_filter +++ b/bin/comps_filter @@ -44,11 +44,7 @@ def main(): f.filter_environments(opts.arch, opts.arch_only_environments) if not opts.no_cleanup: - f.remove_empty_groups(keep_empty=opts.keep_empty_group) - f.filter_category_groups() - f.remove_empty_categories() - f.filter_environment_groups() - f.remove_empty_environments() + f.cleanup(opts.keep_empty_group) if opts.remove_categories: f.remove_categories() diff --git a/pungi/wrappers/comps.py b/pungi/wrappers/comps.py index 19243f58..f6848c29 100644 --- a/pungi/wrappers/comps.py +++ b/pungi/wrappers/comps.py @@ -189,6 +189,17 @@ class CompsFilter(object): self.tree.write(file_obj, pretty_print=self.reindent, xml_declaration=True, encoding=self.encoding) file_obj.write(b"\n") + def cleanup(self, keep_groups=[]): + """ + Remove empty groups, categories and environment from the comps file. + Groups given in ``keep_groups`` will be preserved even if empty. + """ + self.remove_empty_groups(keep_groups) + self.filter_category_groups() + self.remove_empty_categories() + self.filter_environment_groups() + self.remove_empty_environments() + class CompsWrapper(object): """ diff --git a/tests/fixtures/comps-cleanup-all.xml b/tests/fixtures/comps-cleanup-all.xml new file mode 100644 index 00000000..98014690 --- /dev/null +++ b/tests/fixtures/comps-cleanup-all.xml @@ -0,0 +1,19 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + + + + + + diff --git a/tests/fixtures/comps-cleanup-filter.xml b/tests/fixtures/comps-cleanup-filter.xml new file mode 100644 index 00000000..1c2e61c1 --- /dev/null +++ b/tests/fixtures/comps-cleanup-filter.xml @@ -0,0 +1,43 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + + + diff --git a/tests/fixtures/comps-cleanup-keep.xml b/tests/fixtures/comps-cleanup-keep.xml new file mode 100644 index 00000000..638c34b6 --- /dev/null +++ b/tests/fixtures/comps-cleanup-keep.xml @@ -0,0 +1,60 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + diff --git a/tests/fixtures/comps-cleanup.xml b/tests/fixtures/comps-cleanup.xml new file mode 100644 index 00000000..442676a7 --- /dev/null +++ b/tests/fixtures/comps-cleanup.xml @@ -0,0 +1,63 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + diff --git a/tests/fixtures/comps-filtered-environments.xml b/tests/fixtures/comps-filtered-environments.xml new file mode 100644 index 00000000..090db058 --- /dev/null +++ b/tests/fixtures/comps-filtered-environments.xml @@ -0,0 +1,69 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-filtered-groups.xml b/tests/fixtures/comps-filtered-groups.xml new file mode 100644 index 00000000..7d1cabfe --- /dev/null +++ b/tests/fixtures/comps-filtered-groups.xml @@ -0,0 +1,71 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-filtered-packages.xml b/tests/fixtures/comps-filtered-packages.xml new file mode 100644 index 00000000..b55dbe1d --- /dev/null +++ b/tests/fixtures/comps-filtered-packages.xml @@ -0,0 +1,79 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-removed-categories.xml b/tests/fixtures/comps-removed-categories.xml new file mode 100644 index 00000000..442676a7 --- /dev/null +++ b/tests/fixtures/comps-removed-categories.xml @@ -0,0 +1,63 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + diff --git a/tests/fixtures/comps-removed-environments.xml b/tests/fixtures/comps-removed-environments.xml new file mode 100644 index 00000000..c1ed0ccc --- /dev/null +++ b/tests/fixtures/comps-removed-environments.xml @@ -0,0 +1,60 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-removed-langpacks.xml b/tests/fixtures/comps-removed-langpacks.xml new file mode 100644 index 00000000..fbd6388d --- /dev/null +++ b/tests/fixtures/comps-removed-langpacks.xml @@ -0,0 +1,79 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-removed-translations.xml b/tests/fixtures/comps-removed-translations.xml new file mode 100644 index 00000000..104c381d --- /dev/null +++ b/tests/fixtures/comps-removed-translations.xml @@ -0,0 +1,76 @@ + + + + + core + Core + Smallest possible installation + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Basic functionality. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + + apps + Applications + Applications to perform a variety of tasks + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps.xml.in b/tests/fixtures/comps.xml.in new file mode 100644 index 00000000..8ae80cbd --- /dev/null +++ b/tests/fixtures/comps.xml.in @@ -0,0 +1,82 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/test_comps_wrapper.py b/tests/test_comps_wrapper.py index 48d91fa1..fab0322f 100644 --- a/tests/test_comps_wrapper.py +++ b/tests/test_comps_wrapper.py @@ -12,7 +12,7 @@ import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) -from pungi.wrappers.comps import CompsWrapper +from pungi.wrappers.comps import CompsWrapper, CompsFilter from tests.helpers import FIXTURE_DIR COMPS_FILE = os.path.join(FIXTURE_DIR, 'comps.xml') @@ -97,3 +97,70 @@ class CompsWrapperTest(unittest.TestCase): self.assertIn( 'Package dummy-bash in group core has unknown type', str(ctx.exception)) + + +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: + actual = f.read().strip() + with open(filepath, 'r') as f: + expected = f.read().strip() + self.assertEqual(expected, actual) + + def test_filter_packages(self): + self.filter.filter_packages('ppc64le') + self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages.xml')) + + def test_filter_groups(self): + self.filter.filter_groups('ppc64le') + self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups.xml')) + + def test_filter_environments(self): + self.filter.filter_environments('ppc64le') + self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments.xml')) + + 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): + self.filter.filter_packages('ppc64le') + self.filter.cleanup() + self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-filter.xml')) + + def test_cleanup_after_filter_keep_group(self): + self.filter.filter_packages('ppc64le') + self.filter.cleanup(['standard']) + self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-keep.xml')) + + def test_cleanup_all(self): + self.filter.filter_packages('ppc64le') + self.filter.filter_groups('ppc64le') + self.filter.filter_environments('ppc64le') + self.filter.cleanup() + self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-all.xml'))