[Piglit] [PATCH 4/5] framework: Simplify super calls as python3 allows

Dylan Baker baker.dylan.c at gmail.com
Thu Jul 9 14:25:44 PDT 2015


In python2 the super function required passing the class and self as
arguments. In python3 these are optional and super can be called without
any arguments.

This has some nice implications for renaming classes, since the methods
don't need to be aware of that change. It also just removes a lot of
boilerplate, and allows some lines to be wrapped into a single line,
which is more readable.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/junit.py             |  2 +-
 framework/core.py                       |  4 +---
 framework/dmesg.py                      |  2 +-
 framework/log.py                        |  8 ++++----
 framework/profile.py                    |  6 +++---
 framework/status.py                     |  2 +-
 framework/test/base.py                  |  4 ++--
 framework/test/deqp.py                  |  4 ++--
 framework/test/gleantest.py             |  6 +++---
 framework/test/glsl_parser_test.py      |  2 +-
 framework/test/piglit_test.py           | 14 +++++++-------
 framework/test/shader_test.py           |  2 +-
 framework/tests/base_tests.py           |  4 ++--
 framework/tests/json_backend_tests.py   |  4 ++--
 framework/tests/json_tests.py           |  2 +-
 framework/tests/junit_backends_tests.py | 14 +++++++-------
 tests/deqp_gles3.py                     |  2 +-
 tests/es3conform.py                     |  6 +++---
 tests/igt.py                            |  3 +--
 tests/oglconform.py                     |  4 ++--
 tests/xts.py                            |  3 +--
 21 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/framework/backends/junit.py b/framework/backends/junit.py
index bd5383e..8675c5f 100644
--- a/framework/backends/junit.py
+++ b/framework/backends/junit.py
@@ -61,7 +61,7 @@ class JUnitBackend(FileBackend):
     _file_extension = 'xml'
 
     def __init__(self, dest, junit_suffix='', **options):
-        super(JUnitBackend, self).__init__(dest, **options)
+        super().__init__(dest, **options)
         self._test_suffix = junit_suffix
 
         # make dictionaries of all test names expected to crash/fail
diff --git a/framework/core.py b/framework/core.py
index 8796403..2af42cc 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -47,9 +47,7 @@ PLATFORMS = ["glx", "x11_egl", "wayland", "gbm", "mixed_glx_egl"]
 class PiglitConfig(configparser.SafeConfigParser):
     """Custom Config parser that provides a few extra helpers."""
     def __init__(self, *args, **kwargs):
-        # In Python2 the ConfigParser classes are old style, you can't use
-        # super() on them. sigh
-        configparser.SafeConfigParser.__init__(self, *args, **kwargs)
+        super().__init__(*args, **kwargs)
         self.filename = None
 
     def readfp(self, fp, filename=None):
diff --git a/framework/dmesg.py b/framework/dmesg.py
index f1cb976..13f95db 100644
--- a/framework/dmesg.py
+++ b/framework/dmesg.py
@@ -163,7 +163,7 @@ class LinuxDmesg(BaseDmesg):
         # this entry and take any entries that were added after it. This works
         # on Linux because each entry is guaranteed unique by timestamps.
         self._last_message = None
-        super(LinuxDmesg, self).__init__()
+        super().__init__()
 
         if not self._last_message:
             # We need to ensure that there is something in dmesg to check
diff --git a/framework/log.py b/framework/log.py
index 4072326..f1adf19 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -98,7 +98,7 @@ class QuietLog(BaseLog):
     _test_counter = itertools.count()
 
     def __init__(self, *args, **kwargs):
-        super(QuietLog, self).__init__(*args, **kwargs)
+        super().__init__(*args, **kwargs)
 
         # If the output is a tty we can use '\r' (return, no linebreak) to
         # print over the existing line, if stdout isn't a tty that will not
@@ -188,7 +188,7 @@ class VerboseLog(QuietLog):
 
     """
     def __init__(self, *args, **kwargs):
-        super(VerboseLog, self).__init__(*args, **kwargs)
+        super().__init__(*args, **kwargs)
         self.__name = None    # the name needs to be printed by start and log
 
     def _print(self, out, newline=False):
@@ -203,7 +203,7 @@ class VerboseLog(QuietLog):
         status line should.
 
         """
-        super(VerboseLog, self)._print(out)
+        super()._print(out)
         if newline:
             sys.stdout.write('\n')
             sys.stdout.flush()
@@ -232,7 +232,7 @@ class VerboseLog(QuietLog):
         # Set lastlength to 0, this prevents printing needless padding in
         # super()
         self._state['lastlength'] = 0
-        super(VerboseLog, self)._log(value)
+        super()._log(value)
 
 
 class DummyLog(BaseLog):
diff --git a/framework/profile.py b/framework/profile.py
index ec586d8..f0c950f 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -57,7 +57,7 @@ class TestDict(dict):  # pylint: disable=too-few-public-methods
         # manager is opened, and decremented each time it is closed. This
         # allows stacking of the context manager
         self.__allow_reassignment = 0
-        super(TestDict, self).__init__(*args, **kwargs)
+        super().__init__(*args, **kwargs)
 
     def __setitem__(self, key, value):
         """Enforce types on set operations.
@@ -107,11 +107,11 @@ class TestDict(dict):  # pylint: disable=too-few-public-methods
 
     def __getitem__(self, key):
         """Lower the value before returning."""
-        return super(TestDict, self).__getitem__(key.lower())
+        return super().__getitem__(key.lower())
 
     def __delitem__(self, key):
         """Lower the value before returning."""
-        return super(TestDict, self).__delitem__(key.lower())
+        return super().__delitem__(key.lower())
 
     @property
     @contextlib.contextmanager
diff --git a/framework/status.py b/framework/status.py
index aebba07..83b4eb3 100644
--- a/framework/status.py
+++ b/framework/status.py
@@ -207,7 +207,7 @@ class NoChangeStatus(Status):
 
     """
     def __init__(self, name, value=0, fraction=(0, 0)):
-        super(NoChangeStatus, self).__init__(name, value, fraction)
+        super().__init__(name, value, fraction)
 
     def __eq__(self, other):
         if isinstance(other, (str, Status)):
diff --git a/framework/test/base.py b/framework/test/base.py
index 52cfb50..9262fc5 100644
--- a/framework/test/base.py
+++ b/framework/test/base.py
@@ -52,7 +52,7 @@ class TestIsSkip(exceptions.PiglitException):
 class TestRunError(exceptions.PiglitException):
     """Exception raised if the test fails to run."""
     def __init__(self, message, status):
-        super(TestRunError, self).__init__(message)
+        super().__init__(message)
         self.status = status
 
 
@@ -301,7 +301,7 @@ class WindowResizeMixin(object):
 
         """
         for _ in range(5):
-            super(WindowResizeMixin, self)._run_command()
+            super()._run_command()
             if "Got spurious window resize" not in self.result['out']:
                 return
 
diff --git a/framework/test/deqp.py b/framework/test/deqp.py
index b407e0c..7421646 100644
--- a/framework/test/deqp.py
+++ b/framework/test/deqp.py
@@ -126,7 +126,7 @@ class DEQPBaseTest(Test):
     def __init__(self, case_name):
         command = [self.deqp_bin, '--deqp-case=' + case_name]
 
-        super(DEQPBaseTest, self).__init__(command)
+        super().__init__(command)
 
         # dEQP's working directory must be the same as that of the executable,
         # otherwise it cannot find its data files (2014-12-07).
@@ -136,7 +136,7 @@ class DEQPBaseTest(Test):
     @Test.command.getter
     def command(self):
         """Return the command plus any extra arguments."""
-        command = super(DEQPBaseTest, self).command
+        command = super().command
         return command + self.extra_args
 
     def interpret_result(self):
diff --git a/framework/test/gleantest.py b/framework/test/gleantest.py
index bb7614d..cf1e68a 100644
--- a/framework/test/gleantest.py
+++ b/framework/test/gleantest.py
@@ -48,13 +48,13 @@ class GleanTest(Test):
     timeout = 120
 
     def __init__(self, name, **kwargs):
-        super(GleanTest, self).__init__(
+        super().__init__(
             [self._EXECUTABLE, "-o", "-v", "-v", "-v", "-t", "+" + name],
             **kwargs)
 
     @Test.command.getter
     def command(self):
-        return super(GleanTest, self).command + self.GLOBAL_PARAMS
+        return super().command + self.GLOBAL_PARAMS
 
     def interpret_result(self):
         if self.result['returncode'] != 0 or 'FAIL' in self.result['out']:
@@ -69,4 +69,4 @@ class GleanTest(Test):
                 'Glean tests require platform to support glx, '
                 'but the platform is "{}"'.format(
                     self.OPTS.env['PIGLIT_PLATFORM']))
-        super(GleanTest, self).is_skip()
+        super().is_skip()
diff --git a/framework/test/glsl_parser_test.py b/framework/test/glsl_parser_test.py
index fa4e217..e2a9c27 100644
--- a/framework/test/glsl_parser_test.py
+++ b/framework/test/glsl_parser_test.py
@@ -75,7 +75,7 @@ class GLSLParserTest(PiglitBaseTest):
                 raise exceptions.PiglitFatalError(
                     'In file "{}":\n{}'.format(filepath, str(e)))
 
-        super(GLSLParserTest, self).__init__(command, run_concurrent=True)
+        super().__init__(command, run_concurrent=True)
 
     def __get_command(self, config, filepath):
         """ Create the command argument to pass to super()
diff --git a/framework/test/piglit_test.py b/framework/test/piglit_test.py
index 6f91bbf..5a442c2 100644
--- a/framework/test/piglit_test.py
+++ b/framework/test/piglit_test.py
@@ -64,14 +64,14 @@ class PiglitBaseTest(Test):
     timeout = 30
 
     def __init__(self, command, run_concurrent=True, **kwargs):
-        super(PiglitBaseTest, self).__init__(command, run_concurrent, **kwargs)
+        super().__init__(command, run_concurrent, **kwargs)
 
         # Prepend TEST_BIN_DIR to the path.
         self._command[0] = os.path.join(TEST_BIN_DIR, self._command[0])
 
     @Test.command.getter
     def command(self):
-        command = super(PiglitBaseTest, self).command
+        command = super().command
         if self.OPTS.valgrind:
             return ['valgrind', '--quiet', '--error-exitcode=1',
                     '--tool=memcheck'] + command
@@ -114,7 +114,7 @@ class PiglitGLTest(WindowResizeMixin, PiglitBaseTest):
         # but this doesn't work in python2. In python3 thanks to PEP3102, you
         # can in fact do just that
         # The work around is to explicitely pass the arguments down.
-        super(PiglitGLTest, self).__init__(command, **kwargs)
+        super().__init__(command, **kwargs)
 
         assert not (require_platforms and exclude_platforms)
 
@@ -149,15 +149,15 @@ class PiglitGLTest(WindowResizeMixin, PiglitBaseTest):
                 'Test cannot be run on any of the following platforms "{}" '
                 'and the platform is "{}"'.format(
                     self.__exclude_platforms, platform))
-        super(PiglitGLTest, self).is_skip()
+        super().is_skip()
 
     @PiglitBaseTest.command.getter
     def command(self):
         """ Automatically add -auto and -fbo as appropriate """
         if not self.run_concurrent:
-            return super(PiglitGLTest, self).command + ['-auto']
+            return super().command + ['-auto']
         else:
-            return super(PiglitGLTest, self).command + ['-auto', '-fbo']
+            return super().command + ['-auto', '-fbo']
 
 
 class PiglitCLTest(PiglitBaseTest):  # pylint: disable=too-few-public-methods
@@ -167,4 +167,4 @@ class PiglitCLTest(PiglitBaseTest):  # pylint: disable=too-few-public-methods
 
     """
     def __init__(self, command, run_concurrent=CL_CONCURRENT, **kwargs):
-        super(PiglitCLTest, self).__init__(command, run_concurrent, **kwargs)
+        super().__init__(command, run_concurrent, **kwargs)
diff --git a/framework/test/shader_test.py b/framework/test/shader_test.py
index 8554504..e0a4566 100644
--- a/framework/test/shader_test.py
+++ b/framework/test/shader_test.py
@@ -86,7 +86,7 @@ class ShaderTest(PiglitBaseTest):
                 raise exceptions.PiglitFatalError(
                     "In file {}: No GL version set".format(filename))
 
-        super(ShaderTest, self).__init__([prog, filename], run_concurrent=True)
+        super().__init__([prog, filename], run_concurrent=True)
 
     @PiglitBaseTest.command.getter
     def command(self):
diff --git a/framework/tests/base_tests.py b/framework/tests/base_tests.py
index c68251f..eb4db34 100644
--- a/framework/tests/base_tests.py
+++ b/framework/tests/base_tests.py
@@ -93,7 +93,7 @@ def test_WindowResizeMixin_rerun():
     # Because of Python's inheritance order we need the mixin here.
     class Mixin(object):
         def __init__(self, *args, **kwargs):
-            super(Mixin, self).__init__(*args, **kwargs)
+            super().__init__(*args, **kwargs)
             self.__return_spurious = True
 
         def _run_command(self):
@@ -154,7 +154,7 @@ def test_mutation():
     """
     class _Test(TestTest):
         def __init__(self, *args, **kwargs):
