Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_pluginversion.py 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import unittest
  2. from lodel.plugin.plugins import PluginVersion
  3. from lodel.plugin.exceptions import PluginVersionError
  4. class PluginVersionTestCase(unittest.TestCase):
  5. def test_init_str(self):
  6. """Tests PluginVersion instanciation from string"""
  7. test_datas = [(1,2,3), (0,0,0), (54,0,1)]
  8. for test_data in test_datas:
  9. str_init = '.'.join([str(v) for v in test_data])
  10. v = PluginVersion(str_init)
  11. self.assertEqual(str(v), str_init)
  12. for i, field in enumerate(['major', 'minor', 'revision']):
  13. self.assertEqual(test_data[i], getattr(v, field))
  14. def test_init_short_str(self):
  15. """ Tests PluginVersion instanciation from string with less than
  16. 3 numbers"""
  17. #Tuples with shortstr, expected result
  18. test_datas = [
  19. ("1", "1.0.0"),
  20. ("42", "42.0.0"),
  21. ("0.1", "0.1.0"),
  22. ("1.0", "1.0.0"),
  23. ("0", "0.0.0")]
  24. for test_str, expt_res in test_datas:
  25. v = PluginVersion(test_str)
  26. self.assertEqual(expt_res, str(v),
  27. "When instanctiated with '%s' expected result was '%s', but \
  28. got : '%s'" % (test_str, expt_res, str(v)))
  29. def test_init_invalid_str(self):
  30. """Tests PluginVersion instanciation from invalid string"""
  31. test_datas = {
  32. 'bad count': '1.2.3.4.5',
  33. 'bad values': 'a.1.2',
  34. 'bad separators': '1;2;3',
  35. 'bad value': 'foobar' }
  36. for fail_reason, value in test_datas.items():
  37. with self.assertRaises(PluginVersionError,msg="Instanciation \
  38. should fail when '%s' is given as argument because it is a %s" % (
  39. value, fail_reason)):
  40. v = PluginVersion(value)
  41. def test_comparison(self):
  42. """ Tests comparison operators on PluginVersion """
  43. cmp_funs = [
  44. PluginVersion.__lt__,
  45. PluginVersion.__le__,
  46. PluginVersion.__eq__,
  47. PluginVersion.__ne__,
  48. PluginVersion.__gt__,
  49. PluginVersion.__ge__]
  50. cmp_values_res = [
  51. ( ("0.0.0", "0.0.0"),
  52. (False, True, True, False, False, True)),
  53. ( ("1.0.0", "0.0.0"),
  54. (False, False, False, True, True, True)),
  55. ( ("0.0.0", "1.0.0"),
  56. (True, True, False, True, False, False)),
  57. ( ("3.2.1", "2.2.1"),
  58. (False, False, False, True, True, True)),
  59. ( ("3.2.1", "3.2.2"),
  60. (True, True, False, True, False, False)),
  61. ( ("3.2.1", "3.3.0"),
  62. (True, True, False, True, False, False)),
  63. ( ("3.2.2018", "3.2.1"),
  64. (False, False, False, True, True, True)),
  65. ( ("3.42.0", "3.24.520000"),
  66. (False, False, False, True, True, True))
  67. ]
  68. for cmp_cnt, (cmp_str_values, expt_res) in enumerate(cmp_values_res):
  69. cmp_values = tuple([PluginVersion(v) for v in cmp_str_values])
  70. for i, cmp_fun in enumerate(cmp_funs):
  71. if expt_res[i]:
  72. self.assertTrue(cmp_fun(*cmp_values),
  73. msg="Expected comparison %d %s%s to be True, but False \
  74. returned" % (cmp_cnt, cmp_fun, cmp_values))
  75. else:
  76. self.assertFalse(cmp_fun(*cmp_values),
  77. msg="Expected comparison %d %s%s to be False, but True \
  78. returned" % (cmp_cnt, cmp_fun, cmp_values))