[Piglit] [PATCH 08/49] unittests: port generators/test_glsl to pytest
Dylan Baker
dylan at pnwbakers.com
Fri Jul 29 18:38:54 UTC 2016
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
unittests/generators/test_glsl.py | 319 +++++++++++++-------------------------
1 file changed, 111 insertions(+), 208 deletions(-)
diff --git a/unittests/generators/test_glsl.py b/unittests/generators/test_glsl.py
index 84802c2..66e3f66 100644
--- a/unittests/generators/test_glsl.py
+++ b/unittests/generators/test_glsl.py
@@ -26,20 +26,12 @@ from __future__ import (
)
import itertools
import operator
-import os
-import sys
-import nose.tools as nt
+import pytest
import six
-# Add <piglit root>/generated_tests to the module path, this allows it to be
-# imported for testing.
-sys.path.insert(0, os.path.abspath(
- os.path.join(os.path.dirname(__file__), '..', '..', 'generated_tests')))
-
# pylint can't figure out the sys.path manipulation.
from modules import glsl # pylint: disable=import-error
-from .. import utils
# pylint: disable=no-self-use,invalid-name
@@ -65,238 +57,141 @@ _GLSLES = [
'320 es',
]
+_OPERATORS = [
+ operator.lt,
+ operator.le,
+ operator.eq,
+ operator.ne,
+ operator.ge,
+ operator.gt,
+]
+
def test_factory_glsl():
"""generated_tests.modules.glsl.Version: provides a GLSLVersion."""
test = glsl.Version('110')
- nt.assert_is_instance(test, glsl.GLSLVersion)
+ assert isinstance(test, glsl.GLSLVersion)
def test_factory_glsles():
"""generated_tests.modules.glsl.Version: provides a GLSLESVersion."""
test = glsl.Version('100')
- nt.assert_is_instance(test, glsl.GLSLESVersion)
+ assert isinstance(test, glsl.GLSLESVersion)
def test_factory_cache():
"""generated_tests.modules.glsl.Version: caches objects."""
test1 = glsl.Version('100')
test2 = glsl.Version('100')
- nt.assert_is(test1, test2)
-
-
-class TestCompare(object):
- """Comparison tests for GLSLESVersion and GLSLVersion."""
- _operators = [
- ('<', operator.lt),
- ('<=', operator.le),
- ('==', operator.eq),
- ('!=', operator.ne),
- ('>=', operator.ge),
- ('>', operator.gt),
- ]
-
- @utils.nose.generator
- def test_glsl_glsl(self):
- """Test GLSLVersion <cmp> GLSLVersion."""
- def expected(first, second, op):
- return op(int(first), int(second))
-
- def test(first, second, op):
- nt.eq_(op(glsl.Version(first), glsl.Version(second)),
- expected(first, second, op))
-
- desc = 'generated_tests.modules.glsl.GLSLVersion: {} {} {}'
-
- for ver1, ver2 in itertools.combinations(_GLSL, 2):
- for name, op in self._operators:
- test.description = desc.format(ver1, name, ver2)
- yield test, ver1, ver2, op
-
- @utils.nose.generator
- def test_glsles_glsles(self):
- """Test GLSLESVersion <cmp> GLSLESVersion."""
- def expected(first, second, op):
- # use the slice to drop " es" if it exists
- return op(int(first[:3]), int(second[:3]))
-
- def test(first, second, op):
- nt.eq_(op(glsl.Version(first), glsl.Version(second)),
- expected(first, second, op))
-
- desc = 'generated_tests.modules.glsl.GLSLESVersion: {} {} {}'
-
- for ver1, ver2 in itertools.combinations(_GLSLES, 2):
- for name, op in self._operators:
- test.description = desc.format(ver1, name, ver2)
- yield test, ver1, ver2, op
-
- @nt.raises(TypeError)
- def test_glsl_glsles(self):
- """generated_tests.modules.glsl: GLSLVersion <cmp> GLSLESVersion."""
- return glsl.Version('110') < glsl.Version('100')
-
- @nt.raises(TypeError)
- def test_glsles_glsl(self):
- """generated_tests.modules.glsl: GLSLESVersion <cmp> GLSLVersion."""
- return glsl.Version('100') < glsl.Version('110')
-
- @utils.nose.generator
- def test_glsl_int(self):
- """Test GLSLVersion <cmp> GLSLVersion."""
- def expected(first, second, op):
- return op(int(first), int(second))
-
- def test(first, second, op, expect):
- nt.eq_(op(first, second), expect)
-
- desc = 'generated_tests.modules.glsl.GLSLVersion: {} {} {}'
-
- for ver1, ver2 in itertools.combinations(_GLSL, 2):
- for name, op in self._operators:
- test.description = desc.format(
- 'GLSLVersion({})'.format(ver1),
- name,
- 'int({})'.format(ver2))
- yield (test, glsl.Version(ver1), int(ver2), op,
- expected(ver1, ver2, op))
-
- test.description = desc.format(
- 'int({})'.format(ver1),
- name,
- 'GLSLVersion({})'.format(ver2))
- yield (test, int(ver1), glsl.Version(ver2), op,
- expected(ver1, ver2, op))
-
- @utils.nose.generator
- def test_glsl_float(self):
- """Test GLSLVersion <cmp> GLSLVersion."""
- def expected(first, second, op):
- return op(float(first) / 100, float(second) / 100)
-
- def test(first, second, op, expect):
- nt.eq_(op(first, second), expect)
-
- desc = 'generated_tests.modules.glsl.GLSLVersion: {} {} {}'
-
- for ver1, ver2 in itertools.combinations(_GLSL, 2):
- for name, op in self._operators:
- test.description = desc.format(
- 'GLSLVersion({})'.format(ver1),
- name,
- 'float({})'.format(ver2))
- yield (test, glsl.Version(ver1), float(ver2) / 100, op,
- expected(ver1, ver2, op))
-
- test.description = desc.format(
- 'float({})'.format(ver1),
- name,
- 'GLSLVersion({})'.format(ver2))
- yield (test, float(ver1) / 100, glsl.Version(ver2), op,
- expected(ver1, ver2, op))
-
- @utils.nose.generator
- def test_glsles_int(self):
- """Test GLSLESVersion <cmp> GLSLESVersion."""
- def expected(first, second, op):
- return op(int(first[:3]), int(second[:3]))
-
- def test(first, second, op, expect):
- nt.eq_(op(first, second), expect)
-
- desc = 'generated_tests.modules.glsl.GLSLESVersion: {} {} {}'
-
- for ver1, ver2 in itertools.combinations(_GLSLES, 2):
- for name, op in self._operators:
- test.description = desc.format(
- 'GLSLESVersion({})'.format(ver1),
- name,
- 'int({})'.format(ver2))
- # Slice to avoid calling int on '300 es'
- yield (test, glsl.Version(ver1), int(ver2[:3]), op,
- expected(ver1, ver2, op))
-
- test.description = desc.format(
- 'int({})'.format(ver1),
- name,
- 'GLSLESVersion({})'.format(ver2))
- # Slice to avoid calling int on '300 es'
- yield (test, int(ver1[:3]), glsl.Version(ver2), op,
- expected(ver1, ver2, op))
-
- @utils.nose.generator
- def test_glsles_float(self):
- """Test GLSLESVersion <cmp> GLSLESVersion."""
- def expected(first, second, op):
- return op(float(first[:3]) / 100, float(second[:3]) / 100)
-
- def test(first, second, op, expect):
- nt.eq_(op(first, second), expect)
-
- desc = 'generated_tests.modules.glsl.GLSLESVersion: {} {} {}'
-
- for ver1, ver2 in itertools.combinations(_GLSLES, 2):
- for name, op in self._operators:
- test.description = desc.format(
- 'GLSLESVersion({})'.format(ver1),
- name,
- 'float({})'.format(ver2))
- # Slice to avoid calling float on '300 es'
- yield (test, glsl.Version(ver1), float(ver2[:3]) / 100, op,
- expected(ver1, ver2, op))
-
- test.description = desc.format(
- 'float({})'.format(ver1),
- name,
- 'GLSLESVersion({})'.format(ver2))
- # Slice to avoid calling float on '300 es'
- yield (test, float(ver1[:3]) / 100, glsl.Version(ver2), op,
- expected(ver1, ver2, op))
+ assert test1 is test2
+
+
+ at pytest.mark.parametrize("op,first,second",
+ itertools.product(_OPERATORS, _GLSL, _GLSL))
+def test_compare_glsl_to_glsl(op, first, second):
+ """Test GLSLVersion <cmp> GLSLVersion."""
+ actual = op(glsl.Version(first), glsl.Version(second))
+ assert actual == op(int(first), int(second))
+
+
+ at pytest.mark.parametrize("op,first,second",
+ itertools.product(_OPERATORS, _GLSLES, _GLSLES))
+def test_compare_glsles_to_glsles(op, first, second):
+ """Test GLSLESVersion <cmp> GLSLESVersion."""
+ actual = op(glsl.Version(first), glsl.Version(second))
+ assert actual == op(int(first[:3]), int(second[:3]))
+
+
+ at pytest.mark.raises(exception=TypeError)
+def test_glsl_glsles_exception():
+ """generated_tests.modules.glsl: GLSLVersion <cmp> GLSLESVersion."""
+ return glsl.Version('110') < glsl.Version('100')
+
+
+ at pytest.mark.raises(exception=TypeError)
+def test_glsles_glsl_exception():
+ """generated_tests.modules.glsl: GLSLESVersion <cmp> GLSLVersion."""
+ return glsl.Version('100') < glsl.Version('110')
+
+
+ at pytest.mark.parametrize("op,first,second",
+ itertools.product(_OPERATORS, _GLSL, _GLSL))
+def test_compare_glsl_to_int(op, first, second):
+ """Test GLSLVersion <cmp> GLSLVersion."""
+ actual = op(glsl.Version(first), int(second))
+ assert actual == op(int(first), int(second))
+
+
+ at pytest.mark.parametrize("op,first,second",
+ itertools.product(_OPERATORS, _GLSLES, _GLSLES))
+def test_compare_glsles_to_int(op, first, second):
+ """Test GLSLESVersion <cmp> GLSLESVersion."""
+ actual = op(glsl.Version(first), int(second[:3]))
+ assert actual == op(int(first[:3]), int(second[:3]))
+
+
+ at pytest.mark.parametrize("op,first,second",
+ itertools.product(_OPERATORS, _GLSL, _GLSL))
+def test_compare_glsl_to_float(op, first, second):
+ """Test GLSLVersion <cmp> GLSLVersion."""
+ actual = op(glsl.Version(first), float(second) / 100)
+ expected = op(float(first), float(second))
+ assert actual == expected
+
+
+ at pytest.mark.parametrize("op,first,second",
+ itertools.product(_OPERATORS, _GLSLES, _GLSLES))
+def test_compare_glsles_to_float(op, first, second):
+ """Test GLSLESVersion <cmp> GLSLESVersion."""
+ actual = op(glsl.Version(first), float(second[:3]) / 100)
+ assert actual == op(float(first[:3]), float(second[:3]))
+
+
def test_GLSLVersion_str():
"""generated_tests.modules.glsl.GLSLVersion: str()"""
- nt.eq_(six.text_type(glsl.Version('110')), '110')
+ assert six.text_type(glsl.Version('110')) == '110'
def test_GLSLESVersion_str():
"""generated_tests.modules.glsl.GLSLESVersion: str()"""
- nt.eq_(six.text_type(glsl.Version('100')), '100')
+ assert six.text_type(glsl.Version('100')) == '100'
def test_GLSLVersion_int():
"""generated_tests.modules.glsl.GLSLVersion: int()"""
- nt.eq_(int(glsl.Version('110')), 110)
+ assert int(glsl.Version('110')) == 110
def test_GLSLESVersion_int():
"""generated_tests.modules.glsl.GLSLESVersion: int()"""
- nt.eq_(int(glsl.Version('100')), 100)
+ assert int(glsl.Version('100')) == 100
def test_GLSLVersion_float():
"""generated_tests.modules.glsl.GLSLVersion: float()"""
- nt.eq_(float(glsl.Version('110')), 1.10)
+ assert float(glsl.Version('110')) == 1.10
def test_GLSLESVersion_float():
"""generated_tests.modules.glsl.GLSLESVersion: float()"""
- nt.eq_(float(glsl.Version('100')), 1.00)
+ assert float(glsl.Version('100')) == 1.00
def test_GLSLVersion_print_float():
"""generated_tests.modules.glsl.GLSLVersion: print_float()"""
- nt.eq_(glsl.Version('110').print_float(), '1.10')
+ assert glsl.Version('110').print_float() == '1.10'
def test_GLSLESVersion_print_float():
"""generated_tests.modules.glsl.GLSLESVersion: print_float()"""
- nt.eq_(glsl.Version('100').print_float(), '1.00')
+ assert glsl.Version('100').print_float() == '1.00'
def test_GLSLESVersion_print_float_es():
"""generated_tests.modules.glsl.GLSLESVersion: print_float() (es version)"""
- nt.eq_(glsl.Version('300 es').print_float(), '3.00 es')
+ assert glsl.Version('300 es').print_float() == '3.00 es'
class TestMinVersion_for_stage(object):
@@ -307,9 +202,7 @@ class TestMinVersion_for_stage(object):
"""
def _test(self, stage, version, expected):
- nt.eq_(glsl.MinVersion.for_stage(stage, version), expected,
- msg='(actual) {} != (expected) {}'.format(
- str(version), str(expected)))
+ assert glsl.MinVersion.for_stage(stage, version) == expected
def test_opengl_frag(self):
"""generated_tests.modules.glsl.MinVersion.for_stage: FS (OpenGL)"""
@@ -381,28 +274,30 @@ class TestMinVersion_for_stage_with_ext(object):
"""Tests for generated_tests.modules.glsl.MinVersion.for_stage_with_ext."""
def _test(self, stage, version, expected):
ver, ext = glsl.MinVersion.for_stage_with_ext(stage, version)
- nt.eq_((ver, ext), expected,
- msg='(actual) ({}, {}) != (expected) ({}, {})'.format(
- str(ver), ext, str(expected[0]), expected[1]))
+ assert (ver, ext) == expected
def test_opengl_frag(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: FS (OpenGL)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ FS (OpenGL)"""
self._test('frag', glsl.Version('150'), (glsl.Version('150'), None))
self._test('frag', glsl.Version('110'), (glsl.Version('110'), None))
def test_opengl_vert(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: VS (OpenGL)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ VS (OpenGL)"""
self._test('vert', glsl.Version('150'), (glsl.Version('150'), None))
self._test('vert', glsl.Version('110'), (glsl.Version('110'), None))
def test_opengl_geom(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: GS (OpenGL)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ GS (OpenGL)"""
self._test('geom', glsl.Version('330'), (glsl.Version('330'), None))
self._test('geom', glsl.Version('110'), (glsl.Version('150'), None))
self._test('geom', glsl.Version('150'), (glsl.Version('150'), None))
def test_opengl_tesc(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: TCS (OpenGL)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ TCS (OpenGL)"""
self._test('tesc', glsl.Version('410'), (glsl.Version('410'), None))
self._test('tesc', glsl.Version('140'),
(glsl.Version('140'), 'GL_ARB_tesselation_shader'))
@@ -410,7 +305,8 @@ class TestMinVersion_for_stage_with_ext(object):
(glsl.Version('140'), 'GL_ARB_tesselation_shader'))
def test_opengl_tese(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: TES (OpenGL)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ TES (OpenGL)"""
self._test('tese', glsl.Version('410'), (glsl.Version('410'), None))
self._test('tese', glsl.Version('140'),
(glsl.Version('140'), 'GL_ARB_tesselation_shader'))
@@ -418,7 +314,8 @@ class TestMinVersion_for_stage_with_ext(object):
(glsl.Version('140'), 'GL_ARB_tesselation_shader'))
def test_opengl_comp(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: CS (OpenGL)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ CS (OpenGL)"""
self._test('comp', glsl.Version('430'), (glsl.Version('430'), None))
self._test('comp', glsl.Version('140'),
(glsl.Version('140'), 'GL_ARB_compute_shader'))
@@ -426,19 +323,22 @@ class TestMinVersion_for_stage_with_ext(object):
(glsl.Version('140'), 'GL_ARB_compute_shader'))
def test_opengles_frag(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: FS (OpenGL ES)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ FS (OpenGL ES)"""
self._test('frag', glsl.Version('300 es'),
(glsl.Version('300 es'), None))
self._test('frag', glsl.Version('100'), (glsl.Version('100'), None))
def test_opengles_vert(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: VS (OpenGL ES)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ VS (OpenGL ES)"""
self._test('vert', glsl.Version('300 es'),
(glsl.Version('300 es'), None))
self._test('vert', glsl.Version('100'), (glsl.Version('100'), None))
def test_opengles_geom(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: GS (OpenGL ES)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ GS (OpenGL ES)"""
self._test('geom', glsl.Version('100'),
(glsl.Version('310 es'), 'GL_OES_geometry_shader'))
self._test('geom', glsl.Version('310 es'),
@@ -447,7 +347,8 @@ class TestMinVersion_for_stage_with_ext(object):
(glsl.Version('320 es'), None))
def test_opengles_tesc(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: TCS (OpenGL ES)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ TCS (OpenGL ES)"""
self._test('tesc', glsl.Version('320 es'),
(glsl.Version('320 es'), None))
self._test('tesc', glsl.Version('310 es'),
@@ -456,7 +357,8 @@ class TestMinVersion_for_stage_with_ext(object):
(glsl.Version('310 es'), 'GL_OES_tesselation_shader'))
def test_opengles_tese(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: TES (OpenGL ES)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ TES (OpenGL ES)"""
self._test('tese', glsl.Version('320 es'),
(glsl.Version('320 es'), None))
self._test('tese', glsl.Version('310 es'),
@@ -465,7 +367,8 @@ class TestMinVersion_for_stage_with_ext(object):
(glsl.Version('310 es'), 'GL_OES_tesselation_shader'))
def test_opengles_comp(self):
- """generated_tests.modules.glsl.MinVersion.for_stage_with_ext: TES (OpenGL ES)"""
+ """generated_tests.modules.glsl.MinVersion.for_stage_with_ext:
+ TES (OpenGL ES)"""
self._test('comp', glsl.Version('320 es'),
(glsl.Version('320 es'), None))
self._test('comp', glsl.Version('100'), (glsl.Version('310 es'), None))
--
2.9.0
More information about the Piglit
mailing list