[Piglit] [Patch v2 18/18] exectest.py: Use ABC for Test

Dylan Baker baker.dylan.c at gmail.com
Mon Jul 28 15:35:27 PDT 2014


This uses the Abstract Base Class metaclass for Test, and it's
decorators to mark abstract classes. This has a couple of nice
advantages, first the abstract class cannot be initialized. Second, the
methods that are marked abstract must be overwritten in children or
initializing them will raise an error. Third, it is very easy to see
which methods need to be overwritten, even with an editor that folds
code.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/exectest.py            | 6 +++++-
 framework/tests/exectest_test.py | 5 -----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/framework/exectest.py b/framework/exectest.py
index 0b49c6a..36b0076 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -30,6 +30,7 @@ import time
 import sys
 import traceback
 import itertools
+import abc
 try:
     import simplejson as json
 except ImportError:
@@ -69,6 +70,7 @@ class Test(object):
     run_concurrent -- If True the test is thread safe. Default: False
 
     """
+    __metaclass__ = abc.ABCMeta
     __slots__ = ['run_concurrent', 'env', 'result', 'cwd', '_command',
                  '_test_hook_execute_run']
 
@@ -143,8 +145,10 @@ class Test(object):
             return
         self._command = value
 
+    @abc.abstractmethod
     def interpret_result(self):
-        raise NotImplementedError
+        """ Convert the raw output of the test into a form piglit understands
+        """
 
     def run(self):
         """
diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py
index d6d31af..935719d 100644
--- a/framework/tests/exectest_test.py
+++ b/framework/tests/exectest_test.py
@@ -39,11 +39,6 @@ class TestTest(Test):
 
 
 # Tests
-def test_initialize_test():
-    """ Test initializes """
-    Test('/bin/true')
-
-
 def test_initialize_piglittest():
     """ Test that PiglitTest initializes correctly """
     PiglitTest('/bin/true')
-- 
2.0.2



More information about the Piglit mailing list