[osinfo-db PATCH 2/4] test: Add firmware related tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For now, similarly to what's done for devices, let's ensure an OS
doesn't have the same firmware entry already listed in the parent.

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 tests/osinfo.py         | 17 +++++++++++++++++
 tests/test_firmwares.py | 27 +++++++++++++++++++++++++++
 tests/util.py           | 11 ++++++++++-
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 tests/test_firmwares.py

diff --git a/tests/osinfo.py b/tests/osinfo.py
index 3585f44..8a94ef3 100644
--- a/tests/osinfo.py
+++ b/tests/osinfo.py
@@ -137,6 +137,13 @@ class Os(_XMLBase):
     def get_network_install_resources(self, node):
         return self._get_resources(node, 'network-install')
 
+    @_cache_property
+    def firmwares(self):
+        firmwares = []
+        firmwarelist = self._root.findall('firmware')
+        for firmware in firmwarelist:
+            firmwares.append(Firmware(firmware))
+        return firmwares
 
 class Resources(_XMLBase):
     @_cache_property
@@ -156,6 +163,16 @@ class Resources(_XMLBase):
         return self._get_int('storage')
 
 
+class Firmware(_XMLBase):
+    @_cache_property
+    def arch(self):
+        return self._root.attrib["arch"]
+
+    @_cache_property
+    def firmware_type(self):
+        return self._root.attrib["type"]
+
+
 class Image(_XMLBase):
     @_cache_property
     def url(self):
diff --git a/tests/test_firmwares.py b/tests/test_firmwares.py
new file mode 100644
index 0000000..4dad7d4
--- /dev/null
+++ b/tests/test_firmwares.py
@@ -0,0 +1,27 @@
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+import re
+
+from . import util
+
+
+def _check_duplicate_firmwares(osxml):
+    """
+    Ensure an OS doesn't list a firmware that's defined in the parent
+    """
+    broken = []
+    related = util.DataFiles.getosxml_related(osxml)
+    for osxml2 in related:
+        if osxml2.firmwares is not None:
+            for firmware2 in osxml2.firmwares:
+                for firmware in osxml.firmwares:
+                    if firmware.arch == firmware2.arch and \
+                       firmware.firmware_type == firmware2.firmware_type:
+                        broken.append([firmware.firmware_type, firmware.arch])
+    assert broken == []
+
+
+@util.os_parametrize('osxml', filter_firmwares=True)
+def test_firmwares_duplication(osxml):
+    _check_duplicate_firmwares(osxml)
diff --git a/tests/util.py b/tests/util.py
index f60ef9b..726ae05 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -35,6 +35,7 @@ class _Files():
         self._all_xml_cache = []
         self._oses_cache = []
         self._devices_cache = []
+        self._firmwares_cache = []
         self._os_related_cache = defaultdict(list)
         self._files_format = files_format
 
@@ -62,7 +63,7 @@ class _Files():
                 p.startswith(os.path.join(self.datadir, dirname))]
 
     def oses(self, filter_media=False, filter_trees=False, filter_images=False,
-            filter_devices=False, filter_resources=False):
+            filter_devices=False, filter_resources=False, filter_firmwares=False):
         """
         Return a list of osinfo.Os objects
 
@@ -84,6 +85,8 @@ class _Files():
             oses = [o for o in oses if o.devices]
         if filter_resources:
             oses = [o for o in oses if o.resources_list]
+        if filter_firmwares:
+            oses = [o for o in oses if o.firmwares]
         return oses
 
     def getosxml_related(self, osxml):
@@ -118,6 +121,12 @@ class _Files():
                 self._devices_cache.append(osinfo.Device(path))
         return self._devices_cache
 
+    def firmwares(self):
+        if not self._firmwares_cache:
+            for path in self._filter_xml('firmware'):
+                self._firmwares_cache.append(osinfo.Firmware(path))
+        return self._firmwares_cache
+
     def xmls(self):
         return self._get_all_xml()
 
-- 
2.21.0

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux