[Piglit] [PATCH 02/15] framework: Move tests derived classes into a package

Dylan Baker baker.dylan.c at gmail.com
Fri Oct 3 17:57:43 PDT 2014


This moves all of the classes that derive from Test into a package
called test. This patch looks very large, but is mostly just moving
files around and changing imports to account for this.

So why all of this code churn? The big advantage is that through
__init__.py magic there is one module to be imported, framework.test.
This module contains all of the public classes, functions, and
constants, in one place while hiding the rest, but allowing them to be
accessed explicitly.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/profile.py                                  |  4 ++--
 framework/{tests/opencv_tests.py => test/__init__.py} | 16 ++++++++--------
 framework/{ => test}/exectest.py                      |  0
 framework/{ => test}/gleantest.py                     |  5 ++++-
 framework/{ => test}/glsl_parser_test.py              |  6 ++++++
 framework/{ => test}/gtest.py                         |  6 +++++-
 framework/{ => test}/oclconform.py                    |  8 +++++++-
 framework/{ => test}/opencv.py                        |  7 ++++++-
 framework/{ => test}/shader_test.py                   |  7 ++++++-
 framework/tests/dmesg_tests.py                        | 13 +++++--------
 framework/tests/exectest_test.py                      |  2 +-
 framework/tests/gleantest_tests.py                    |  4 +---
 framework/tests/glsl_parser_test_tests.py             |  4 ++--
 framework/tests/gtest_tests.py                        |  2 +-
 framework/tests/opencv_tests.py                       |  2 +-
 framework/tests/shader_test_tests.py                  | 16 ++++++++--------
 piglit                                                |  2 +-
 tests/all.py                                          |  7 +++----
 tests/cl.py                                           |  4 +---
 tests/es3conform.py                                   |  2 +-
 tests/gpu.py                                          |  2 +-
 tests/igt.py                                          |  2 +-
 tests/oglconform.py                                   |  2 +-
 tests/quick.py                                        |  2 +-
 tests/quick_cl.py                                     |  3 +--
 tests/sanity.py                                       |  2 +-
 tests/xts.py                                          |  2 +-
 27 files changed, 76 insertions(+), 56 deletions(-)
 copy framework/{tests/opencv_tests.py => test/__init__.py} (82%)
 rename framework/{ => test}/exectest.py (100%)
 rename framework/{ => test}/gleantest.py (98%)
 rename framework/{ => test}/glsl_parser_test.py (98%)
 rename framework/{ => test}/gtest.py (96%)
 rename framework/{ => test}/oclconform.py (97%)
 rename framework/{ => test}/opencv.py (97%)
 rename framework/{ => test}/shader_test.py (97%)

diff --git a/framework/profile.py b/framework/profile.py
index 8888c77..6a0f5a8 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -35,7 +35,7 @@ import importlib
 
 from framework.dmesg import get_dmesg
 from framework.log import LogManager