-            super(_Test, self).__init__(*args, **kwargs)
+            super().__init__(*args, **kwargs)
             self._command[0] = 'bin/' + self._command[0]
 
     args = ['a', 'b']
diff --git a/framework/tests/json_backend_tests.py b/framework/tests/json_backend_tests.py
index a6851c8..597f87f 100644
--- a/framework/tests/json_backend_tests.py
+++ b/framework/tests/json_backend_tests.py
@@ -83,7 +83,7 @@ class TestJSONTestMethod(utils.StaticDirectory):
             'out': 'this is stdout',
             'err': 'this is stderr',
         })
-        super(TestJSONTestMethod, cls).setup_class()
+        super().setup_class()
         test = backends.json.JSONBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         with test.write_test(cls.test_name) as t:
@@ -119,7 +119,7 @@ class TestJSONTestFinalize(utils.StaticDirectory):
             'out': 'this is stdout',
             'err': 'this is stderr',
         })
-        super(TestJSONTestFinalize, cls).setup_class()
+        super().setup_class()
         test = backends.json.JSONBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         with test.write_test(cls.test_name) as t:
diff --git a/framework/tests/json_tests.py b/framework/tests/json_tests.py
index 142b743..7af00b3 100644
--- a/framework/tests/json_tests.py
+++ b/framework/tests/json_tests.py
@@ -71,7 +71,7 @@ class TestJsonOutput(utils.StaticDirectory):
     """Class for testing JSON output."""
     @classmethod
     def setup_class(cls):
-        super(TestJsonOutput, cls).setup_class()
+        super().setup_class()
 
         args = Namespace()
         # pylint: disable=attribute-defined-outside-init
diff --git a/framework/tests/junit_backends_tests.py b/framework/tests/junit_backends_tests.py
index 53d03cb..7c2ed96 100644
--- a/framework/tests/junit_backends_tests.py
+++ b/framework/tests/junit_backends_tests.py
@@ -73,7 +73,7 @@ def teardown_module():
 class TestJunitNoTests(utils.StaticDirectory):
     @classmethod
     def setup_class(cls):
-        super(TestJunitNoTests, cls).setup_class()
+        super().setup_class()
         test = backends.junit.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.finalize()
@@ -93,7 +93,7 @@ class TestJunitNoTests(utils.StaticDirectory):
 class TestJUnitSingleTest(TestJunitNoTests):
     @classmethod
     def setup_class(cls):
-        super(TestJUnitSingleTest, cls).setup_class()
+        super().setup_class()
         cls.test_file = os.path.join(cls.tdir, 'results.xml')
         test = backends.junit.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
@@ -110,7 +110,7 @@ class TestJUnitSingleTest(TestJunitNoTests):
 
     def test_xml_well_formed(self):
         """backends.junit.JUnitBackend.write_test(): (once) produces well formed xml"""
-        super(TestJUnitSingleTest, self).test_xml_well_formed()
+        super().test_xml_well_formed()
 
     def test_xml_valid(self):
         """backends.junit.JUnitBackend.write_test(): (once) produces valid xml"""
@@ -124,7 +124,7 @@ class TestJUnitSingleTest(TestJunitNoTests):
 class TestJUnitMultiTest(TestJUnitSingleTest):
     @classmethod
     def setup_class(cls):
-        super(TestJUnitMultiTest, cls).setup_class()
+        super().setup_class()
         cls.test_file = os.path.join(cls.tdir, 'results.xml')
         test = backends.junit.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
@@ -148,11 +148,11 @@ class TestJUnitMultiTest(TestJUnitSingleTest):
 
     def test_xml_well_formed(self):
         """backends.junit.JUnitBackend.write_test(): (twice) produces well formed xml"""
