No Description
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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import unittest
  20. from lodel.plugin.plugins import PluginVersion
  21. from lodel.plugin.exceptions import PluginVersionError
  22. class PluginVersionTestCase(unittest.TestCase):
  23. def test_init_str(self):
  24. """Tests PluginVersion instanciation from string"""
  25. test_datas = [(1,2,3), (0,0,0), (54,0,1)]
  26. for test_data in test_datas:
  27. str_init = '.'.join([str(v) for v in test_data])
  28. v = PluginVersion(str_init)
  29. self.assertEqual(str(v), str_init)
  30. for i, field in enumerate(['major', 'minor', 'revision']):
  31. self.assertEqual(test_data[i], getattr(v, field))
  32. def test_init_short_str(self):
  33. """ Tests PluginVersion instanciation from string with less than
  34. 3 numbers"""
  35. #Tuples with shortstr, expected result
  36. test_datas = [
  37. ("1", "1.0.0"),
  38. ("42", "42.0.0"),
  39. ("0.1", "0.1.0"),
  40. ("1.0", "1.0.0"),
  41. ("0", "0.0.0")]
  42. for test_str, expt_res in test_datas:
  43. v = PluginVersion(test_str)
  44. self.assertEqual(expt_res, str(v),
  45. "When instanctiated with '%s' expected result was '%s', but \
  46. got : '%s'" % (test_str, expt_res, str(v)))
  47. def test_init_invalid_str(self):
  48. """Tests PluginVersion instanciation from invalid string"""
  49. test_datas = {
  50. 'bad count': '1.2.3.4.5',
  51. 'bad values': 'a.1.2',
  52. 'bad separators': '1;2;3',
  53. 'bad value': 'foobar' }
  54. for fail_reason, value in test_datas.items():
  55. with self.assertRaises(PluginVersionError,msg="Instanciation \
  56. should fail when '%s' is given as argument because it is a %s" % (
  57. value, fail_reason)):
  58. v = PluginVersion(value)
  59. def test_comparison(self):
  60. """ Tests comparison operators on PluginVersion """
  61. cmp_funs = [
  62. PluginVersion.__lt__,
  63. PluginVersion.__le__,
  64. PluginVersion.__eq__,
  65. PluginVersion.__ne__,
  66. PluginVersion.__gt__,
  67. PluginVersion.__ge__]
  68. cmp_values_res = [
  69. ( ("0.0.0", "0.0.0"),
  70. (False, True, True, False, False, True)),
  71. ( ("1.0.0", "0.0.0"),
  72. (False, False, False, True, True, True)),
  73. ( ("0.0.0", "1.0.0"),
  74. (True, True, False, True, False, False)),
  75. ( ("3.2.1", "2.2.1"),
  76. (False, False, False, True, True, True)),
  77. ( ("3.2.1", "3.2.2"),
  78. (True, True, False, True, False, False)),
  79. ( ("3.2.1", "3.3.0"),
  80. (True, True, False, True, False, False)),
  81. ( ("3.2.2018", "3.2.1"),
  82. (False, False, False, True, True, True)),
  83. ( ("3.42.0", "3.24.520000"),
  84. (False, False, False, True, True, True))
  85. ]
  86. for cmp_cnt, (cmp_str_values, expt_res) in enumerate(cmp_values_res):
  87. cmp_values = tuple([PluginVersion(v) for v in cmp_str_values])
  88. for i, cmp_fun in enumerate(cmp_funs):
  89. if expt_res[i]:
  90. self.assertTrue(cmp_fun(*cmp_values),
  91. msg="Expected comparison %d %s%s to be True, but False \
  92. returned" % (cmp_cnt, cmp_fun, cmp_values))
  93. else:
  94. self.assertFalse(cmp_fun(*cmp_values),
  95. msg="Expected comparison %d %s%s to be False, but True \
  96. returned" % (cmp_cnt, cmp_fun, cmp_values))