[Piglit] [PATCH 4/5] status: Make NOTRUN and SKIP a special class

Dylan Baker baker.dylan.c at gmail.com
Mon Mar 17 12:06:13 PDT 2014


SKIP and NOTRUN are changed to a special class that when compared with
=<, <, >, or >= will always return False. This is because we want to
consider NOTRUN <-> * and SKIP <-> * as not regressions or fixes,
instead we want to catch them and add them to special enabled and
disabled lists.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/status.py             | 57 +++++++++++++++++++++++++++++++++--------
 framework/tests/status_tests.py | 17 ++++++++++++
 2 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/framework/status.py b/framework/status.py
index d5e6b63..bb7c594 100644
--- a/framework/status.py
+++ b/framework/status.py
@@ -44,13 +44,14 @@ crash
 timeout
 
 SKIP and NOTRUN are not factored into regressions and fixes, they are counted
-seperately.
+seperately. They also derive from a sublcass of Status, which always returns
+False
 
 The formula for determining regressions is:
-  max(PASS, old_status) < new_status
+  old_status < new_status
 
 The formula for determining fixes is:
-  max(PASS, old_status) > new_status
+  old_status > new_status
 
 """
 
@@ -125,6 +126,7 @@ class Status(object):
     __slots__ = ['__name', '__value', '__fraction']
 
     def __init__(self, name, value, fraction=(0, 1)):
+        assert isinstance(value, int), type(value)
         # The object is immutable, so calling self.foo = foo will raise a
         # TypeError. Using setattr from the parrent object works around this.
         self.__name = name
@@ -183,18 +185,51 @@ class Status(object):
         return self.value
 
 
-NOTRUN = Status('Not Run', 0, (0, 0))
+class NoChangeStatus(Status):
+    """ Special sublcass of status that overides rich comparison methods
 
-SKIP = Status('skip', 10, (0, 0))
+    This special class of a Status is for use with NOTRUN and SKIP, it never
+    returns that it is a pass or regression
 
-PASS = Status('pass', 20, (1, 1))
+    """
+    def __init__(self, name, value=0, fraction=(0, 0)):
+        super(NoChangeStatus, self).__init__(name, value, fraction)
+
+    def __lt__(self, other):
+        return False
+
+    def __le__(self, other):
+        return False
+
+    def __eq__(self, other):
+        if isinstance(other, (str, unicode, Status)):
+            return unicode(self) == unicode(other)
+        raise TypeError("Cannot compare type: {}".format(type(other)))
+
+    def __ne__(self, other):
+        if isinstance(other, (str, unicode, Status)):
+            return unicode(self) != unicode(other)
+        raise TypeError("Cannot compare type: {}".format(type(other)))
+
+    def __ge__(self, other):
+        return False
+
+    def __gt__(self, other):
+        return False
+
+
+NOTRUN = NoChangeStatus('Not Run')
+
+SKIP = NoChangeStatus('skip')
+
+PASS = Status('pass', 0, (1, 1))
 
-DMESG_WARN = Status('dmesg-warn', 30)
+DMESG_WARN = Status('dmesg-warn', 10)
 
-WARN = Status('warn', 40)
+WARN = Status('warn', 20)
 
-DMESG_FAIL = Status('dmesg-fail', 50)
+DMESG_FAIL = Status('dmesg-fail', 30)
 
-FAIL = Status('fail', 60)
+FAIL = Status('fail', 40)
 
-CRASH = Status('crash', 70)
+CRASH = Status('crash', 50)
diff --git a/framework/tests/status_tests.py b/framework/tests/status_tests.py
index 8ba11aa..ad0630a 100644
--- a/framework/tests/status_tests.py
+++ b/framework/tests/status_tests.py
@@ -48,6 +48,17 @@ def initialize_status():
     assert test
 
 
+def initialize_nochangestatus():
+    """ NoChangeStatus initializes """
+    nc = status.NoChangeStatus('test')
+    assert nc
+
+
+def compare_status_nochangestatus():
+    """ Status and NoChangeStatus can be compared with < """
+    status.CRASH < status.PASS
+
+
 def check_lookup(stat):
     """ Lookup a status """
     stt = status.status_lookup(stat)
@@ -140,3 +151,9 @@ def test_not_change():
         yieldable.description = "{0} -> {1} should not be a change".format(
                 nochange, stat)
         yield yieldable, status.status_lookup(nochange), status.status_lookup(stat)
+
+
+def test_compare_statuses():
+    """ Compare NOTRUN -> PASS returns false """
+    nt.assert_equal(False, status.NOTRUN < status.PASS,
+                   msg="NOTRUN -> PASS returned True but should return False")
-- 
1.9.0



More information about the Piglit mailing list