comps: Add tests for CompsFilter

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-04-06 10:10:17 +02:00
parent 7ea4c33d87
commit de231064b7
15 changed files with 844 additions and 6 deletions

View File

@ -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()

View File

@ -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):
"""

19
tests/fixtures/comps-cleanup-all.xml vendored Normal file
View File

@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq>Dummy-firefox</packagereq>
</packagelist>
</group>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
</comps>

43
tests/fixtures/comps-cleanup-filter.xml vendored Normal file
View File

@ -0,0 +1,43 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq>Dummy-firefox</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
</comps>

60
tests/fixtures/comps-cleanup-keep.xml vendored Normal file
View File

@ -0,0 +1,60 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq>Dummy-firefox</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist/>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
</comps>

63
tests/fixtures/comps-cleanup.xml vendored Normal file
View File

@ -0,0 +1,63 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
</comps>

View File

@ -0,0 +1,69 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -0,0 +1,71 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group>
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -0,0 +1,79 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq>Dummy-firefox</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist/>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -0,0 +1,63 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
</comps>

View File

@ -0,0 +1,60 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -0,0 +1,79 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -0,0 +1,76 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<description>Smallest possible installation</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<description>Basic functionality.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<description>Applications to perform a variety of tasks</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

82
tests/fixtures/comps.xml.in vendored Normal file
View File

@ -0,0 +1,82 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -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'))