/tests/test_isoinfo.py

https://gitlab.com/libosinfo/osinfo-db
Python | 60 lines | 41 code | 9 blank | 10 comment | 10 complexity | 4dd0ea1d02af49f73b77183c857e2a63 MD5 | raw file
  1. # This work is licensed under the GNU GPLv2 or later.
  2. # See the COPYING file in the top-level directory.
  3. import glob
  4. import logging
  5. import os
  6. import pytest
  7. from . import util
  8. from . import isodata
  9. def _get_isodatapaths():
  10. """
  11. Collect iso media data and return a list of tuples:
  12. (osname, isodatapaths)
  13. """
  14. isodata_path = os.path.join(
  15. os.path.dirname(os.path.realpath(__file__)),
  16. 'isodata')
  17. ret = []
  18. allpaths = glob.glob(os.path.join(isodata_path, "*", "*"))
  19. for osdir in sorted(allpaths, key=util.human_sort):
  20. osname = os.path.basename(osdir)
  21. isodatapaths = glob.glob(os.path.join(osdir, "*.txt"))
  22. if len(isodatapaths):
  23. ret.append((osname, isodatapaths))
  24. return ret
  25. @pytest.mark.parametrize("testdata", _get_isodatapaths(), ids=lambda d: d[0])
  26. def test_iso_detection(testdata):
  27. osname, isodatapaths = testdata
  28. for isodatapath in isodatapaths:
  29. detected = []
  30. isodatamedia = isodata.get_isodatamedia(isodatapath)
  31. for osxml2 in util.DataFiles.oses():
  32. for media in osxml2.medias:
  33. if isodatamedia.match(media.iso):
  34. if osname != osxml2.shortid:
  35. logging.warning(
  36. 'ISO \'%s\' was matched by OS \'%s\' while it '
  37. 'should only be matched by OS \'%s\'',
  38. isodatamedia.filename, osxml2.shortid, osname)
  39. else:
  40. logging.info('ISO \'%s\' matched by OS \'%s\'',
  41. isodatamedia.filename, osxml2.shortid)
  42. # For several distros we do not have the volume-size
  43. # set as part of our DB, thus multiple detections may
  44. # occur. Although this case is not the optimal, as long
  45. # as we detect the very same distro it's okay-ish.
  46. if osxml2.shortid not in detected:
  47. detected.append(osxml2.shortid)
  48. if detected == [osname]:
  49. continue
  50. raise AssertionError("isodata: %s\nMatched=%s but expected=%s" %
  51. (isodatapath, detected, [osname]))