[Piglit] [Patch v2 11/13] framework/exectest.py: Use abc metaclass for Test

Dylan Baker baker.dylan.c at gmail.com
Tue May 13 11:38:44 PDT 2014


Using the abc (Abstract Base Class) module is nice for a couple of
reasons. First, you cant initialize a class marked as an abc period,
second; decorators are used to define methods and properties that
children must implement, but super() can be used to call the code in the
base class (unlike raising NotImplementedError).

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

diff --git a/framework/exectest.py b/framework/exectest.py
index 2a28541..1d630de 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -30,6 +30,7 @@ import sys
 import traceback
 import ConfigParser
 import re
+import abc
 from cStringIO import StringIO
 from .core import TestResult, Environment
 
@@ -66,6 +67,7 @@ class Test(object):
     ENV = Environment()
     __slots__ = ['ENV', 'run_concurrent', 'env', 'result', 'cwd', '_command',
                  '_test_hook_execute_run']
+    __metaclass__ = abc.ABCMeta
 
     def __init__(self, command, run_concurrent=False):
         '''
@@ -141,8 +143,9 @@ class Test(object):
             return
         self._command = value
 
+    @abc.abstractmethod
     def interpret_result(self):
-        raise NotImplementedError
+        pass
 
     def run(self):
         """
diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py
index 0543f5b..3e0ccd4 100644
--- a/framework/tests/exectest_test.py
+++ b/framework/tests/exectest_test.py
@@ -28,11 +28,6 @@ import framework.tests.utils as utils
 import framework.exectest as exectest
 
 
-def test_initialize_test():
-    """ Test initializes """
-    exectest.Test('/bin/true')
-
-
 def test_initialize_piglittest():
     """ Test that PiglitTest initializes correctly """
     exectest.PiglitTest('/bin/true')
-- 
2.0.0.rc2



More information about the Piglit mailing list