Change in vdsm[master]: MonkeyPatch: fix reverting staticmethods.

asegurap at redhat.com asegurap at redhat.com
Fri Jan 17 11:40:36 UTC 2014


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: MonkeyPatch: fix reverting staticmethods.
......................................................................

MonkeyPatch: fix reverting staticmethods.

Under some circumstances setattr can make an object of type function
become of type instancemethod. This patch detects those cases and
fixes the type. This is specially relevant when reverting a
@staticmethod.

Change-Id: Ie3100455ab761481f57a93ab8aacc34ac4ab91eb
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M tests/monkeypatch.py
1 file changed, 6 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/23378/1

diff --git a/tests/monkeypatch.py b/tests/monkeypatch.py
index b51f097..cb8296a 100644
--- a/tests/monkeypatch.py
+++ b/tests/monkeypatch.py
@@ -20,6 +20,7 @@
 
 from contextlib import contextmanager
 from functools import wraps
+import types
 
 
 #
@@ -66,7 +67,12 @@
         assert self.old != []
         while self.old:
             module, name, that = self.old.pop()
+            oldtype = type(that)
+            isFunction = isinstance(that, types.FunctionType)
             setattr(module, name, that)
+            if oldtype != type(getattr(module, name)):
+                if isFunction:
+                    setattr(module, name, staticmethod(that))
 
 
 #


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie3100455ab761481f57a93ab8aacc34ac4ab91eb
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>


More information about the vdsm-patches mailing list