comps-wrapper: Add tests

This tests pretty much all the code that parses, filters and then writes
comps back to a file.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-04-12 12:58:01 +02:00
parent daf3628594
commit fbf189d9c7
5 changed files with 623 additions and 0 deletions

125
tests/fixtures/comps-env.xml vendored Normal file
View File

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps
PUBLIC '-//Red Hat, Inc.//DTD Comps info//EN'
'comps.dtd'>
<comps>
<group>
<id>basic-desktop</id>
<name>Desktop</name>
<description>Basic Desktop packages</description>
<default>true</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq requires="dummy-imsettings" type="conditional">dummy-imsettings-gnome</packagereq>
</packagelist>
</group>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<name xml:lang="am">ማዕከላዊ ቦታ</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<description xml:lang="am">ትንሹ የሚቻለው የማስገባት ሥራ</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq type="mandatory">dummy-bash</packagereq>
</packagelist>
</group>
<group>
<id>firefox</id>
<name>Firefox Web Browser</name>
<description/>
<default>false</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq type="mandatory">Dummy-firefox</packagereq>
<packagereq type="mandatory">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group>
<id>resilient-storage</id>
<name>Resilient Storage</name>
<description>Clustered storage, including the GFS2 filesystem.</description>
<default>false</default>
<uservisible>true</uservisible>
<langonly>en</langonly>
<packagelist>
<packagereq type="mandatory">dummy-gfs2-utils</packagereq>
<packagereq type="mandatory">dummy-lvm2-cluster</packagereq>
<packagereq type="mandatory">dummy-pacemaker</packagereq>
<packagereq type="mandatory">dummy-resource-agents</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 type="mandatory">dummy-lvm2</packagereq>
</packagelist>
</group>
<group>
<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>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<name xml:lang="am">መጠቀሚያ ፕሮግራሞች</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>
<environment>
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<name xml:lang="ca">Instal·lació mínima</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<description xml:lang="ca">Funcionalitat bàsica.</description>
<display_order>10</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
<match install="aspell-%s" name="aspell"/>
<match install="autocorr-%s" name="autocorr-en"/>
<match install="calligra-l10n-%s" name="calligra-core"/>
<match install="childsplay-alphabet_sounds_%s" name="childsplay"/>
<match install="eclipse-nls-%s" name="eclipse-platform"/>
<match install="firefox-langpack-%s" name="firefox"/>
<match install="gcompris-sound-%s" name="gcompris"/>
<match install="gimp-help-%s" name="gimp-help"/>
<match install="hunspell-%s" name="hunspell"/>
<match install="hyphen-%s" name="hyphen"/>
<match install="kde-l10n-%s" name="kdelibs"/>
<match install="kde-i18n-%s" name="kdelibs3"/>
<match install="libreoffice-langpack-%s" name="libreoffice-core"/>
<match install="man-pages-%s" name="man-pages"/>
<match install="moodle-%s" name="moodle"/>
<match install="mythes-%s" name="mythes"/>
<match install="nqc-doc-%s" name="nqc-doc"/>
<match install="openoffice.org-langpack-%s" name="openoffice.org-core"/>
<match install="tesseract-langpack-%s" name="tesseract"/>
<match install="tkgate-%s" name="tkgate"/>
<match install="dummy-release-notes-%s" name="dummy-release-notes"/>
</langpacks>
</comps>