-import framework.exectest
+import framework.test
 
 __all__ = [
     'TestProfile',
@@ -188,7 +188,7 @@ class TestProfile(object):
         """
 
         self._pre_run_hook()
-        framework.exectest.Test.OPTS = opts
+        framework.test.Test.OPTS = opts
 
         chunksize = 1
 
diff --git a/framework/tests/opencv_tests.py b/framework/test/__init__.py
similarity index 82%
copy from framework/tests/opencv_tests.py
copy to framework/test/__init__.py
index 4658a9e..011416e 100644
--- a/framework/tests/opencv_tests.py
+++ b/framework/test/__init__.py
@@ -18,12 +18,12 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-""" Module for testing opencv """
+""" Module that provides test classes and helpers """
 
-from framework.opencv import OpenCVTest
-
-
-def test_initialize_opencvtest():
-    """ Test that opencvtest initializes correctly """
-    test = OpenCVTest('test_prog', 'testname')
-    assert test
+from .exectest import *
+from .gleantest import *
+from .glsl_parser_test import *
+from .shader_test import *
+from .gtest import *
+from .opencv import *
+from .oclconform import *
diff --git a/framework/exectest.py b/framework/test/exectest.py
similarity index 100%
rename from framework/exectest.py
rename to framework/test/exectest.py
diff --git a/framework/gleantest.py b/framework/test/gleantest.py
similarity index 98%
rename from framework/gleantest.py
rename to framework/test/gleantest.py
index 1af1897..7795d1f 100644
--- a/framework/gleantest.py
+++ b/framework/test/gleantest.py
@@ -23,9 +23,12 @@
 """ Glean support """
 
 import os
-
 from .exectest import Test, TEST_BIN_DIR
 
+__all__ = [
+    'GleanTest',
+]
+
 
 # GleanTest: Execute a sub-test of Glean
 class GleanTest(Test):
diff --git a/framework/glsl_parser_test.py b/framework/test/glsl_parser_test.py
similarity index 98%
rename from framework/glsl_parser_test.py
rename to framework/test/glsl_parser_test.py
index dfe2f76..b808a61 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/test/glsl_parser_test.py
@@ -29,6 +29,12 @@ import sys
 
 from .exectest import PiglitTest
 
+__all__ = [
+    'GLSLParserTest',
+    'add_glsl_parser_test',
+    'import_glsl_parser_tests',
+]
+
 
 def add_glsl_parser_test(group, filepath, test_name):
     """Add an instance of GLSLParserTest to the given group."""
diff --git a/framework/gtest.py b/framework/test/gtest.py
similarity index 96%
rename from framework/gtest.py
rename to framework/test/gtest.py
index d7bc42c..ba7926f 100644
--- a/framework/gtest.py
+++ b/framework/test/gtest.py
@@ -23,8 +23,12 @@
 #
 
 import re
+from .exectest import Test
+
+__all__ = [
+    'GTest',
+]
 
-from framework.exectest import Test
 
 class GTest(Test):
     def interpret_result(self):
diff --git a/framework/oclconform.py b/framework/test/oclconform.py
similarity index 97%
rename from framework/oclconform.py
rename to framework/test/oclconform.py
index 91a9e43..014df6c 100644
--- a/framework/oclconform.py
+++ b/framework/test/oclconform.py
@@ -30,7 +30,13 @@ from os.path import join
 from sys import stderr
 
 from framework.core import PIGLIT_CONFIG
-from framework.exectest import Test
+from .exectest import Test
+
+__all__ = [
+    'OCLConform',
+    'add_oclconform_tests',
+]
+
 
 def get_test_section_name(test):
     return 'oclconform-{}'.format(test)
diff --git a/framework/opencv.py b/framework/test/opencv.py
similarity index 97%
rename from framework/opencv.py
rename to framework/test/opencv.py
index a5201c9..4a8a9a7 100644
--- a/framework/opencv.py
+++ b/framework/test/opencv.py
@@ -26,9 +26,14 @@ from __future__ import print_function
 import re
 import subprocess
 from os import path
-from framework.gtest import GTest
+from .gtest import GTest
 from framework.core import PIGLIT_CONFIG
 
+__all__ = [
+    'OpenCVTest',
+    'add_opencv_tests',
+]
+
 
 class OpenCVTest(GTest):
     def __init__(self, test_prog, testname):
diff --git a/framework/shader_test.py b/framework/test/shader_test.py
similarity index 97%
rename from framework/shader_test.py
rename to framework/test/shader_test.py
index 6cfd86a..a3779d0 100644
--- a/framework/shader_test.py
+++ b/framework/test/shader_test.py
@@ -29,7 +29,12 @@ import re
 
 from .exectest import PiglitTest
 
-__all__ = ['add_shader_test', 'add_shader_test_dir']
+__all__ = [
+    'ShaderTest',
+    'ShaderTestParserException',
+    'add_shader_test',
+    'add_shader_test_dir'
+]
 
 
 class ShaderTest(PiglitTest):
diff --git a/framework/tests/dmesg_tests.py b/framework/tests/dmesg_tests.py
index a4d7627..e26f9bb 100644
--- a/framework/tests/dmesg_tests.py
+++ b/framework/tests/dmesg_tests.py
@@ -34,10 +34,7 @@ import nose.tools as nt
 from nose.plugins.skip import SkipTest
 import framework.dmesg as dmesg
 import framework.core
-import framework.exectest
-import framework.gleantest
-import framework.shader_test
-import framework.glsl_parser_test
+import framework.test
 import framework.backends
 import framework.tests.utils as utils
 
@@ -333,12 +330,12 @@ def test_json_serialize_updated_result():
 @utils.nose_generator
 def test_testclasses_dmesg():
     """ Generator that creates tests for """
-    lists = [(framework.exectest.PiglitTest,
+    lists = [(framework.test.PiglitTest,
               ['attribs', '-auto', '-fbo'], 'PiglitTest'),
-             (framework.gleantest.GleanTest, 'basic', "GleanTest"),
-             (framework.shader_test.ShaderTest,
+             (framework.test.GleanTest, 'basic', "GleanTest"),
+             (framework.test.ShaderTest,
               'tests/shaders/loopfunc.shader_test', 'ShaderTest'),
-             (framework.glsl_parser_test.GLSLParserTest,
+             (framework.test.GLSLParserTest,
               'tests/glslparsertest/shaders/main1.vert', 'GLSLParserTest')]
 
     for tclass, tfile, desc in lists:
diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py
index 831e29b..a334d81 100644
--- a/framework/tests/exectest_test.py
+++ b/framework/tests/exectest_test.py
@@ -21,8 +21,8 @@
 """ Tests for the exectest module """
 
 import nose.tools as nt
-from framework.exectest import PiglitTest, Test
 import framework.tests.utils as utils
+from framework.test import PiglitTest, Test
 
 
 # Helpers
diff --git a/framework/tests/gleantest_tests.py b/framework/tests/gleantest_tests.py
index dd309d9..d0feb24 100644
--- a/framework/tests/gleantest_tests.py
+++ b/framework/tests/gleantest_tests.py
@@ -21,9 +21,7 @@
 """ Tests for the glean class. Requires Nose """
 
 from __future__ import print_function
-import os
-from nose.plugins.skip import SkipTest
-from framework.gleantest import GleanTest
+from framework.test import GleanTest
 
 
 def test_initialize_gleantest():
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index 5d3f61e..ea13928 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -23,9 +23,9 @@
 import sys
 import os
 import nose.tools as nt
-import framework.glsl_parser_test as glsl
+import framework.test as glsl
 import framework.tests.utils as utils
-from framework.exectest import TEST_BIN_DIR
+from framework.test import TEST_BIN_DIR
 
 # Nose does not capture stderr, so all of the error catching tetss will spam
 # the console, however, it does capture stdout, so redirecting stderr to stdout
diff --git a/framework/tests/gtest_tests.py b/framework/tests/gtest_tests.py
index 4f7a3f6..53fe64e 100644
--- a/framework/tests/gtest_tests.py
+++ b/framework/tests/gtest_tests.py
@@ -21,7 +21,7 @@
 """ Module providing tests for gtest """
 
 
-from framework.gtest import GTest
+from framework.test import GTest
 
 
 def test_initialize_gtest():
diff --git a/framework/tests/opencv_tests.py b/framework/tests/opencv_tests.py
index 4658a9e..5cd89e3 100644
--- a/framework/tests/opencv_tests.py
+++ b/framework/tests/opencv_tests.py
@@ -20,7 +20,7 @@
 
 """ Module for testing opencv """
 
-from framework.opencv import OpenCVTest
+from framework.test import OpenCVTest
 
 
 def test_initialize_opencvtest():
diff --git a/framework/tests/shader_test_tests.py b/framework/tests/shader_test_tests.py
index 6600dee..c7c7663 100644
--- a/framework/tests/shader_test_tests.py
+++ b/framework/tests/shader_test_tests.py
@@ -22,13 +22,13 @@
 
 import os
 import nose.tools as nt
-import framework.shader_test as shader_test
+import framework.test as testm
 import framework.tests.utils as utils
 
 
 def test_initialize_shader_test():
     """ Test that ShaderTest initializes """
-    shader_test.ShaderTest('tests/spec/glsl-es-1.00/execution/sanity.shader_test')
+    testm.ShaderTest('tests/spec/glsl-es-1.00/execution/sanity.shader_test')
 
 
 def test_parse_gl_test_no_decimal():
@@ -36,8 +36,8 @@ def test_parse_gl_test_no_decimal():
     data = ('[require]\n'
             'GL = 2\n')
     with utils.with_tempfile(data) as temp:
-        with nt.assert_raises(shader_test.ShaderTestParserException) as exc:
-            shader_test.ShaderTest(temp)
+        with nt.assert_raises(testm.ShaderTestParserException) as exc:
+            testm.ShaderTest(temp)
             nt.assert_equal(exc.exception, "No GL version set",
                             msg="A GL version was passed without a decimal, "
                                 "which should have raised an exception, but "
@@ -50,7 +50,7 @@ def test_parse_gles2_test():
             'GL ES >= 2.0\n'
             'GLSL ES >= 1.00\n')
     with utils.with_tempfile(data) as temp:
-        test = shader_test.ShaderTest(temp)
+        test = testm.ShaderTest(temp)
 
     nt.assert_equal(
         os.path.basename(test.command[0]), "shader_runner_gles2",
@@ -64,7 +64,7 @@ def test_parse_gles3_test():
             'GL ES >= 3.0\n'
             'GLSL ES >= 3.00\n')
     with utils.with_tempfile(data) as temp:
-        test = shader_test.ShaderTest(temp)
+        test = testm.ShaderTest(temp)
 
     nt.assert_equal(
         os.path.basename(test.command[0]), "shader_runner_gles3",
@@ -74,10 +74,10 @@ def test_parse_gles3_test():
 
 def test_add_shader_test():
     """ Test that add_shader_test works """
-    shader_test.add_shader_test(
+    testm.add_shader_test(
         {}, 'test', 'tests/spec/glsl-es-3.00/execution/sanity.shader_test')
 
 
 def test_add_shader_test_dir():
     """ Test that add_shader_test_dir works """
-    shader_test.add_shader_test_dir({}, 'tests/spec/glsl-es-3.00/execution')
+    testm.add_shader_test_dir({}, 'tests/spec/glsl-es-3.00/execution')
diff --git a/piglit b/piglit
index c1c2520..5edfcfa 100755
--- a/piglit
+++ b/piglit
@@ -64,7 +64,7 @@ def setup_module_search_path():
 
     def is_piglit_data_dir(dirpath):
         tested_piglit_data_dirs.append(dirpath)
-        return path.exists(path.join(dirpath, 'framework', 'exectest.py'))
+        return path.exists(path.join(dirpath, 'framework'))
 
     # This script may be in two valid locations:
     #
diff --git a/tests/all.py b/tests/all.py
index 831af29..89649cd 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -10,10 +10,9 @@ import subprocess
 import sys
 
 from framework.profile import TestProfile
-from framework.exectest import PiglitTest
-from framework.gleantest import GleanTest
-from framework.glsl_parser_test import GLSLParserTest, add_glsl_parser_test, import_glsl_parser_tests
-from framework.shader_test import add_shader_test_dir
+from framework.test import (PiglitTest, GleanTest,
+                            add_glsl_parser_test, import_glsl_parser_tests,
+                            add_shader_test_dir)
 
 # Path to tests dir, correct even when not running from the top directory.
 testsDir = os.path.dirname(__file__)
diff --git a/tests/cl.py b/tests/cl.py
index 67ed542..885c43a 100644
--- a/tests/cl.py
+++ b/tests/cl.py
@@ -10,10 +10,8 @@ import os.path as path
 import platform
 import glob
 
-from framework.opencv import add_opencv_tests
-
 from framework.profile import TestProfile
-from framework.exectest import PiglitTest
+from framework.test import PiglitTest
 
 ######
 # Helper functions
diff --git a/tests/es3conform.py b/tests/es3conform.py
index b94cb06..5f7c6c2 100644
--- a/tests/es3conform.py
+++ b/tests/es3conform.py
@@ -27,7 +27,7 @@ import sys
 from os import path
 from glob import glob
 from framework.profile import TestProfile
-from framework.exectest import Test, TEST_BIN_DIR
+from framework.test import Test, TEST_BIN_DIR
 
 __all__ = ['profile']
 
diff --git a/tests/gpu.py b/tests/gpu.py
index 55ead29..49bdfa6 100644
--- a/tests/gpu.py
+++ b/tests/gpu.py
@@ -3,7 +3,7 @@
 # quick.tests minus compiler tests.
 
 from tests.quick import profile
-from framework.glsl_parser_test import GLSLParserTest
+from framework.test import GLSLParserTest
 
 __all__ = ['profile']
 
diff --git a/tests/igt.py b/tests/igt.py
index 13860a7..ae2929c 100644
--- a/tests/igt.py
+++ b/tests/igt.py
@@ -35,7 +35,7 @@ from datetime import datetime
 from os import path
 import framework.core
 from framework.profile import TestProfile
-from framework.exectest import Test
+from framework.test import Test
 
 __all__ = ['profile']
 
diff --git a/tests/oglconform.py b/tests/oglconform.py
index fab1946..80679e4 100644
--- a/tests/oglconform.py
+++ b/tests/oglconform.py
@@ -28,7 +28,7 @@ import subprocess
 
 import framework.core
 from framework.profile import TestProfile
-from framework.exectest import Test
+from framework.test import Test
 from os import path
 
 __all__ = ['profile']
diff --git a/tests/quick.py b/tests/quick.py
index 9dc0f98..8762d7d 100644
--- a/tests/quick.py
+++ b/tests/quick.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-from framework.gleantest import GleanTest
+from framework.test import GleanTest
 from tests.all import profile
 
 __all__ = ['profile']
diff --git a/tests/quick_cl.py b/tests/quick_cl.py
index ea48a7a..7f82a86 100644
--- a/tests/quick_cl.py
+++ b/tests/quick_cl.py
@@ -25,8 +25,7 @@
 #
 
 from tests.cl import profile
-from framework.oclconform import add_oclconform_tests
-from framework.opencv import add_opencv_tests
+from framework.test import add_opencv_tests, add_oclconform_tests
 
 add_opencv_tests(profile)
 add_oclconform_tests(profile)
diff --git a/tests/sanity.py b/tests/sanity.py
index 0e0e038..db07447 100644
--- a/tests/sanity.py
+++ b/tests/sanity.py
@@ -3,7 +3,7 @@
 #
 
 from framework.profile import TestProfile
-from framework.gleantest import GleanTest
+from framework.test import GleanTest
 
 __all__ = ['profile']
 
diff --git a/tests/xts.py b/tests/xts.py
index 7ba59f1..8d85674 100644
--- a/tests/xts.py
+++ b/tests/xts.py
@@ -30,7 +30,7 @@ import subprocess
 import itertools
 import framework.core
 from framework.profile import TestProfile
-from framework.exectest import Test
+from framework.test import Test
 
 __all__ = ['profile']
 
-- 
2.1.2



More information about the Piglit mailing list