test: skip the oeffis tests if we don't have dbusmock 0.28.5

This commit is contained in:
Peter Hutterer 2023-03-17 11:18:27 +10:00
parent bba921329d
commit 74ed569fe0

View file

@ -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")