[virt-tools-list] [PATCH 02/12] tests/nodedev: make compare recursive

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Tue Feb 21 13:00:52 UTC 2017


From: Marc-André Lureau <marcandre.lureau at redhat.com>

This will allow to have nested dict for childrens. See the following
commits.

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 tests/nodedev.py | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/tests/nodedev.py b/tests/nodedev.py
index 5d9fdec8..1a69c823 100644
--- a/tests/nodedev.py
+++ b/tests/nodedev.py
@@ -68,18 +68,26 @@ class TestNodeDev(unittest.TestCase):
         return NodeDevice.parse(conn, xml)
 
     def _testCompare(self, devname, vals, devxml=None):
+        def _compare(dev, vals, root=""):
+            for attr in vals.keys():
+                expect = vals[attr]
+                actual = getattr(dev, attr)
+                if isinstance(expect, list):
+                    for adev, exp in zip(actual, expect):
+                        _compare(adev, exp, attr + ".")
+                else:
+                    if expect != actual:
+                        raise AssertionError("devname=%s attribute=%s%s did not match:\n"
+                            "expect=%s\nactual=%s" % (devname, root, attr, expect, actual))
+                    self.assertEqual(vals[attr], getattr(dev, attr))
+
         if devxml:
             dev = NodeDevice.parse(conn, devxml)
         else:
             dev = self._nodeDevFromName(devname)
 
-        for attr in vals.keys():
-            expect = vals[attr]
-            actual = getattr(dev, attr)
-            if expect != actual:
-                raise AssertionError("devname=%s attribute=%s did not match:\n"
-                    "expect=%s\nactual=%s" % (devname, attr, expect, actual))
-            self.assertEqual(vals[attr], getattr(dev, attr))
+        _compare(dev, vals)
+        return dev
 
     def _testNode2DeviceCompare(self, nodename, devfile, nodedev=None):
         devfile = os.path.join("tests/nodedev-xml/devxml", devfile)
-- 
2.11.0.295.gd7dffce1c.dirty




More information about the virt-tools-list mailing list