fix: class Python26CompatTestCase broken by minor python versions

Extract the version of Python interpreter using the `sys.version` will
break the Python26CompatTestCase class when the Python version is 3.11.

Rather the correct way to compare the Python version is using the
`sys.version_info` or the `platform` module as suggested in Python
official doc, https://docs.python.org/3/library/sys.html#sys.version.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2022-03-11 15:05:56 -05:00 committed by Till Maas
parent 8b8492eac6
commit da260c85cd

View file

@ -58,9 +58,9 @@ def pprint(msg, obj):
class Python26CompatTestCase(unittest.TestCase):
# pylint: disable=no-member
def assertRaisesRegex(self, exception, regex, *args, **kwargs):
if sys.version[:3] == "2.6":
if sys.version_info[:2] == (2, 6):
self.assertRaises(exception, *args, **kwargs)
elif sys.version[:3] < "3.2":
elif sys.version_info[:2] < (3, 2):
self.assertRaisesRegexp(exception, regex, *args, **kwargs)
else:
super(Python26CompatTestCase, self).assertRaisesRegex(