[Piglit] [PATCH 4/7] status.py: Adds a new status class and subclasses

Dylan Baker baker.dylan.c at gmail.com
Fri Sep 27 14:39:18 PDT 2013


These status classes are intended to replace the string statuses
currently used by piglit summary.

They give a couple of very nice advantages, first, they can be directly
compared to each other to determine whether a status is worse than
another status. These statuses can also be compared to any object
implementing the __int__ magic method.

This will allow us to remove a number of special functions for sorting
representations of statuses.

v2: - Use larger numbers for the statuses, this should make adding
      addtional statuses easier, since there is room between the
      statuses.
    - Add a class for the "Not Run" status
    - Adds classes for dmesg-warn and dmesg-fail
    - Change statuses to match the standard set in the framework test

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

diff --git a/framework/status.py b/framework/status.py
new file mode 100644
index 0000000..43b807b
--- /dev/null
+++ b/framework/status.py
@@ -0,0 +1,118 @@
+# Copyright (c) 2013 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+
+class Status(object):
+    """
+    A simple class for representing the output values of tests.
+
+    This is a base class, and should not be directly called. Instead a child
+    class should be created and called. This module provides 5 of them: Skip,
+    Pass, Warn, Fail, and Crash.
+    """
+
+    # Using __slots__ allows us to implement the flyweight method, limiting the
+    # memory consumed for creating tens of thousands of these objects.
+    __slots__ = ['name', 'value']
+
+    def __init__(self):
+        raise NotImplementedError
+
+    def split(self, spliton):
+        return (self.name.split(spliton))
+
+    def __repr__(self):
+        return self.name
+
+    def __str__(self):
+        return str(self.name)
+
+    def __unicode__(self):
+        return unicode(self.name)
+
+    def __lt__(self, other):
+        return int(self) < int(other)
+
+    def __le__(self, other):
+        return int(self) <= int(other)
+
+    def __eq__(self, other):
+        return int(self) == int(other)
+
+    def __ne__(self, other):
+        return int(self) != int(other)
+
+    def __ge__(self, other):
+        return int(self) >= int(other)
+
+    def __gt__(self, other):
+        return int(self) > int(other)
+
+    def __int__(self):
+        return self.value
+
+
+class NotRun(Status):
+    def __init__(self):
+        self.name = 'Not Run'
+        self.value = 0
+
+
+class Pass(Status):
+    def __init__(self):
+        self.name = 'pass'
+        self.value = 10
+
+
+class DmesgWarn(Status):
+    def __init__(self):
+        self.name = 'dmesg-warn'
+        self.value = 20
+
+
+class Warn(Status):
+    def __init__(self):
+        self.name = 'warn'
+        self.value = 25
+
+
+class DmesgFail(Status):
+    def __init__(self):
+        self.name = 'dmesg-fail'
+        self.value = 30
+
+
+class Fail(Status):
+    def __init__(self):
+        self.name = 'fail'
+        self.value = 35
+
+
+class Crash(Status):
+    def __init__(self):
+        self.name = 'crash'
+        self.value = 40
+
+
+class Skip(Status):
+    def __init__(self):
+        self.name = 'skip'
+        self.value = 50
-- 
1.8.1.5



More information about the Piglit mailing list