ut_misc.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. """
  3. test.unit_tests_d.ut_misc: miscellaneous unit tests for the MMGen suite
  4. """
  5. class unit_tests:
  6. def pyversion(self,name,ut):
  7. from ..include.common import vmsg
  8. from mmgen.pyversion import PythonVersion,python_version
  9. ver = {}
  10. fs = '{:<7} {:<9} {:<5} {}'
  11. vmsg('\n' + fs.format('Version','PyVersion','Major','Minor'))
  12. for k in ('current','3.3','3.12','4.3','7.0'):
  13. obj = python_version if k == 'current' else PythonVersion(k)
  14. major,minor = [int(s) for s in obj.split('.')]
  15. assert obj.major == major and obj.minor == minor
  16. vmsg(fs.format(k.upper(),obj,major,minor))
  17. ver[k] = obj
  18. vmsg('\nPerforming comparison tests:')
  19. assert ver['3.3'] == '3.3'
  20. assert ver['current'] < ver['7.0']
  21. assert ver['3.3'] < ver['4.3']
  22. assert ver['3.12'] < ver['7.0']
  23. assert ver['3.3'] < ver['3.12']
  24. assert ver['current'] < '7.0'
  25. assert ver['3.3'] < '4.3'
  26. assert ver['3.12'] < '7.0'
  27. assert ver['3.3'] < '3.12' # ensure we’re comparing numerically, not stringwise
  28. assert ver['current'] <= ver['current']
  29. assert ver['3.3'] <= '4.3'
  30. assert ver['3.12'] <= '7.0'
  31. assert ver['3.3'] <= '3.12'
  32. assert ver['current'] == ver['current']
  33. assert ver['3.3'] == ver['3.3']
  34. assert ver['3.3'] != ver['3.12']
  35. assert ver['3.3'] != ver['4.3']
  36. assert ver['3.3'] == '3.3'
  37. assert ver['3.3'] != '3.12'
  38. assert ver['3.3'] != '4.3'
  39. assert ver['current'] > '3.6'
  40. assert ver['7.0'] > ver['current']
  41. assert ver['4.3'] > '3.3'
  42. assert ver['3.12'] > '3.3'
  43. assert ver['current'] >= ver['current']
  44. assert ver['7.0'] >= ver['current']
  45. assert ver['4.3'] >= '3.3'
  46. assert ver['3.12'] >= '3.12'
  47. assert ver['3.12'] >= '3.3'
  48. assert '3.0' < ver['3.12'] < '3.13'
  49. assert '3.9' < ver['3.12'] # ensure we’re reverse comparing numerically, not stringwise
  50. assert '3.3' < ver['4.3'] <= '4.3'
  51. assert '4.3' <= ver['4.3'] <= '4.3'
  52. assert '4.3' == ver['4.3'] == '4.3'
  53. return True