[Piglit] [Patch V2 6/8] framework/status.py: Fix bug in Status.__eq__

Dylan Baker baker.dylan.c at gmail.com
Mon Mar 10 18:25:32 PDT 2014


Because Status.__eq__ didn't have the ability to compare str or unicode
instances, using Pass() in ['pass'] would raise an exception. With this
patch that is no longer the case, and that syntax works fine.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/status.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/framework/status.py b/framework/status.py
index 5170847..e34e4af 100644
--- a/framework/status.py
+++ b/framework/status.py
@@ -170,7 +170,13 @@ class Status(object):
         return int(self) <= int(other)
 
     def __eq__(self, other):
-        return int(self) == int(other)
+        # This must be int or status, since status comparisons are done using
+        # the __int__ magic method
+        if isinstance(other, (int, Status)):
+            return int(self) == int(other)
+        elif isinstance(other, (str, unicode)):
+            return unicode(self) == unicode(other)
+        raise TypeError("Cannot compare type: {}".format(type(other)))
 
     def __ne__(self, other):
         return int(self) != int(other)
-- 
1.9.0



More information about the Piglit mailing list