linux: Fix broken assertDevs() device loop

The test uses a generator to get the list of basenames for the devices:
names = (n.split('/')[-1] for n in devs)

Unfortunately, using that "names" varible will consume the generator,
and our array will be lost.

When passing a device dictionary, this code:
print(sorted(names))
print(sorted(names))
will yield:
['battery_hidpp_battery_0']
[]

Save the sorted array, and use that to test for properties equality.
This commit is contained in:
Bastien Nocera 2023-04-14 11:39:05 +02:00
parent a5acbad7f1
commit 32e2cd5eb9

View file

@ -285,9 +285,9 @@ class Tests(dbusmock.DBusTestCase):
def assertDevs(self, expected):
devs = self.proxy.EnumerateDevices()
names = (n.split('/')[-1] for n in devs)
names = sorted(n.split('/')[-1] for n in devs)
self.assertEqual(sorted(names), sorted(expected.keys()))
self.assertEqual(names, sorted(expected.keys()))
for n in names:
props = self.get_dbus_dev_properties(n)