139
tests/fixtures/comps-formatted.xml vendored Normal file
View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps
PUBLIC '-//Red Hat, Inc.//DTD Comps info//EN'
'comps.dtd'>
<comps>
<group>
<id>basic-desktop</id>
<name>Desktop</name>
<description>Basic Desktop packages</description>
<default>true</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq requires="dummy-imsettings" type="conditional">dummy-imsettings-gnome</packagereq>
</packagelist>
</group>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<name xml:lang="am">ማዕከላዊ ቦታ</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<description xml:lang="am">ትንሹ የሚቻለው የማስገባት ሥራ</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq type="mandatory">dummy-bash</packagereq>
</packagelist>
</group>
<group>
<id>firefox</id>
<name>Firefox Web Browser</name>
<description/>
<default>false</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq type="mandatory">Dummy-firefox</packagereq>
<packagereq type="mandatory">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group>
<id>resilient-storage</id>
<name>Resilient Storage</name>
<description>Clustered storage, including the GFS2 filesystem.</description>
<default>false</default>
<uservisible>true</uservisible>
<langonly>en</langonly>
<packagelist>
<packagereq type="mandatory">dummy-gfs2-utils</packagereq>
<packagereq type="mandatory">dummy-lvm2-cluster</packagereq>
<packagereq type="mandatory">dummy-pacemaker</packagereq>
<packagereq type="mandatory">dummy-resource-agents</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 type="mandatory">dummy-lvm2</packagereq>
</packagelist>
</group>
<group>
<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>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<name xml:lang="am">መጠቀሚያ ፕሮግራሞች</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>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>basic-desktop</groupid>
<groupid>core</groupid>
<groupid>standard</groupid>
</grouplist>
<optionlist>
<groupid>text-internet</groupid>
</optionlist>
</environment>
<environment>
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<name xml:lang="ca">Instal·lació mínima</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<description xml:lang="ca">Funcionalitat bàsica.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
<match install="aspell-%s" name="aspell"/>
<match install="autocorr-%s" name="autocorr-en"/>
<match install="calligra-l10n-%s" name="calligra-core"/>
<match install="childsplay-alphabet_sounds_%s" name="childsplay"/>
<match install="eclipse-nls-%s" name="eclipse-platform"/>
<match install="firefox-langpack-%s" name="firefox"/>
<match install="gcompris-sound-%s" name="gcompris"/>
<match install="gimp-help-%s" name="gimp-help"/>
<match install="hunspell-%s" name="hunspell"/>
<match install="hyphen-%s" name="hyphen"/>
<match install="kde-l10n-%s" name="kdelibs"/>
<match install="kde-i18n-%s" name="kdelibs3"/>
<match install="libreoffice-langpack-%s" name="libreoffice-core"/>
<match install="man-pages-%s" name="man-pages"/>
<match install="moodle-%s" name="moodle"/>
<match install="mythes-%s" name="mythes"/>
<match install="nqc-doc-%s" name="nqc-doc"/>
<match install="openoffice.org-langpack-%s" name="openoffice.org-core"/>
<match install="tesseract-langpack-%s" name="tesseract"/>
<match install="tkgate-%s" name="tkgate"/>
<match install="dummy-release-notes-%s" name="dummy-release-notes"/>
</langpacks>
</comps>

105
tests/fixtures/comps-group.xml vendored Normal file
View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps
PUBLIC '-//Red Hat, Inc.//DTD Comps info//EN'
'comps.dtd'>
<comps>
<group>
<id>basic-desktop</id>
<name>Desktop</name>
<description>Basic Desktop packages</description>
<default>true</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq requires="dummy-imsettings" type="conditional">dummy-imsettings-gnome</packagereq>
</packagelist>
</group>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<name xml:lang="am">ማዕከላዊ ቦታ</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<description xml:lang="am">ትንሹ የሚቻለው የማስገባት ሥራ</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="mandatory">dummy-bash</packagereq>
</packagelist>
</group>
<group>
<id>resilient-storage</id>
<name>Resilient Storage</name>
<description>Clustered storage, including the GFS2 filesystem.</description>
<default>false</default>
<uservisible>true</uservisible>
<langonly>en</langonly>
<packagelist>
<packagereq type="mandatory">dummy-gfs2-utils</packagereq>
<packagereq type="mandatory">dummy-lvm2-cluster</packagereq>
<packagereq type="mandatory">dummy-pacemaker</packagereq>
<packagereq type="mandatory">dummy-resource-agents</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 type="mandatory">dummy-lvm2</packagereq>
</packagelist>
</group>
<environment>
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>basic-desktop</groupid>
<groupid>core</groupid>
<groupid>standard</groupid>
</grouplist>
<optionlist>
<groupid>text-internet</groupid>
</optionlist>
</environment>
<environment>
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<name xml:lang="ca">Instal·lació mínima</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<description xml:lang="ca">Funcionalitat bàsica.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
<match install="aspell-%s" name="aspell"/>
<match install="autocorr-%s" name="autocorr-en"/>
<match install="calligra-l10n-%s" name="calligra-core"/>
<match install="childsplay-alphabet_sounds_%s" name="childsplay"/>
<match install="eclipse-nls-%s" name="eclipse-platform"/>
<match install="firefox-langpack-%s" name="firefox"/>
<match install="gcompris-sound-%s" name="gcompris"/>
<match install="gimp-help-%s" name="gimp-help"/>
<match install="hunspell-%s" name="hunspell"/>
<match install="hyphen-%s" name="hyphen"/>
<match install="kde-l10n-%s" name="kdelibs"/>
<match install="kde-i18n-%s" name="kdelibs3"/>
<match install="libreoffice-langpack-%s" name="libreoffice-core"/>
<match install="man-pages-%s" name="man-pages"/>
<match install="moodle-%s" name="moodle"/>
<match install="mythes-%s" name="mythes"/>
<match install="nqc-doc-%s" name="nqc-doc"/>
<match install="openoffice.org-langpack-%s" name="openoffice.org-core"/>
<match install="tesseract-langpack-%s" name="tesseract"/>
<match install="tkgate-%s" name="tkgate"/>
<match install="dummy-release-notes-%s" name="dummy-release-notes"/>
</langpacks>
</comps>

