[PATCH osinfo-db 07/10] tests: Simplify pytest parameterize calls

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

 



- Call oses()/xmls() directly
- Use lambda functions for ids= callback
- Rename '_file' parameters to 'path'

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 tests/test_isoinfo.py    | 11 ++---------
 tests/test_urls.py       | 13 +++----------
 tests/test_validation.py | 11 +++--------
 3 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/tests/test_isoinfo.py b/tests/test_isoinfo.py
index 7e3f7b0..9477942 100644
--- a/tests/test_isoinfo.py
+++ b/tests/test_isoinfo.py
@@ -9,14 +9,7 @@ import pytest
 from . import util
 
 
-OSES = util.DataFiles.oses()
-
-
-def _os_id(_os):
-    return _os.shortid
-
-
-@pytest.mark.parametrize('_os', [*OSES], ids=_os_id)
+@pytest.mark.parametrize('_os', util.DataFiles.oses(), ids=lambda o: o.shortid)
 def test_iso_detection(_os):
     expensive = os.environ.get('OSINFO_DB_ENABLE_EXPENSIVE')
     if expensive is not None:
@@ -24,7 +17,7 @@ def test_iso_detection(_os):
     expensive = bool(expensive)
     for isodatamedia in _get_isodatamedias(_os):
         detected = []
-        for __os in OSES:
+        for __os in util.DataFiles.oses():
             if not expensive and _os.shortid != __os.shortid:
                 continue
             for media in __os.medias:
diff --git a/tests/test_urls.py b/tests/test_urls.py
index 2429e5c..4cc38e7 100644
--- a/tests/test_urls.py
+++ b/tests/test_urls.py
@@ -7,14 +7,7 @@ import pytest
 from . import util
 
 
-OSES = util.DataFiles.oses()
-
-
-def _os_id(_os):
-    return _os.shortid
-
-
-@pytest.mark.parametrize('_os', [*OSES], ids=_os_id)
+@pytest.mark.parametrize('_os', util.DataFiles.oses(), ids=lambda o: o.shortid)
 @pytest.mark.skipif(os.environ.get('OSINFO_DB_NETWORK_TESTS') is None,
                     reason='Network related tests are not enabled')
 def test_images_url(_os):
@@ -26,7 +19,7 @@ def test_images_url(_os):
     assert broken == []
 
 
-@pytest.mark.parametrize('_os', [*OSES], ids=_os_id)
+@pytest.mark.parametrize('_os', util.DataFiles.oses(), ids=lambda o: o.shortid)
 @pytest.mark.skipif(os.environ.get('OSINFO_DB_NETWORK_TESTS') is None,
                     reason='Network related tests are not enabled')
 def test_medias_url(_os):
@@ -38,7 +31,7 @@ def test_medias_url(_os):
     assert broken == []
 
 
-@pytest.mark.parametrize('_os', [*OSES], ids=_os_id)
+@pytest.mark.parametrize('_os', util.DataFiles.oses(), ids=lambda o: o.shortid)
 @pytest.mark.skipif(os.environ.get('OSINFO_DB_NETWORK_TESTS') is None,
                     reason='Network related tests are not enabled')
 def test_trees_url(_os):
diff --git a/tests/test_validation.py b/tests/test_validation.py
index ec9fbec..8c71454 100755
--- a/tests/test_validation.py
+++ b/tests/test_validation.py
@@ -7,17 +7,12 @@ import pytest
 from . import util
 
 
-XMLS = util.DataFiles.xmls()
 SCHEMA = util.DataFiles.schema
 PARSER = libxml2.relaxNGNewParserCtxt(SCHEMA)
 VALID = PARSER.relaxNGParse().relaxNGNewValidCtxt()
 
 
-def _file_id(_file):
-    return _file
-
-
-@pytest.mark.parametrize('_file', [*XMLS], ids=_file_id)
-def test_validation(_file):
-    doc = libxml2.parseFile(_file)
+@pytest.mark.parametrize("path", util.DataFiles.xmls(), ids=lambda path: path)
+def test_validation(path):
+    doc = libxml2.parseFile(path)
     assert VALID.relaxNGValidateDoc(doc) == 0
-- 
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