[Piglit] [PATCH 24/49] unittests: port piglit_test to pytest

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


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

diff --git a/unittests/framework/test/test_piglit_test.py b/unittests/framework/test/test_piglit_test.py
new file mode 100644
index 0000000..288f738
--- /dev/null
+++ b/unittests/framework/test/test_piglit_test.py
@@ -0,0 +1,164 @@
+# 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.
+
+"""Tests for the piglit_test module."""
+
+from __future__ import (
+    absolute_import, division, print_function, unicode_literals
+)
+import textwrap
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
+import pytest
+
+
+from framework import status
+from framework.options import _Options as Options
+from framework.test.base import TestIsSkip as _TestIsSkip
+from framework.test.piglit_test import PiglitBaseTest, PiglitGLTest
+
+# pylint: disable=no-self-use
+
+
+class TestPiglitBaseTest(object):
+    """Tests for the PiglitBaseTest class."""
+
+    class TestIntepretResult(object):
+        """Tests for PiglitBaseTest.interpret_results."""
+
+        def test_basic(self):
+            """A basic sanity test with nothing tricky."""
+            test = PiglitBaseTest(['foo'])
+            test.result.out = 'PIGLIT: {"result": "pass"}\n'
+            test.result.returncode = 0
+            test.interpret_result()
+            assert test.result.result is status.PASS
+
+        def test_stdout(self):
+            """Separates the actual stdout printing from the PIGLIT protocol.
+            """
+            test = PiglitBaseTest(['foo'])
+            test.result.out = textwrap.dedent("""\
+                This is output
+
+                more output
+                PIGLIT: {"result": "pass"}
+                and stuff""")
+            test.result.returncode = 0
+            test.interpret_result()
+
+            assert test.result.result is status.PASS
+            assert test.result.out == textwrap.dedent("""\
+                This is output
+
+                more output
+                and stuff""")
+
+        def test_with_subtests(self):
+            """works with one subtest."""
+            test = PiglitBaseTest(['foo'])
+            test.result.out = textwrap.dedent("""\
+                PIGLIT: {"result": "pass"}
+                PIGLIT: {"subtest": {"subtest": "pass"}}""")
+            test.result.returncode = 0
+            test.interpret_result()
+            assert test.result.subtests['subtest'] is status.PASS
+
+        def test_with_multiple_subtests(self):
+            """Works with multiple subtests.
+
+            Including that it doesn't only take the last subtest, but counts
+            all of them.
+            """
+            test = PiglitBaseTest(['a', 'command'])
+            test.result.out = textwrap.dedent("""\
+                PIGLIT: {"result": "pass"}
+                PIGLIT: {"subtest": {"test1": "pass"}}
+                PIGLIT: {"subtest": {"test2": "pass"}}""")
+            test.result.returncode = 0
+            test.interpret_result()
+
+            assert dict(test.result.subtests) == \
+                {'test1': 'pass', 'test2': 'pass'}
+
+
+class TestPiglitGLTest(object):
+    """tests for the PiglitGLTest class."""
+
+    class TestCommand(object):
+        """Tests for the command getter and setter."""
+
+        def test_getter_serial(self):
+            """adds -auto to serial tests."""
+            test = PiglitGLTest(['foo'])
+            assert '-auto' in test.command
+
+        def test_getter_concurrent(self):
+            """adds -fbo and -auto to concurrent tests."""
+            test = PiglitGLTest(['foo'], run_concurrent=True)
+            assert '-auto' in test.command
+            assert '-fbo' in test.command
+
+    class TestIsSkip(object):
+        """Tests for the is_skip method and the constructor logic to make it
+        work.
+        """
+
+        @pytest.yield_fixture()
+        def mock_options(self):
+            with mock.patch('framework.test.piglit_test.options.OPTIONS',
+                            new_callable=Options) as m:
+                yield m
+
+        def test_include_and_exclude(self):
+            """ raises if include and exclude are given."""
+            with pytest.raises(AssertionError):
+                PiglitGLTest(['foo'],
+                             require_platforms=['glx'],
+                             exclude_platforms=['gbm'])
+
+        def test_platform_in_require(self, mock_options):
+            """does not skip if platform is in require_platforms."""
+            mock_options.env['PIGLIT_PLATFORM'] = 'glx'
+            test = PiglitGLTest(['foo'], require_platforms=['glx'])
+            test.is_skip()
+
+        def test_platform_not_in_require(self, mock_options):
+            """skips if platform is not in require_platforms."""
+            mock_options.env['PIGLIT_PLATFORM'] = 'gbm'
+            test = PiglitGLTest(['foo'], require_platforms=['glx'])
+            with pytest.raises(_TestIsSkip):
+                test.is_skip()
+
+        def test_platform_in_exclude(self, mock_options):
+            """skips if platform is in exclude_platforms."""
+            mock_options.env['PIGLIT_PLATFORM'] = 'glx'
+            test = PiglitGLTest(['foo'], exclude_platforms=['glx'])
+            with pytest.raises(_TestIsSkip):
+                test.is_skip()
+
+        def test_platform_not_in_exclude(self, mock_options):
+            """does not skip if platform is in exclude_platforms."""
+            mock_options.env['PIGLIT_PLATFORM'] = 'gbm'
+            test = PiglitGLTest(['foo'], exclude_platforms=['glx'])
+            test.is_skip()
diff --git a/unittests/piglit_test_tests.py b/unittests/piglit_test_tests.py
deleted file mode 100644
index 76027fb..0000000
--- a/unittests/piglit_test_tests.py
+++ /dev/null
@@ -1,140 +0,0 @@
-# Copyright (c) 2014, 2015 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.
-
-"""Tests for the piglit_test module"""
-
-from __future__ import (
-    absolute_import, division, print_function, unicode_literals
-)
-
-try:
-    from unittest import mock
-except ImportError:
-    import mock
-
-import nose.tools as nt
-
-from . import utils
-from framework.options import _Options as Options
-from framework.test.base import TestIsSkip
-from framework.test.piglit_test import (PiglitBaseTest, PiglitGLTest,
-                                        PiglitCLTest)
-
-
- at utils.nose.no_error
-def test_initialize_piglitgltest():
-    """test.piglit_test.PiglitGLTest: Class initializes"""
-    PiglitGLTest(['/bin/true'])
-
-
- at utils.nose.no_error
-def test_initialize_piglitcltest():
-    """test.piglit_test.PiglitCLTest: Class initializes"""
-    PiglitCLTest(['/bin/true'])
-
-
-def test_piglittest_interpret_result():
-    """test.piglit_test.PiglitBaseTest.interpret_result(): works with no subtests"""
-    test = PiglitBaseTest(['foo'])
-    test.result.out = 'PIGLIT: {"result": "pass"}\n'
-    test.result.returncode = 0
-    test.interpret_result()
-    nt.eq_(test.result.result, 'pass')
-
-
-def test_piglittest_interpret_result_subtest():
-    """test.piglit_test.PiglitBaseTest.interpret_result(): works with subtests"""
-    test = PiglitBaseTest(['foo'])
-    test.result.out = ('PIGLIT: {"result": "pass"}\n'
-                          'PIGLIT: {"subtest": {"subtest": "pass"}}\n')
-    test.result.returncode = 0
-    test.interpret_result()
-    nt.eq_(test.result.subtests['subtest'], 'pass')
-
-
-def test_piglitest_no_clobber():
-    """test.piglit_test.PiglitBaseTest.interpret_result(): does not clobber subtest entires"""
-    test = PiglitBaseTest(['a', 'command'])
-    test.result.out = (
-        'PIGLIT: {"result": "pass"}\n'
-        'PIGLIT: {"subtest": {"test1": "pass"}}\n'
-        'PIGLIT: {"subtest": {"test2": "pass"}}\n'
-    )
-    test.result.returncode = 0
-    test.interpret_result()
-
-    nt.eq_(test.result.subtests, {'test1': 'pass', 'test2': 'pass'})
-
-
-def test_piglittest_command_getter_serial():
-    """test.piglit_test.PiglitGLTest.command: adds -auto to serial tests"""
-    test = PiglitGLTest(['foo'])
-    nt.assert_in('-auto', test.command)
-
-
-def test_piglittest_command_getter_concurrent():
-    """test.piglit_test.PiglitGLTest.command: adds -fbo and -auto to concurrent tests"""
-    test = PiglitGLTest(['foo'], run_concurrent=True)
-    nt.assert_in('-auto', test.command)
-    nt.assert_in('-fbo', test.command)
-
-
-def test_PiglitGLTest_include_and_exclude():
-    """test.piglit_test.PiglitGLTest.is_skip(): raises if include and exclude are given."""
-    with nt.assert_raises(AssertionError):
-        PiglitGLTest(['foo'],
-                     require_platforms=['glx'],
-                     exclude_platforms=['gbm'])
-
-
- at mock.patch('framework.test.piglit_test.options.OPTIONS', new_callable=Options)
- at utils.nose.not_raises(TestIsSkip)
-def test_PiglitGLTest_platform_in_require(mock_opts):
-    """test.piglit_test.PiglitGLTest.is_skip(): does not skip if platform is in require_platforms"""
-    mock_opts.env['PIGLIT_PLATFORM'] = 'glx'
-    test = PiglitGLTest(['foo'], require_platforms=['glx'])
-    test.is_skip()
-
-
- at mock.patch('framework.test.piglit_test.options.OPTIONS', new_callable=Options)
- at nt.raises(TestIsSkip)
-def test_PiglitGLTest_platform_not_in_require(mock_opts):
-    """test.piglit_test.PiglitGLTest.is_skip(): skips if platform is not in require_platforms"""
-    mock_opts.env['PIGLIT_PLATFORM'] = 'gbm'
-    test = PiglitGLTest(['foo'], require_platforms=['glx'])
-    test.is_skip()
-
-
- at mock.patch('framework.test.piglit_test.options.OPTIONS', new_callable=Options)
- at nt.raises(TestIsSkip)
-def test_PiglitGLTest_platform_in_exclude(mock_opts):
-    """test.piglit_test.PiglitGLTest.is_skip(): skips if platform is in exclude_platforms"""
-    mock_opts.env['PIGLIT_PLATFORM'] = 'glx'
-    test = PiglitGLTest(['foo'], exclude_platforms=['glx'])
-    test.is_skip()
-
-
- at mock.patch('framework.test.piglit_test.options.OPTIONS', new_callable=Options)
- at utils.nose.not_raises(TestIsSkip)
-def test_PiglitGLTest_platform_not_in_exclude(mock_opts):
-    """test.piglit_test.PiglitGLTest.is_skip(): does not skip if platform is in exclude_platforms"""
-    mock_opts.env['PIGLIT_PLATFORM'] = 'gbm'
-    test = PiglitGLTest(['foo'], exclude_platforms=['glx'])
-    test.is_skip()
-- 
2.9.0



More information about the Piglit mailing list