[Piglit] [PATCH 19/49] unittests: port shader_test tests to py.test

Dylan Baker dylan at pnwbakers.com
Fri Jul 29 18:39:05 UTC 2016


Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 unittests/framework/test/test_shader_test.py | 194 +++++++++++++++++++++++++
 unittests/shader_test_tests.py               | 205 ---------------------------
 2 files changed, 194 insertions(+), 205 deletions(-)
 create mode 100644 unittests/framework/test/test_shader_test.py
 delete mode 100644 unittests/shader_test_tests.py

diff --git a/unittests/framework/test/test_shader_test.py b/unittests/framework/test/test_shader_test.py
new file mode 100644
index 0000000..bd54624
--- /dev/null
+++ b/unittests/framework/test/test_shader_test.py
@@ -0,0 +1,194 @@
+# Copyright (c) 2014, 2016 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+""" Provides tests for the shader_test module """
+
+from __future__ import (
+    absolute_import, division, print_function, unicode_literals
+)
+import os
+import textwrap
+try:
+    import mock
+except ImportError:
+    from unittest import mock
+
+import pytest
+import six
+
+from framework import exceptions
+from framework.test import shader_test
+
+# pylint: disable=invalid-name,no-self-use
+
+
+class _Setup(object):
+    def __init__(self):
+        self.__patchers = []
+        self.__patchers.append(mock.patch.dict(
+            'framework.test.base.options.OPTIONS.env',
+            {'PIGLIT_PLATFORM': 'foo'}))
+
+    def setup(self, _):
+        for patcher in self.__patchers:
+            patcher.start()
+
+    def teardown(self, _):
+        for patcher in self.__patchers:
+            patcher.stop()
+
+
+_setup = _Setup()
+setup_module = _setup.setup
+teardown_module = _setup.teardown
+
+
+class TestConfigParsing(object):
+    """Tests for ShaderRunner config parsing."""
+
+    def test_no_decimal(self, tmpdir):
+        """test.shader_test.ShaderTest: raises if version lacks decminal."""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL = 2
+            """))
+
+        with pytest.raises(exceptions.PiglitFatalError):
+            shader_test.ShaderTest(six.text_type(p))
+
+    def test_gles2_bin(self, tmpdir):
+        """test.shader_test.ShaderTest: Identifies GLES2 tests successfully."""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL ES >= 2.0
+            GLSL ES >= 1.00
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert os.path.basename(test.command[0]) == "shader_runner_gles2"
+
+    def test_gles3_bin(self, tmpdir):
+        """test.shader_test.ShaderTest: Identifies GLES3 tests successfully."""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL ES >= 3.0
+            GLSL ES >= 3.00 es
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert os.path.basename(test.command[0]) == "shader_runner_gles3"
+
+    def test_skip_gl_required(self, tmpdir):
+        """test.shader_test.ShaderTest: populates gl_requirements properly"""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL >= 3.0
+            GL_ARB_ham_sandwhich
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert test.gl_required == {'GL_ARB_ham_sandwhich'}
+
+    def test_skip_gl_version(self, tmpdir):
+        """test.shader_test.ShaderTest: finds gl_version."""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL >= 2.0
+            GL_ARB_ham_sandwhich
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert test.gl_version == 2.0
+
+    def test_skip_gles_version(self, tmpdir):
+        """test.shader_test.ShaderTest: finds gles_version."""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL ES >= 2.0
+            GL_ARB_ham_sandwhich
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert test.gles_version == 2.0
+
+    def test_skip_glsl_version(self, tmpdir):
+        """test.shader_test.ShaderTest: finds glsl_version."""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL >= 2.1
+            GLSL >= 1.20
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert test.glsl_version == 1.2
+
+    def test_skip_glsl_es_version(self, tmpdir):
+        """test.shader_test.ShaderTest: finds glsl_es_version."""
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL ES >= 2.0
+            GLSL ES >= 1.00
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert test.glsl_es_version == 1.0
+
+    def test_ignore_directives(self, tmpdir):
+        """There are some directives for shader_runner that are not interpreted
+        by the python layer, they are only for the C layer. These should be
+        ignored by the python layer.
+        """
+        p = tmpdir.join('test.shader_test')
+        p.write(textwrap.dedent("""\
+            [require]
+            GL >= 3.3
+            GLSL >= 1.50
+            GL_MAX_VERTEX_OUTPUT_COMPONENTS
+            GL_MAX_FRAGMENT_UNIFORM_COMPONENTS
+            GL_MAX_VERTEX_UNIFORM_COMPONENTS
+            GL_MAX_VARYING_COMPONENTS
+            GL_ARB_foobar
+            """))
+        test = shader_test.ShaderTest(six.text_type(p))
+
+        assert test.gl_version == 3.3
+        assert test.glsl_version == 1.50
+        assert test.gl_required == {'GL_ARB_foobar'}
+
+
+def test_command_add_auto(tmpdir):
+    """test.shader_test.ShaderTest: -auto is added to the command."""
+    p = tmpdir.join('test.shader_test')
+    p.write(textwrap.dedent("""\
+        [require]
+        GL ES >= 3.0
+        GLSL ES >= 3.00 es
+        """))
+    test = shader_test.ShaderTest(six.text_type(p))
+
+    assert '-auto' in test.command
diff --git a/unittests/shader_test_tests.py b/unittests/shader_test_tests.py
deleted file mode 100644
index b20aabd..0000000
--- a/unittests/shader_test_tests.py
+++ /dev/null
@@ -1,205 +0,0 @@
-# Copyright (c) 2014, 2016 Intel Corporation
-
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-""" Provides tests for the shader_test module """
-
-from __future__ import (
-    absolute_import, division, print_function, unicode_literals
-)
-import os
-
-try:
-    from unittest import mock
-except ImportError:
-    import mock
-
-import nose.tools as nt
-
-from framework import exceptions
-import framework.test as testm
-from . import utils
-
-# pylint: disable=invalid-name
-
-
-class _Setup(object):
-    def __init__(self):
-        self.__patchers = []
-        self.__patchers.append(mock.patch.dict(
-            'framework.test.base.options.OPTIONS.env',
-            {'PIGLIT_PLATFORM': 'foo'}))
-
-    def setup(self):
-        for patcher in self.__patchers:
-            patcher.start()
-
-    def teardown(self):
-        for patcher in self.__patchers:
-            patcher.stop()
-
-
-_setup = _Setup()
-setup = _setup.setup
-teardown = _setup.teardown
-
-
-def test_initialize_shader_test():
-    """test.shader_test.ShaderTest: class initializes"""
-    testm.ShaderTest('tests/spec/glsl-es-1.00/execution/sanity.shader_test')
-
-
-def test_parse_gl_test_no_decimal():
-    """test.shader_test.ShaderTest: raises if version lacks decminal"""
-    data = ('[require]\n'
-            'GL = 2\n')
-    with utils.nose.tempfile(data) as temp:
-        with nt.assert_raises(exceptions.PiglitFatalError) 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 "
-                                "did not")
-
-
-def test_parse_gles2_test():
-    """test.shader_test.ShaderTest: Identifies GLES2 tests successfully"""
-    data = ('[require]\n'
-            'GL ES >= 2.0\n'
-            'GLSL ES >= 1.00\n')
-    with utils.nose.tempfile(data) as temp:
-        test = testm.ShaderTest(temp)
-
-    nt.assert_equal(
-        os.path.basename(test.command[0]), "shader_runner_gles2",
-        msg="This test should have run with shader_runner_gles2, "
-            "but instead ran with " + os.path.basename(test.command[0]))
-
-
-def test_parse_gles3_test():
-    """test.shader_test.ShaderTest: Identifies GLES3 tests successfully"""
-    data = ('[require]\n'
-            'GL ES >= 3.0\n'
-            'GLSL ES >= 3.00\n')
-    with utils.nose.tempfile(data) as temp:
-        test = testm.ShaderTest(temp)
-
-    nt.assert_equal(
-        os.path.basename(test.command[0]), "shader_runner_gles3",
-        msg="This test should have run with shader_runner_gles3, "
-            "but instead ran with " + os.path.basename(test.command[0]))
-
-
-def test_add_auto():
-    """test.shader_test.ShaderTest: -auto is added to the command"""
-    test = testm.ShaderTest('tests/spec/glsl-es-1.00/execution/sanity.shader_test')
-    nt.assert_in('-auto', test.command)
-
-
-def test_find_requirements_gl_requirements():
-    """test.shader_test.ShaderTest: populates gl_requirements properly"""
-
-    data = ('[require]\n'
-            'GL = 2.0\n'
-            'GL_ARB_ham_sandwhich\n')
-
-    with utils.nose.tempfile(data) as temp:
-        test = testm.ShaderTest(temp)
-
-    nt.eq_(test.gl_required, set(['GL_ARB_ham_sandwhich']))
-
-
-def test_find_requirements_gl_version():
-    """test.shader_test.ShaderTest: finds gl_version."""
-    data = ('[require]\n'
-            'GL = 2.0\n'
-            'GL_ARB_ham_sandwhich\n')
-
-    with mock.patch('framework.test.shader_test.io.open',
-                    mock.mock_open(read_data=data)):
-        test = testm.ShaderTest('null')
-    nt.eq_(test.gl_version, 2.0)
-
-
-def test_find_requirements_gles_version():
-    """test.shader_test.ShaderTest: finds gles_version."""
-    data = ('[require]\n'
-            'GL ES = 2.0\n'
-            'GL_ARB_ham_sandwhich\n')
-
-    with mock.patch('framework.test.shader_test.io.open',
-                    mock.mock_open(read_data=data)):
-        test = testm.ShaderTest('null')
-    nt.eq_(test.gles_version, 2.0)
-
-
-def test_find_requirements_glsl_version():
-    """test.shader_test.ShaderTest: finds glsl_version."""
-    data = ('[require]\n'
-            'GL = 2.0\n'
-            'GLSL >= 1.0\n'
-            'GL_ARB_ham_sandwhich\n')
-
-    with mock.patch('framework.test.shader_test.io.open',
-                    mock.mock_open(read_data=data)):
-        test = testm.ShaderTest('null')
-    nt.eq_(test.glsl_version, 1.0)
-
-
-def test_find_requirements_glsl_es_version():
-    """test.shader_test.ShaderTest: finds glsl_es_version."""
-    data = ('[require]\n'
-            'GL ES = 2.0\n'
-            'GLSL ES > 2.00\n'
-            'GL_ARB_ham_sandwhich\n')
-
-    with mock.patch('framework.test.shader_test.io.open',
-                    mock.mock_open(read_data=data)):
-        test = testm.ShaderTest('null')
-    nt.eq_(test.glsl_es_version, 2.0)
-
-
- at utils.nose.generator
-def test_ignore_shader_runner_directives():
-    """test.shader_test.ShaderTest: Doesn't add shader_runner command to gl_required list"""
-    should_ignore = [
-        'GL_MAX_VERTEX_OUTPUT_COMPONENTS',
-        'GL_MAX_FRAGMENT_UNIFORM_COMPONENTS',
-        'GL_MAX_VERTEX_UNIFORM_COMPONENTS',
-        'GL_MAX_VARYING_COMPONENTS',
-    ]
-
-    def test(config):
-        with mock.patch('framework.test.shader_test.io.open',
-                        mock.mock_open(read_data=config)):
-            test = testm.ShaderTest('null')
-        nt.eq_(test.gl_required, {'GL_foobar'})
-
-    for ignore in should_ignore:
-        config = '\n'.join([
-            '[require]',
-            'GL >= 1.0',
-            'GL_foobar',
-            ignore,
-        ])
-        test.description = ('test.shader_test.ShaderTest: doesn\'t add '
-                            'shader_runner command {} to gl_required'.format(
-                                ignore))
-
-        yield test, config
-- 
2.9.0



More information about the Piglit mailing list