tests: correctly compare DeviceManager objects

Usefull for assertEqual(vm1.devices, vm2.devices) - clone tests, backup
tests etc.
This commit is contained in:
Marek Marczykowski-Górecki 2016-08-09 04:26:05 +02:00
parent d954bb82a3
commit ac68ffe39f
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -51,6 +51,7 @@ import lxml.etree
import time
import qubes.config
import qubes.devices
import qubes.events
import qubes.backup
import qubes.exc
@ -220,6 +221,8 @@ class QubesTestCase(unittest.TestCase):
self.__class__.__module__,
self.__class__.__name__,
self._testMethodName))
self.addTypeEqualityFunc(qubes.devices.DeviceManager,
self.assertDevicesEqual)
def __str__(self):
@ -287,6 +290,15 @@ class QubesTestCase(unittest.TestCase):
for key in xml1.keys():
self.assertEqual(xml1.get(key), xml2.get(key))
def assertDevicesEqual(self, devices1, devices2, msg=None):
self.assertEqual(devices1.keys(), devices2.keys(), msg)
for dev_class in devices1.keys():
self.assertEqual(
[str(dev) for dev in devices1[dev_class]],
[str(dev) for dev in devices2[dev_class]],
"Devices of class {} differs{}".format(
dev_class, (": " + msg) if msg else "")
)
def assertEventFired(self, emitter, event, args=None, kwargs=None):
'''Check whether event was fired on given emitter and fail if it did