From fbf189d9c752fedf8d2ab8db3ec2fc748a7a81ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 12 Apr 2017 12:58:01 +0200 Subject: [PATCH] comps-wrapper: Add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This tests pretty much all the code that parses, filters and then writes comps back to a file. Signed-off-by: Lubomír Sedlář --- tests/fixtures/comps-env.xml | 125 +++++++++++++++++++++ tests/fixtures/comps-formatted.xml | 139 +++++++++++++++++++++++ tests/fixtures/comps-group.xml | 105 +++++++++++++++++ tests/fixtures/comps.xml | 175 +++++++++++++++++++++++++++++ tests/test_comps_wrapper.py | 79 +++++++++++++ 5 files changed, 623 insertions(+) create mode 100644 tests/fixtures/comps-env.xml create mode 100644 tests/fixtures/comps-formatted.xml create mode 100644 tests/fixtures/comps-group.xml create mode 100644 tests/fixtures/comps.xml create mode 100644 tests/test_comps_wrapper.py diff --git a/tests/fixtures/comps-env.xml b/tests/fixtures/comps-env.xml new file mode 100644 index 00000000..d8a0490f --- /dev/null +++ b/tests/fixtures/comps-env.xml @@ -0,0 +1,125 @@ + + + + + basic-desktop + Desktop + Basic Desktop packages + true + true + + dummy-imsettings-gnome + + + + core + Core + Kern + ማዕከላዊ ቦታ + Smallest possible installation + Kleinste moontlike installasie + ትንሹ የሚቻለው የማስገባት ሥራ + true + false + + dummy-bash + + + + firefox + Firefox Web Browser + + false + false + + Dummy-firefox + dummy-icedtea-web + + + + resilient-storage + Resilient Storage + Clustered storage, including the GFS2 filesystem. + false + true + en + + dummy-gfs2-utils + dummy-lvm2-cluster + dummy-pacemaker + dummy-resource-agents + + + + 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 + + + + minimal + Minimal install + Минимална инсталация + Instal·lació mínima + Basic functionality. + Основна функционалност. + Funcionalitat bàsica. + 10 + + core + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/fixtures/comps-formatted.xml b/tests/fixtures/comps-formatted.xml new file mode 100644 index 00000000..510acff6 --- /dev/null +++ b/tests/fixtures/comps-formatted.xml @@ -0,0 +1,139 @@ + + + + + basic-desktop + Desktop + Basic Desktop packages + true + true + + dummy-imsettings-gnome + + + + core + Core + Kern + ማዕከላዊ ቦታ + Smallest possible installation + Kleinste moontlike installasie + ትንሹ የሚቻለው የማስገባት ሥራ + true + false + + dummy-bash + + + + firefox + Firefox Web Browser + + false + false + + Dummy-firefox + dummy-icedtea-web + + + + resilient-storage + Resilient Storage + Clustered storage, including the GFS2 filesystem. + false + true + en + + dummy-gfs2-utils + dummy-lvm2-cluster + dummy-pacemaker + dummy-resource-agents + + + + 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 + + + + desktop + Desktop + Desktop. + 10 + + basic-desktop + core + standard + + + text-internet + + + + minimal + Minimal install + Минимална инсталация + Instal·lació mínima + Basic functionality. + Основна функционалност. + Funcionalitat bàsica. + 99 + + core + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/fixtures/comps-group.xml b/tests/fixtures/comps-group.xml new file mode 100644 index 00000000..ebf2207d --- /dev/null +++ b/tests/fixtures/comps-group.xml @@ -0,0 +1,105 @@ + + + + + basic-desktop + Desktop + Basic Desktop packages + true + true + + dummy-imsettings-gnome + + + + core + Core + Kern + ማዕከላዊ ቦታ + Smallest possible installation + Kleinste moontlike installasie + ትንሹ የሚቻለው የማስገባት ሥራ + false + true + + dummy-bash + + + + resilient-storage + Resilient Storage + Clustered storage, including the GFS2 filesystem. + false + true + en + + dummy-gfs2-utils + dummy-lvm2-cluster + dummy-pacemaker + dummy-resource-agents + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + desktop + Desktop + Desktop. + 10 + + basic-desktop + core + standard + + + text-internet + + + + minimal + Minimal install + Минимална инсталация + Instal·lació mínima + Basic functionality. + Основна функционалност. + Funcionalitat bàsica. + 99 + + core + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/fixtures/comps.xml b/tests/fixtures/comps.xml new file mode 100644 index 00000000..a303cf5c --- /dev/null +++ b/tests/fixtures/comps.xml @@ -0,0 +1,175 @@ + + + + + + + + core + Core + Kern + ማዕከላዊ ቦታ + Smallest possible installation + Kleinste moontlike installasie + ትንሹ የሚቻለው የማስገባት ሥራ + true + false + + dummy-bash + + + + + 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 + + + + + firefox + Firefox Web Browser + + false + false + + Dummy-firefox + dummy-icedtea-web + + + + + resilient-storage + Resilient Storage + Clustered storage, including the GFS2 filesystem. + false + true + en + + dummy-gfs2-utils + dummy-lvm2-cluster + dummy-pacemaker + dummy-resource-agents + + + + + basic-desktop + Desktop + Basic Desktop packages + true + true + + dummy-imsettings-gnome + + + + + + + minimal + Minimal install + Минимална инсталация + Instal·lació mínima + Basic functionality. + Основна функционалност. + Funcionalitat bàsica. + 99 + + core + + + + + + + desktop + Desktop + Desktop. + 10 + + core + standard + basic-desktop + + + text-internet + + + + + empty + Empty + Should not appear in the repos. + 10 + + does-not-exist + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 00000000..985fefe6 --- /dev/null +++ b/tests/test_comps_wrapper.py @@ -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"]}])