175
tests/fixtures/comps.xml vendored Normal file
View File

@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<!-- GROUPS -->
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<name xml:lang="am">ማዕከላዊ ቦታ</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<description xml:lang="am">ትንሹ የሚቻለው የማስገባት ሥራ</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq type="mandatory">dummy-bash</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>dummy-lvm2</packagereq>
</packagelist>
</group>
<group>
<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>
<group>
<id>firefox</id>
<name>Firefox Web Browser</name>
<description/>
<default>false</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq>Dummy-firefox</packagereq>
<packagereq>dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>resilient-storage</id>
<name>Resilient Storage</name>
<description>Clustered storage, including the GFS2 filesystem.</description>
<default>false</default>
<uservisible>true</uservisible>
<langonly>en</langonly>
<packagelist>
<packagereq type="mandatory">dummy-gfs2-utils</packagereq>
<packagereq type="mandatory">dummy-lvm2-cluster</packagereq>
<packagereq type="mandatory">dummy-pacemaker</packagereq>
<packagereq type="mandatory">dummy-resource-agents</packagereq>
</packagelist>
</group>
<group>
<id>basic-desktop</id>
<name>Desktop</name>
<description>Basic Desktop packages</description>
<default>true</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="conditional" requires="dummy-imsettings">dummy-imsettings-gnome</packagereq>
</packagelist>
</group>
<!-- ENVIRONMENTS -->
<environment>
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<name xml:lang="ca">Instal·lació mínima</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<description xml:lang="ca">Funcionalitat bàsica.</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>core</groupid>
<groupid>standard</groupid>
<groupid>basic-desktop</groupid>
</grouplist>
<optionlist>
<groupid>text-internet</groupid>
</optionlist>
</environment>
<environment>
<id>empty</id>
<name>Empty</name>
<description>Should not appear in the repos.</description>
<display_order>10</display_order>
<grouplist>
<groupid>does-not-exist</groupid>
</grouplist>
</environment>
<!-- LANGPACKS -->
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
<match install="aspell-%s" name="aspell"/>
<match install="autocorr-%s" name="autocorr-en"/>
<match install="calligra-l10n-%s" name="calligra-core"/>
<match install="childsplay-alphabet_sounds_%s" name="childsplay"/>
<match install="eclipse-nls-%s" name="eclipse-platform"/>
<match install="firefox-langpack-%s" name="firefox"/>
<match install="gcompris-sound-%s" name="gcompris"/>
<match install="gimp-help-%s" name="gimp-help"/>
<match install="hunspell-%s" name="hunspell"/>
<match install="hyphen-%s" name="hyphen"/>
<match install="kde-l10n-%s" name="kdelibs"/>
<match install="kde-i18n-%s" name="kdelibs3"/>
<match install="libreoffice-langpack-%s" name="libreoffice-core"/>
<match install="man-pages-%s" name="man-pages"/>
<match install="moodle-%s" name="moodle"/>
<match install="mythes-%s" name="mythes"/>
<match install="nqc-doc-%s" name="nqc-doc"/>
<match install="openoffice.org-langpack-%s" name="openoffice.org-core"/>
<match install="tesseract-langpack-%s" name="tesseract"/>
<match install="tkgate-%s" name="tkgate"/>
<match install="dummy-release-notes-%s" name="dummy-release-notes"/>
</langpacks>
<!-- CATEGORIES -->
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<name xml:lang="am">መጠቀሚያ ፕሮግራሞች</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 @@
# -*- coding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
import tempfile
import difflib
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from pungi.wrappers.comps import CompsWrapper
from tests.helpers import FIXTURE_DIR
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')
class CompsWrapperTest(unittest.TestCase):
def setUp(self):
self.file = tempfile.NamedTemporaryFile(prefix='comps-wrapper-test-')
def assertFilesEqual(self, fn1, fn2):
with open(fn1) as f1:
lines1 = f1.read().splitlines()
with open(fn2) as f2:
lines2 = f2.read().splitlines()
diff = '\n'.join(difflib.unified_diff(lines1, lines2,
fromfile='EXPECTED', tofile='ACTUAL'))
self.assertEqual(diff, '', 'Files differ:\n' + diff)
def test_get_groups(self):
comps = CompsWrapper(COMPS_FILE)
self.assertItemsEqual(
comps.get_comps_groups(),
['core', 'standard', 'text-internet', 'firefox', 'resilient-storage', 'basic-desktop'])
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"]}])