From 74ed569fe0dd83d0da1276680d398ad9f2c705b7 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 17 Mar 2023 11:18:27 +1000 Subject: [PATCH] test: skip the oeffis tests if we don't have dbusmock 0.28.5 --- test/test_oeffis.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/test_oeffis.py b/test/test_oeffis.py index b69e028..1b18fb7 100644 --- a/test/test_oeffis.py +++ b/test/test_oeffis.py @@ -50,6 +50,7 @@ from ctypes import c_char_p, c_int, c_uint32, c_void_p from typing import Dict, List, Tuple, Type, Optional, TextIO from gi.repository import GLib # type: ignore from dbus.mainloop.glib import DBusGMainLoop +import unittest import attr import ctypes @@ -66,6 +67,16 @@ DBusGMainLoop(set_as_default=True) PREFIX = "oeffis_" +def version_at_least(have, required) -> bool: + for h, r in zip(have.split("."), required.split(".")): + if h < r: + return False + elif h > r: + return True + + return True + + @attr.s class _Api: name: str = attr.ib() @@ -291,6 +302,10 @@ class TestOeffis(dbusmock.DBusTestCase): Test class that sets up a mocked DBus session bus to be used by liboeffis.so. """ + @unittest.skipIf( + not version_at_least(dbusmock.__version__, "0.28.5"), + "dbusmock >= 0.28.5 required", + ) @classmethod def setUpClass(cls): cls.PORTAL_NAME = "RemoteDesktop" @@ -391,3 +406,19 @@ class TestOeffis(dbusmock.DBusTestCase): assert eisfd is not None assert eisfd.recv(64) == b"VANILLA" # that's what the template sends + + +def test_version_compare(): + assert version_at_least("1", "1.0") + assert version_at_least("1.0", "1.0") + assert version_at_least("1.1", "1.0") + assert version_at_least("1.0.1", "1.0.0") + assert version_at_least("1.0.2", "1.0.1") + assert version_at_least("1.1", "1.0.2") + assert version_at_least("1.1.1", "1.0.2") + assert version_at_least("1.0.2.dev1234", "1.0.2") + assert version_at_least("2", "1.3") + + assert not version_at_least("1.0", "1.1") + assert not version_at_least("1.0.2", "1.0.3") + assert not version_at_least("1.0.2.dev1234", "1.0.3")