[Piglit] [PATCH 34/49] unittests: port oglconform_tests to pytest

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


Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 unittests/oglconform_tests.py       | 160 -----------------------------------
 unittests/suites/test_oglconform.py | 163 ++++++++++++++++++++++++++++++++++++
 2 files changed, 163 insertions(+), 160 deletions(-)
 delete mode 100644 unittests/oglconform_tests.py
 create mode 100644 unittests/suites/test_oglconform.py

diff --git a/unittests/oglconform_tests.py b/unittests/oglconform_tests.py
deleted file mode 100644
index 4997832..0000000
--- a/unittests/oglconform_tests.py
+++ /dev/null
@@ -1,160 +0,0 @@
-# Copyright (c) 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 oglconform integration."""
-
-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 six.moves import cStringIO as StringIO
-
-from . import utils
-from framework import grouptools
-
-with mock.patch('framework.core.PIGLIT_CONFIG.required_get',
-                mock.Mock(return_value='piglit.conf.example')):
-    with mock.patch('subprocess.call', mock.Mock()):
-        from tests import oglconform
-
-# pylint: disable=protected-access,invalid-name,line-too-long
-
-
- at mock.patch.object(oglconform.tempfile, 'NamedTemporaryFile')
-def test_make_profile(mock_temp):
-    """tests.oglconform._make_profile: Adds test names"""
-    io_ = mock.Mock(wraps=StringIO(u'group test.name\n'))
-    io_.name = mock.Mock()
-    mock_file = mock.MagicMock()
-    mock_file.__enter__.return_value = io_
-    mock_temp.return_value = mock_file
-
-    with mock.patch('subprocess.call', mock.Mock()):
-        profile = oglconform._make_profile()
-
-    name = grouptools.join('oglconform', 'group', 'test.name')
-    nt.ok_(name in profile.test_list,
-           msg='{} not in {}'.format(name, profile.test_list.keys()))
-
-
- at utils.nose.not_raises(ValueError)
- at mock.patch.object(oglconform.tempfile, 'NamedTemporaryFile')
-def test_make_profile_missing(mock_temp):
-    """tests.oglconform._make_profile: handles missing groups"""
-    io_ = mock.Mock(wraps=StringIO(u'test.name\n'))
-    io_.name = mock.Mock()
-    mock_file = mock.MagicMock()
-    mock_file.__enter__.return_value = io_
-    mock_temp.return_value = mock_file
-
-    with mock.patch('subprocess.call', mock.Mock()):
-        oglconform._make_profile()
-
-
-def test_oglctest_command():
-    """tests.oglconform.OGLCtest.command: value is as expected"""
-    expected = ['piglit.conf.example', '-minFmt', '-v', '4', '-test', 'group',
-                'test']
-
-    test = oglconform.OGLCTest('group', 'test')
-    nt.eq_(expected, test.command)
-
-
-def test_oglctest_interpret_result_pass():
-    """tests.oglconform.OGLCtest.interpret_result: status is pass when expected
-    """
-    test = oglconform.OGLCTest('group', 'test')
-    test.result.returncode = 0
-    test.result.out = (
-        'Another line\n'
-        'Total Passed : 1\n'
-        'Total Failed : 0\n'
-        'Total Not run: 0\n'
-    )
-    test.interpret_result()
-
-    nt.eq_(test.result.result, 'pass')
-
-
-def test_oglctest_interpret_result_skip():
-    """tests.oglconform.OGLCtest.interpret_result: status is skip when tests not run"""
-    test = oglconform.OGLCTest('group', 'test')
-    test.result.returncode = 0
-    test.result.out = (
-        'Another line\n'
-        'Total Failed : 0\n'
-        'Total Passed : 0\n'
-        'Total Not run: 1\n'
-    )
-    test.interpret_result()
-
-    nt.eq_(test.result.result, 'skip')
-
-
- at utils.nose.generator
-def test_oglctest_interpret_result_skip_re():
-    """Generate tests for various skip tests."""
-    values = [
-        'no test in schedule is compat',
-        'GLSL 1.30 is not supported',
-        'GLSL 1.40 is not supported',
-        'GLSL 1.50 is not supported',
-        'GLSL 3.30 is not supported',
-        'GLSL 3.40 is not supported',
-        'GLSL 3.50 is not supported',
-        'wont be scheduled due to lack of compatible fbconfig'
-    ]
-
-    def test(out):
-        """The actual test."""
-        test = oglconform.OGLCTest('group', 'value')
-        test.result.out = out
-        test.result.returncode = 0
-        test.interpret_result()
-        nt.eq_(test.result.result, 'skip')
-
-    for each in values:
-        test.description = ('tests.oglconform.OGLCTest.interpret_result: '
-                            '"{}" in result.out makes status skip'.format(each))
-        yield test, each
-
-
-def test_oglctest_interpret_result_fail():
-    """tests.oglconform.OGLCtest.interpret_result: status is fail otherwise"""
-    test = oglconform.OGLCTest('group', 'test')
-    test.result.returncode = 0
-    test.interpret_result()
-
-    nt.eq_(test.result.result, 'fail')
-
-
-def test_oglctest_interpret_result_crash():
-    """tests.oglconform.OGLCtest.interpret_result: status is crash if returncode is not 0"""
-    test = oglconform.OGLCTest('group', 'test')
-    test.result.returncode = -1
-    test.interpret_result()
-
-    nt.eq_(test.result.result, 'crash')
diff --git a/unittests/suites/test_oglconform.py b/unittests/suites/test_oglconform.py
new file mode 100644
index 0000000..6e6b690
--- /dev/null
+++ b/unittests/suites/test_oglconform.py
@@ -0,0 +1,163 @@
+# Copyright (c) 2015-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 oglconform integration."""
+
+from __future__ import (
+    absolute_import, division, print_function, unicode_literals
+)
+try:
+    import mock
+except ImportError:
+    from unittest import mock
+
+import pytest
+from six.moves import cStringIO as StringIO
+
+from framework import grouptools
+from framework import status
+
+with mock.patch('framework.core.PIGLIT_CONFIG.required_get',
+                mock.Mock(return_value='piglit.conf.example')):
+    with mock.patch('subprocess.call', mock.Mock()):
+        from tests import oglconform
+
+# pylint: disable=protected-access,no-self-use
+
+
+class TestMakeProfile(object):
+    """Tests for the _make_profile function."""
+
+    def test_basic(self, mocker):
+        """tests.oglconform._make_profile: Adds test names"""
+        io_ = mocker.Mock(wraps=StringIO(u'group test.name\n'))
+        io_.name = mocker.Mock()
+
+        mock_file = mocker.MagicMock()
+        mock_file.__enter__.return_value = io_
+
+        mock_temp = mocker.patch.object(oglconform.tempfile,
+                                        'NamedTemporaryFile')
+        mock_temp.return_value = mock_file
+
+        mocker.patch('subprocess.call', mocker.Mock())
+        profile = oglconform._make_profile()
+
+        name = grouptools.join('oglconform', 'group', 'test.name')
+        assert name in profile.test_list
+
+    def test_missing(self, mocker):
+        """tests.oglconform._make_profile: handles missing groups"""
+        io_ = mocker.Mock(wraps=StringIO(u'test.name\n'))
+        io_.name = mocker.Mock()
+
+        mock_file = mocker.MagicMock()
+        mock_file.__enter__.return_value = io_
+
+        mock_temp = mocker.patch.object(oglconform.tempfile,
+                                        'NamedTemporaryFile')
+        mock_temp.return_value = mock_file
+
+        mocker.patch('subprocess.call', mocker.Mock())
+        oglconform._make_profile()
+
+
+class TestOGLCTest(object):
+    """Tests for the OGLCTest class."""
+
+    def test_command(self):
+        """tests.oglconform.OGLCtest.command: value is as expected"""
+        expected = ['piglit.conf.example', '-minFmt', '-v', '4', '-test',
+                    'group', 'test']
+
+        test = oglconform.OGLCTest('group', 'test')
+        assert expected == test.command
+
+    class TestInterpretResult(object):
+        """Tests for the interpret_result method."""
+
+        def test_pass(self):
+            """tests.oglconform.OGLCtest.interpret_result: status is pass when
+            expected.
+            """
+            test = oglconform.OGLCTest('group', 'test')
+            test.result.returncode = 0
+            test.result.out = (
+                'Another line\n'
+                'Total Passed : 1\n'
+                'Total Failed : 0\n'
+                'Total Not run: 0\n'
+            )
+            test.interpret_result()
+
+            assert test.result.result is status.PASS
+
+        def test_skip_from_not_run(self):
+            """tests.oglconform.OGLCtest.interpret_result: status is skip when
+            tests not run.
+            """
+            test = oglconform.OGLCTest('group', 'test')
+            test.result.returncode = 0
+            test.result.out = (
+                'Another line\n'
+                'Total Failed : 0\n'
+                'Total Passed : 0\n'
+                'Total Not run: 1\n'
+            )
+            test.interpret_result()
+
+            assert test.result.result is status.SKIP
+
+        def test_fail(self):
+            """tests.oglconform.OGLCtest.interpret_result: status is fail
+            otherwise.
+            """
+            test = oglconform.OGLCTest('group', 'test')
+            test.result.returncode = 0
+            test.interpret_result()
+
+            assert test.result.result is status.FAIL
+
+        def test_crash(self):
+            """tests.oglconform.OGLCtest.interpret_result: status is crash if
+            returncode is not 0.
+            """
+            test = oglconform.OGLCTest('group', 'test')
+            test.result.returncode = -1
+            test.interpret_result()
+
+            assert test.result.result is status.CRASH
+
+    @pytest.mark.parametrize("out", [
+        'no test in schedule is compat',
+        'GLSL 1.30 is not supported',
+        'GLSL 1.40 is not supported',
+        'GLSL 1.50 is not supported',
+        'GLSL 3.30 is not supported',
+        'GLSL 3.40 is not supported',
+        'GLSL 3.50 is not supported',
+        'wont be scheduled due to lack of compatible fbconfig',
+    ])
+    def test_skip_from_re(self, out):
+        test = oglconform.OGLCTest('group', 'value')
+        test.result.out = out
+        test.result.returncode = 0
+        test.interpret_result()
+        assert test.result.result == 'skip'
-- 
2.9.0



More information about the Piglit mailing list