[Piglit] [PATCH 5/7] framework/status.py: Fix bug in Status.__eq__

Dylan Baker baker.dylan.c at gmail.com
Fri Feb 28 15:43:01 PST 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 d682531..2bca257 100644
--- a/framework/status.py
+++ b/framework/status.py
@@ -144,7 +144,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