-        super(TestJUnitMultiTest, self).test_xml_well_formed()
+        super().test_xml_well_formed()
 
     def test_xml_valid(self):
         """backends.junit.JUnitBackend.write_test(): (twice) produces valid xml"""
-        super(TestJUnitMultiTest, self).test_xml_valid()
+        super().test_xml_valid()
 
 
 @doc_formatter
@@ -204,7 +204,7 @@ class TestJUnitLoad(utils.StaticDirectory):
 
     @classmethod
     def setup_class(cls):
-        super(TestJUnitLoad, cls).setup_class()
+        super().setup_class()
         cls.xml_file = os.path.join(cls.tdir, 'results.xml')
         
         with open(cls.xml_file, 'w') as f:
diff --git a/tests/deqp_gles3.py b/tests/deqp_gles3.py
index d353899..f2adb33 100644
--- a/tests/deqp_gles3.py
+++ b/tests/deqp_gles3.py
@@ -81,7 +81,7 @@ class DEQPGLES3Test(deqp.DEQPBaseTest):
 
 
     def __init__(self, *args, **kwargs):
-        super(DEQPGLES3Test, self).__init__(*args, **kwargs)
+        super().__init__(*args, **kwargs)
 
 
 profile = deqp.make_profile(  # pylint: disable=invalid-name
diff --git a/tests/es3conform.py b/tests/es3conform.py
index 42080dc..5694254 100644
--- a/tests/es3conform.py
+++ b/tests/es3conform.py
@@ -52,9 +52,9 @@ class GTFTest(Test):
         r'(Conformance|Regression) PASSED all (?P<passed>\d+) tests')
 
     def __init__(self, testpath):
-        super(GTFTest, self).__init__([path.join(TEST_BIN_DIR, 'GTF3'),
-                                       '-minfmt', '-width=113', '-height=47',
-                                       '-run=' + testpath])
+        super().__init__([path.join(TEST_BIN_DIR, 'GTF3'),
+                                    '-minfmt', '-width=113', '-height=47',
+                                    '-run=' + testpath])
 
     def interpret_result(self):
         mo = self.pass_re.search(self.result['out'])
diff --git a/tests/igt.py b/tests/igt.py
index ae2e3f3..2c2de9d 100644
--- a/tests/igt.py
+++ b/tests/igt.py
@@ -103,8 +103,7 @@ class IGTTest(Test):
     def __init__(self, binary, arguments=None):
         if arguments is None:
             arguments = []
-        super(IGTTest, self).__init__(
-            [os.path.join(IGT_TEST_ROOT, binary)] + arguments)
+        super().__init__([os.path.join(IGT_TEST_ROOT, binary)] + arguments)
         self.timeout = 600
 
     def interpret_result(self):
diff --git a/tests/oglconform.py b/tests/oglconform.py
index 4ec127e..ecb1c68 100644
--- a/tests/oglconform.py
+++ b/tests/oglconform.py
@@ -51,8 +51,8 @@ class OGLCTest(Test):
                          r'scheduled due to lack of compatible fbconfig')
 
     def __init__(self, category, subtest):
-        super(OGLCTest, self).__init__([bin_oglconform, '-minFmt', '-v', '4',
-                                        '-test', category, subtest])
+        super().__init__([bin_oglconform, '-minFmt', '-v', '4', '-test',
+                          category, subtest])
 
     def interpret_result(self):
         if self.skip_re.search(self.result['out']) is not None:
diff --git a/tests/xts.py b/tests/xts.py
index 973e398..ade3f95 100644
--- a/tests/xts.py
+++ b/tests/xts.py
@@ -71,8 +71,7 @@ class XTSTest(Test):  # pylint: disable=too-few-public-methods
     RESULTS_PATH = None
 
     def __init__(self, name, testname, testnum):
-        super(XTSTest, self).__init__(
-            ['./' + os.path.basename(name), '-i', str(testnum)])
+        super().__init__(['./' + os.path.basename(name), '-i', str(testnum)])
         self.testname = '{0}-{1}'.format(testname, testnum)
         self.cwd = os.path.dirname(os.path.realpath(name))
         self.test_results_file = os.path.join(self.cwd, self.testname)
-- 
2.4.5



More information about the Piglit mailing list