Re: [Piglit] [PATCH] unittests: test WflInfo in its own module and correct depending ones

2017-11-15 Thread Brian Paul


Reviewed-by: Brian Paul 

On 11/15/2017 02:21 AM, Andres Gomez wrote:

Fixes: edc41a1db ("framework: move WflInfo class into new wflinfo.py module")

Cc: Brian Paul 
Cc: Dylan Baker 
Signed-off-by: Andres Gomez 
---
  unittests/framework/test/test_glsl_parser_test.py |   2 +-
  unittests/framework/test/test_opengl.py   | 363 +---
  unittests/framework/test_wflinfo.py   | 389 ++
  3 files changed, 395 insertions(+), 359 deletions(-)
  create mode 100644 unittests/framework/test_wflinfo.py

diff --git a/unittests/framework/test/test_glsl_parser_test.py 
b/unittests/framework/test/test_glsl_parser_test.py
index 124f3e9e9..d252e27bc 100644
--- a/unittests/framework/test/test_glsl_parser_test.py
+++ b/unittests/framework/test/test_glsl_parser_test.py
@@ -55,7 +55,7 @@ class _Setup(object):
  self.patchers = [
  mock.patch('framework.test.glsl_parser_test._HAS_GL_BIN', True),
  mock.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', True),
-mock.patch.dict('framework.test.opengl.OPTIONS.env',
+mock.patch.dict('framework.wflinfo.OPTIONS.env',
  {'PIGLIT_PLATFORM': 'foo'}),
  ]

diff --git a/unittests/framework/test/test_opengl.py 
b/unittests/framework/test/test_opengl.py
index a3974081a..59024edf1 100644
--- a/unittests/framework/test/test_opengl.py
+++ b/unittests/framework/test/test_opengl.py
@@ -23,8 +23,6 @@
  from __future__ import (
  absolute_import, division, print_function, unicode_literals
  )
-import subprocess
-import textwrap
  try:
  from unittest import mock
  except ImportError:
@@ -32,6 +30,7 @@ except ImportError:

  import pytest

+from framework import wflinfo
  from framework.test import opengl
  from framework.test.base import TestIsSkip as _TestIsSkip

@@ -40,365 +39,13 @@ from .. import utils
  # pylint: disable=no-self-use,attribute-defined-outside-init,protected-access


-def _has_wflinfo():
-"""Return True if wflinfo is available in PATH."""
-try:
-subprocess.check_call(['wflinfo', '--help'])
-except subprocess.CalledProcessError:
-return False
-except OSError as e:
-if e.errno != 2:
-raise
-return False
-return True
-
-
-@pytest.mark.skipif(not _has_wflinfo(), reason="Tests require wflinfo binary.")
-class TestWflInfo(object):
-"""Tests for the WflInfo class."""
-
-class TestAttributes(object):
-"""test for attribute assignments."""
-
-@pytest.yield_fixture(autouse=True)
-def patch(self):
-"""Mock a few things for testing purposes."""
-# This is pretty ugly, but as a Borb with a private shared state,
-# the only way to test this module is to actually replace the
-# shared_state with a mock value so it's reset after each test
-with mock.patch.dict('framework.test.opengl.OPTIONS.env',
- {'PIGLIT_PLATFORM': 'foo'}), \
-mock.patch(
-'framework.test.opengl.WflInfo._WflInfo__shared_state',
-{}):
-yield
-
-def setup(self):
-"""Setup each instance, patching necissary bits."""
-self._test = opengl.WflInfo()
-
-def test_gl_extension(self):
-"""test.opengl.WflInfo.gl_extensions: Provides list of gl
-extensions.
-"""
-rv = (b'foo\nbar\nboink\nOpenGL extensions: '
-  b'GL_foobar GL_ham_sandwhich\n')
-expected = set(['GL_foobar', 'GL_ham_sandwhich'])
-
-with mock.patch('framework.test.opengl.subprocess.check_output',
-mock.Mock(return_value=rv)):
-assert self._test.gl_extensions == expected
-
-def test_gl_version(self):
-"""test.opengl.WflInfo.gl_version: Provides a version number."""
-rv = textwrap.dedent("""\
-Waffle platform: gbm
-Waffle api: gl
-OpenGL vendor string: Intel Open Source Technology Center
-OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
-OpenGL version string: 18 (Core Profile) Mesa 11.0.4
-OpenGL context flags: 0x0
-""").encode('utf-8')
-with mock.patch('framework.test.opengl.subprocess.check_output',
-mock.Mock(return_value=rv)):
-assert self._test.gl_version == 18.0
-
-def test_gles_version(self):
-"""test.opengl.WflInfo.gles_version: Provides a version number."""
-rv = textwrap.dedent("""\
-Waffle platform: gbm
-Waffle api: gles3
-OpenGL vendor string: Intel Open Source Technology Center
-OpenGL renderer 

[Piglit] [PATCH] unittests: test WflInfo in its own module and correct depending ones

2017-11-15 Thread Andres Gomez
Fixes: edc41a1db ("framework: move WflInfo class into new wflinfo.py module")

Cc: Brian Paul 
Cc: Dylan Baker 
Signed-off-by: Andres Gomez 
---
 unittests/framework/test/test_glsl_parser_test.py |   2 +-
 unittests/framework/test/test_opengl.py   | 363 +---
 unittests/framework/test_wflinfo.py   | 389 ++
 3 files changed, 395 insertions(+), 359 deletions(-)
 create mode 100644 unittests/framework/test_wflinfo.py

diff --git a/unittests/framework/test/test_glsl_parser_test.py 
b/unittests/framework/test/test_glsl_parser_test.py
index 124f3e9e9..d252e27bc 100644
--- a/unittests/framework/test/test_glsl_parser_test.py
+++ b/unittests/framework/test/test_glsl_parser_test.py
@@ -55,7 +55,7 @@ class _Setup(object):
 self.patchers = [
 mock.patch('framework.test.glsl_parser_test._HAS_GL_BIN', True),
 mock.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', True),
-mock.patch.dict('framework.test.opengl.OPTIONS.env',
+mock.patch.dict('framework.wflinfo.OPTIONS.env',
 {'PIGLIT_PLATFORM': 'foo'}),
 ]
 
diff --git a/unittests/framework/test/test_opengl.py 
b/unittests/framework/test/test_opengl.py
index a3974081a..59024edf1 100644
--- a/unittests/framework/test/test_opengl.py
+++ b/unittests/framework/test/test_opengl.py
@@ -23,8 +23,6 @@
 from __future__ import (
 absolute_import, division, print_function, unicode_literals
 )
-import subprocess
-import textwrap
 try:
 from unittest import mock
 except ImportError:
@@ -32,6 +30,7 @@ except ImportError:
 
 import pytest
 
+from framework import wflinfo
 from framework.test import opengl
 from framework.test.base import TestIsSkip as _TestIsSkip
 
@@ -40,365 +39,13 @@ from .. import utils
 # pylint: disable=no-self-use,attribute-defined-outside-init,protected-access
 
 
-def _has_wflinfo():
-"""Return True if wflinfo is available in PATH."""
-try:
-subprocess.check_call(['wflinfo', '--help'])
-except subprocess.CalledProcessError:
-return False
-except OSError as e:
-if e.errno != 2:
-raise
-return False
-return True
-
-
-@pytest.mark.skipif(not _has_wflinfo(), reason="Tests require wflinfo binary.")
-class TestWflInfo(object):
-"""Tests for the WflInfo class."""
-
-class TestAttributes(object):
-"""test for attribute assignments."""
-
-@pytest.yield_fixture(autouse=True)
-def patch(self):
-"""Mock a few things for testing purposes."""
-# This is pretty ugly, but as a Borb with a private shared state,
-# the only way to test this module is to actually replace the
-# shared_state with a mock value so it's reset after each test
-with mock.patch.dict('framework.test.opengl.OPTIONS.env',
- {'PIGLIT_PLATFORM': 'foo'}), \
-mock.patch(
-'framework.test.opengl.WflInfo._WflInfo__shared_state',
-{}):
-yield
-
-def setup(self):
-"""Setup each instance, patching necissary bits."""
-self._test = opengl.WflInfo()
-
-def test_gl_extension(self):
-"""test.opengl.WflInfo.gl_extensions: Provides list of gl
-extensions.
-"""
-rv = (b'foo\nbar\nboink\nOpenGL extensions: '
-  b'GL_foobar GL_ham_sandwhich\n')
-expected = set(['GL_foobar', 'GL_ham_sandwhich'])
-
-with mock.patch('framework.test.opengl.subprocess.check_output',
-mock.Mock(return_value=rv)):
-assert self._test.gl_extensions == expected
-
-def test_gl_version(self):
-"""test.opengl.WflInfo.gl_version: Provides a version number."""
-rv = textwrap.dedent("""\
-Waffle platform: gbm
-Waffle api: gl
-OpenGL vendor string: Intel Open Source Technology Center
-OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
-OpenGL version string: 18 (Core Profile) Mesa 11.0.4
-OpenGL context flags: 0x0
-""").encode('utf-8')
-with mock.patch('framework.test.opengl.subprocess.check_output',
-mock.Mock(return_value=rv)):
-assert self._test.gl_version == 18.0
-
-def test_gles_version(self):
-"""test.opengl.WflInfo.gles_version: Provides a version number."""
-rv = textwrap.dedent("""\
-Waffle platform: gbm
-Waffle api: gles3
-OpenGL vendor string: Intel Open Source Technology Center
-OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
-OpenGL version string: OpenGL ES 7.1 Mesa 11.0.4