ut_misc.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env python3
  2. """
  3. test.unit_tests_d.ut_misc: miscellaneous unit tests for the MMGen suite
  4. """
  5. import re
  6. from collections import namedtuple
  7. from mmgen.color import yellow, blue
  8. from ..include.common import vmsg
  9. class unit_tests:
  10. def xmrwallet_uarg_info(self,name,ut): # WIP
  11. from mmgen.xmrwallet import xmrwallet_uarg_info as uarg_info
  12. vs = namedtuple('vector_data', ['text', 'groups'])
  13. fs = '{:16} {}'
  14. vmsg(blue(' ' + fs.format('ID','ANNOT')))
  15. for k,v in uarg_info.items():
  16. vmsg(' ' + fs.format(k, v[0]))
  17. vectors = {
  18. 'sweep_spec': (
  19. vs('1:2', "('1', '2', None, None)"),
  20. vs('1:2,3', "('1', '2', '3', None)"),
  21. vs('1:2,3:4', "('1', '2', '3', '4')"),
  22. ),
  23. }
  24. vmsg('')
  25. for k,v in uarg_info.items():
  26. vmsg(f' {k}')
  27. if k in vectors:
  28. vmsg(f' pat: {v.pat}')
  29. vmsg(f' vectors:')
  30. for vec in vectors[k]:
  31. m = re.match(v.pat, vec.text)
  32. vmsg(f' {vec.text:10} ==> {m.groups()}')
  33. assert str(m.groups()) == vec.groups
  34. else:
  35. vmsg(yellow(' TBD'))
  36. return True
  37. def pyversion(self,name,ut):
  38. from mmgen.pyversion import PythonVersion,python_version
  39. ver = {}
  40. fs = '{:<7} {:<9} {:<5} {}'
  41. vmsg('\n' + fs.format('Version','PyVersion','Major','Minor'))
  42. for k in ('current','3.3','3.12','4.3','7.0'):
  43. obj = python_version if k == 'current' else PythonVersion(k)
  44. major,minor = [int(s) for s in obj.split('.')]
  45. assert obj.major == major and obj.minor == minor
  46. vmsg(fs.format(k.upper(),obj,major,minor))
  47. ver[k] = obj
  48. vmsg('\nPerforming comparison tests:')
  49. assert ver['3.3'] == '3.3'
  50. assert ver['current'] < ver['7.0']
  51. assert ver['3.3'] < ver['4.3']
  52. assert ver['3.12'] < ver['7.0']
  53. assert ver['3.3'] < ver['3.12']
  54. assert ver['current'] < '7.0'
  55. assert ver['3.3'] < '4.3'
  56. assert ver['3.12'] < '7.0'
  57. assert ver['3.3'] < '3.12' # ensure we’re comparing numerically, not stringwise
  58. assert ver['current'] <= ver['current']
  59. assert ver['3.3'] <= '4.3'
  60. assert ver['3.12'] <= '7.0'
  61. assert ver['3.3'] <= '3.12'
  62. assert ver['current'] == ver['current']
  63. assert ver['3.3'] == ver['3.3']
  64. assert ver['3.3'] != ver['3.12']
  65. assert ver['3.3'] != ver['4.3']
  66. assert ver['3.3'] == '3.3'
  67. assert ver['3.3'] != '3.12'
  68. assert ver['3.3'] != '4.3'
  69. assert ver['current'] > '3.6'
  70. assert ver['7.0'] > ver['current']
  71. assert ver['4.3'] > '3.3'
  72. assert ver['3.12'] > '3.3'
  73. assert ver['current'] >= ver['current']
  74. assert ver['7.0'] >= ver['current']
  75. assert ver['4.3'] >= '3.3'
  76. assert ver['3.12'] >= '3.12'
  77. assert ver['3.12'] >= '3.3'
  78. assert '3.0' < ver['3.12'] < '3.13'
  79. assert '3.9' < ver['3.12'] # ensure we’re reverse comparing numerically, not stringwise
  80. assert '3.3' < ver['4.3'] <= '4.3'
  81. assert '4.3' <= ver['4.3'] <= '4.3'
  82. assert '4.3' == ver['4.3'] == '4.3'
  83. return True