[Piglit] [PATCH 1/2] status.py: Adds a new status class and subclasses
Dylan Baker
baker.dylan.c at gmail.com
Fri Sep 13 17:22:40 PDT 2013
These status classes are intended to replace the string statuses
currently used by piglit.
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__ method.
This will allow us to remove a number of special functions for sorting
representations of statuses.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/status.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
create mode 100644 framework/status.py
diff --git a/framework/status.py b/framework/status.py
new file mode 100644
index 0000000..b9ce70f
--- /dev/null
+++ b/framework/status.py
@@ -0,0 +1,99 @@
+# 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
+ __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 Skip(Status):
+ def __init__(self):
+ self.name = 'skip'
+ self.value = 1
+
+
+class Pass(Status):
+ def __init__(self):
+ self.name = 'pass'
+ self.value = 2
+
+
+class Warn(Status):
+ def __init__(self):
+ self.name = 'warn'
+ self.value = 3
+
+
+class Fail(Status):
+ def __init__(self):
+ self.name = 'fail'
+ self.value = 4
+
+
+class Crash(Status):
+ def __init__(self):
+ self.name = 'crash'
+ self.value = 5
--
1.8.1.5
More information about the Piglit
mailing list