[node-patches] Change in ovirt-node[master]: test: Add decorator for common mock opertions

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Jun 18 16:21:13 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: test: Add decorator for common mock opertions
......................................................................

test: Add decorator for common mock opertions

Change-Id: Ifa044f2eca6d2e41f2cf667d98eb6ba2e70a4670
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M tests/nose/network_config.py
1 file changed, 22 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/62/15862/1

diff --git a/tests/nose/network_config.py b/tests/nose/network_config.py
index 0d89160..81fb50f 100644
--- a/tests/nose/network_config.py
+++ b/tests/nose/network_config.py
@@ -29,6 +29,19 @@
 # http://ivory.idyll.org/articles/nose-intro.html
 
 
+def patch_common(cls):
+    @patch("ovirt.node.utils.fs.File", FakeFs.File)
+    @patch("os.listdir", FakeFs.listdir)
+    @patch("ovirt.node.utils.process.call")
+    @patch.object(UdevNICInfo, "vendor")
+    @patch.object(UdevNICInfo, "devtype")
+    @patch.object(SysfsNICInfo, "hwaddr", "th:em:ac:ad:dr")
+    class TestWrapperClass(cls):
+        pass
+    TestWrapperClass.__name__ = cls.__name__
+    return TestWrapperClass
+
+
 class TestFakeFs():
     def setUp(self):
         FakeFs.erase()
@@ -48,10 +61,7 @@
             assert FakeFs.filemap == {}
 
 
- at patch("ovirt.node.utils.fs.File", FakeFs.File)
- at patch.object(UdevNICInfo, "vendor")
- at patch.object(UdevNICInfo, "devtype")
- at patch.object(SysfsNICInfo, "hwaddr", "th:em:ac:ad:dr")
+ at patch_common
 class TestBridgedNIC():
     """Test the bridged/legacy configuration
     """
@@ -105,10 +115,7 @@
                                 ('TYPE', 'Bridge')])
 
 
- at patch("ovirt.node.utils.fs.File", FakeFs.File)
- at patch.object(UdevNICInfo, "vendor")
- at patch.object(UdevNICInfo, "devtype")
- at patch.object(SysfsNICInfo, "hwaddr", "th:em:ac:ad:dr")
+ at patch_common
 class TestDirectNIC():
     """Test the bridgeless configuration
     """
@@ -161,12 +168,7 @@
         assert "brens1" not in FakeFs.filemap
 
 
- at patch("ovirt.node.utils.fs.File", FakeFs.File)
- at patch("os.listdir", FakeFs.listdir)
- at patch("ovirt.node.utils.process.call")
- at patch.object(UdevNICInfo, "vendor")
- at patch.object(UdevNICInfo, "devtype")
- at patch.object(SysfsNICInfo, "hwaddr", "th:em:ac:ad:dr")
+ at patch_common
 class TestBond():
     """Test bonding configuration
     """
@@ -302,6 +304,8 @@
 
 
 def run_tx_by_name(txs, name):
+    """Run a Transaction.Element by it's classname
+    """
     tx = None
     for _tx in txs:
         if _tx.__class__.__name__ == name:
@@ -312,10 +316,14 @@
 
 
 def ifcfgfilename(ifname):
+    """Return the path to an ifcfg file usign the ifname
+    """
     return "/etc/sysconfig/network-scripts/ifcfg-" + ifname
 
 
 def ifcfg_has_items(ifname, expected_items):
+    """Check if the items in an ifcfg file are equal the expected_items
+    """
     ifcfg = ShellVarFile(ifcfgfilename(ifname))
     ifcfg_items = sorted(ifcfg.get_dict().items())
     logging.info("ifcfg : %s" % ifname)


-- 
To view, visit http://gerrit.ovirt.org/15862
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa044f2eca6d2e41f2cf667d98eb6ba2e70a4670
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list