[Piglit] [PATCH 10/44] framework: use six.add_metaclass

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Wed Jan 27 16:06:18 PST 2016


From: Dylan Baker <baker.dylan.c at gmail.com>

This makes metaclasses work on both python 3 and python 2, which have a
different syntax for setting the metaclass of a class.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/abstract.py | 5 +++--
 framework/dmesg.py             | 5 +++--
 framework/log.py               | 5 ++---
 framework/test/base.py         | 3 ++-
 framework/test/deqp.py         | 5 +++--
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/framework/backends/abstract.py b/framework/backends/abstract.py
index 56aed3f..c0c8903 100644
--- a/framework/backends/abstract.py
+++ b/framework/backends/abstract.py
@@ -32,6 +32,8 @@ import itertools
 import os
 import shutil
 
+import six
+
 from framework import options
 from . import compression
 from framework.results import TestResult
@@ -61,6 +63,7 @@ def write_compressed(filename):
         yield f
 
 
+ at six.add_metaclass(abc.ABCMeta)
 class Backend(object):
     """ Abstract base class for summary backends
 
@@ -75,8 +78,6 @@ class Backend(object):
     be thread safe and not need to be locked during write)
 
     """
-    __metaclass__ = abc.ABCMeta
-
     @abc.abstractmethod
     def __init__(self, dest, metadata, **kwargs):
         """ Generic constructor
diff --git a/framework/dmesg.py b/framework/dmesg.py
index 7989072..76a3710 100644
--- a/framework/dmesg.py
+++ b/framework/dmesg.py
@@ -43,6 +43,8 @@ import subprocess
 import sys
 import warnings
 
+import six
+
 from framework import exceptions
 
 __all__ = [
@@ -53,6 +55,7 @@ __all__ = [
 ]
 
 
+ at six.add_metaclass(abc.ABCMeta)
 class BaseDmesg(object):
     """ Abstract base class for Dmesg derived objects
 
@@ -70,8 +73,6 @@ class BaseDmesg(object):
     first, test B will be marked as having the dmesg error.
 
     """
-    __metaclass__ = abc.ABCMeta
-
     @abc.abstractmethod
     def __init__(self):
         # A list containing all messages since the last time dmesg was read.
diff --git a/framework/log.py b/framework/log.py
index 704ab05..86ae575 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -32,12 +32,12 @@ import abc
 import itertools
 import threading
 import collections
-
 try:
     import simplejson as json
 except ImportError:
     import json
 
+import six
 from six.moves.BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
 
 from framework.core import PIGLIT_CONFIG
@@ -46,6 +46,7 @@ from framework import grouptools
 __all__ = ['LogManager']
 
 
+ at six.add_metaclass(abc.ABCMeta)
 class BaseLog(object):
     """ Abstract base class for Log objects
 
@@ -56,8 +57,6 @@ class BaseLog(object):
     state -- the state dict from LogManager
 
     """
-    __metaclass__ = abc.ABCMeta
-
     SUMMARY_KEYS = set([
         'pass', 'fail', 'warn', 'crash', 'skip', 'dmesg-warn', 'dmesg-fail',
         'dry-run', 'timeout'])
diff --git a/framework/test/base.py b/framework/test/base.py
index 0c15808..1272aff 100644
--- a/framework/test/base.py
+++ b/framework/test/base.py
@@ -34,6 +34,7 @@ import copy
 import signal
 import warnings
 
+import six
 from six.moves import range
 
 try:
@@ -109,6 +110,7 @@ def is_crash_returncode(returncode):
         return returncode < 0
 
 
+ at six.add_metaclass(abc.ABCMeta)
 class Test(object):
     """ Abstract base class for Test classes
 
@@ -128,7 +130,6 @@ class Test(object):
     run_concurrent -- If True the test is thread safe. Default: False
 
     """
-    __metaclass__ = abc.ABCMeta
     __slots__ = ['run_concurrent', 'env', 'result', 'cwd', '_command']
     timeout = None
 
diff --git a/framework/test/deqp.py b/framework/test/deqp.py
index ae6c591..5b25718 100644
--- a/framework/test/deqp.py
+++ b/framework/test/deqp.py
@@ -23,7 +23,8 @@ import abc
 import os
 import subprocess
 
-# Piglit modules
+import six
+
 from framework import core, grouptools, exceptions
 from framework.profile import TestProfile
 from framework.test.base import Test, is_crash_returncode
@@ -105,8 +106,8 @@ def iter_deqp_test_cases(case_file):
                     'deqp: {}:{}: ill-formed line'.format(case_file, i))
 
 
+ at six.add_metaclass(abc.ABCMeta)
 class DEQPBaseTest(Test):
-    __metaclass__ = abc.ABCMeta
     __RESULT_MAP = {"Pass": "pass",
                     "Fail": "fail",
                     "QualityWarning": "warn",
-- 
2.7.0



More information about the Piglit mailing list