[Libosinfo] [PATCH osinfo-db 3/7] tests: test_isoinfo: Parameterize based on input OS

Cole Robinson crobinso at redhat.com
Wed Mar 20 21:53:22 UTC 2019


Right now we run the test case for every OS, even if there's no
isodata/ tracked for it. Instead, only run the test if we detect an
osname from the special isodata/ dir naming. This revealed a few
issues:

* We weren't even testing windows data because it was looking for
  isodata/win, but the folder is isodata/windows.
* libosinfo was also testing .lng files specially. Our test chokes
  on them thinking they are isos. I've just opted to skip them for
  now.

Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
 tests/test_isoinfo.py | 53 +++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/tests/test_isoinfo.py b/tests/test_isoinfo.py
index 3476ea9..4d70d87 100644
--- a/tests/test_isoinfo.py
+++ b/tests/test_isoinfo.py
@@ -1,6 +1,7 @@
 # This work is licensed under the GNU GPLv2 or later.
 # See the COPYING file in the top-level directory.
 
+import glob
 import logging
 import os
 import pytest
@@ -8,18 +9,41 @@ import pytest
 from . import util
 
 
- at pytest.mark.parametrize('_os', util.DataFiles.oses(), ids=lambda o: o.shortid)
-def test_iso_detection(_os):
-    for isodatamedia in _get_isodatamedias(_os):
+def _get_isodatapaths():
+    """
+    Collect iso media data and return a list of tuples:
+        (osname, isodatapaths)
+    """
+    isodata_path = os.path.join(
+        os.path.dirname(os.path.realpath(__file__)),
+        'isodata')
+
+    ret = []
+    for osdir in glob.glob(os.path.join(isodata_path, "*", "*")):
+        osname = os.path.basename(osdir)
+        isodatapaths = glob.glob(os.path.join(osdir, "*"))
+        ret.append((osname, isodatapaths))
+    return ret
+
+
+ at pytest.mark.parametrize("testdata", _get_isodatapaths(), ids=lambda d: d[0])
+def test_iso_detection(testdata):
+    osname, isodatapaths = testdata
+    for isodatapath in isodatapaths:
+        if isodatapath.endswith(".lng"):
+            # libosinfo handled these specially, we should too
+            continue
+
         detected = []
+        isodatamedia = _get_isodatamedia(isodatapath)
         for __os in util.DataFiles.oses():
             for media in __os.medias:
                 if isodatamedia.match(media.iso):
-                    if _os.shortid != __os.shortid:
+                    if osname != __os.shortid:
                         logging.warning(
                             'ISO \'%s\' was matched by OS \'%s\' while it '
                             'should only be matched by OS \'%s\'',
-                            isodatamedia.filename, __os.shortid, _os.shortid)
+                            isodatamedia.filename, __os.shortid, osname)
                     else:
                         logging.info('ISO \'%s\' matched by OS \'%s\'',
                                      isodatamedia.filename, __os.shortid)
@@ -124,22 +148,3 @@ def _get_isodatamedia(filepath):
 
     return _ISODataMedia(filepath, volumeid, publisherid, systemid,
                          applicationid, volumesize)
-
-
-def _get_isodatamedias(_os):
-    isodata_path = os.path.join(
-        os.path.dirname(os.path.realpath(__file__)),
-        'isodata')
-    shortid_path = os.path.join(isodata_path, _os.distro, _os.shortid)
-
-    medias = []
-    if not os.path.exists(shortid_path):
-        return []
-
-    for _file in os.listdir(shortid_path):
-        path = os.path.join(shortid_path, _file)
-        if not os.path.exists(path):
-            continue
-
-        medias.append(_get_isodatamedia(path, _os.shortid))
-    return medias
-- 
2.21.0




More information about the Libosinfo mailing list