<commit_before>""" Test to verify some basic functionality of our OpenGL API. We cover
much more in the test_functionality. Together, these two tests should
touch *all* ES 2.0 API calls.

The only exception is glCompressedTexImage2D and glCompressedTexSubImage2D.
"""

import sys

from nose.tools import assert_equal, assert_true  # noqa

from vispy.app import Canvas
from numpy.testing import assert_almost_equal
from vispy.testing import (requires_application, requires_pyopengl, SkipTest,
                           glut_skip)
from vispy.ext.six import string_types
from vispy.util import use_log_level
from vispy.gloo import gl


def teardown_module():
    gl.use_gl()  # Reset to default


@requires_application()
def test_basics_desktop():
    """ Test desktop GL backend for basic functionality. """
    glut_skip()
    _test_basics('desktop')


@requires_application()
def test_functionality_proxy():
    """ Test GL proxy class for basic functionality. """
    # By using debug mode, we are using the proxy class
    glut_skip()
    _test_basics('desktop debug')


@requires_application()
@requires_pyopengl()
def test_basics_pypengl():
    """ Test pyopengl GL backend for basic functionality. """
    glut_skip()
    _test_basics('pyopengl')


@requires_application()
def test_functionality_angle():
    """ Test angle GL backend for basic functionality. """
    if True:
        raise SkipTest('Skip Angle functionality test for now.')
    if sys.platform.startswith('win'):
        raise SkipTest('Can only test angle functionality on Windows.')

    glut_skip()
    _test_basics('angle')


def _test_basics(backend):
    """ Create app and canvas so we have a context. Then run tests.
    """

    # use the backend
    gl.use_gl(backend)

    with Canvas():
        _test_setting_parameters()
        _test_enabling_disabling()
        _test_setting_stuff()
        _test_object_creation_and_deletion()
        _test_fbo()
        gl.glFinish()


def _test_setting_parameters():
    # Set some parameters and get result
    clr = 1.0, 0.1, 0.2, 0.7
    gl.glClearColor(*clr)
    assert_almost_equal(gl.glGetParameter(gl.GL_COLOR_CLEAR_VALUE), clr)
    #
    gl.glCullFace(gl.GL_FRONT)
    assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_FRONT)
    gl.glCullFace(gl.GL_BACK)
    assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_BACK)
    #
    gl.glDepthFunc(gl.GL_NOTEQUAL)
    assert_equal(gl.glGetParameter(gl.GL_DEPTH_FUNC), gl.GL_NOTEQUAL)
    #
    val = 0.2, 0.3<commit_msg>FIX: Fix warning<commit_after>""" Test to verify some basic functionality of our OpenGL API. We cover
much more in the test_functionality. Together, these two tests should
touch *all* ES 2.0 API calls.

The only exception is glCompressedTexImage2D and glCompressedTexSubImage2D.
"""

import sys

from nose.tools import assert_equal, assert_true  # noqa

from vispy.app import Canvas
from numpy.testing import assert_almost_equal
from vispy.testing import (requires_application, requires_pyopengl, SkipTest,
                           glut_skip)
from vispy.ext.six import string_types
from vispy.util import use_log_level
from vispy.gloo import gl


def teardown_module():
    gl.use_gl()  # Reset to default


@requires_application()
def test_basics_desktop():
    """ Test desktop GL backend for basic functionality. """
    glut_skip()
    _test_basics('desktop')


@requires_application()
def test_functionality_proxy():
    """ Test GL proxy class for basic functionality. """
    # By using debug mode, we are using the proxy class
    glut_skip()
    _test_basics('desktop debug')


@requires_application()
@requires_pyopengl()
def test_basics_pypengl():
    """ Test pyopengl GL backend for basic functionality. """
    glut_skip()
    _test_basics('pyopengl')


@requires_application()
def test_functionality_angle():
    """ Test angle GL backend for basic functionality. """
    if True:
        raise SkipTest('Skip Angle functionality test for now.')
    if sys.platform.startswith('win'):
        raise SkipTest('Can only test angle functionality on Windows.')

    glut_skip()
    _test_basics('angle')


def _test_basics(backend):
    """ Create app and canvas so we have a context. Then run tests.
    """

    # use the backend
    with use_log_level('error', print_msg=False):
        gl.use_gl(backend)  # pyopengl throws warning on injection

    with Canvas():
        _test_setting_parameters()
        _test_enabling_disabling()
        _test_setting_stuff()
        _test_object_creation_and_deletion()
        _test_fbo()
        gl.glFinish()


def _test_setting_parameters():
    # Set some parameters and get result
    clr = 1.0, 0.1, 0.2, 0.7
    gl.glClearColor(*clr)
    assert_almost_equal(gl.glGetParameter(gl.GL_COLOR_CLEAR_VALUE), clr)
    #
    gl.glCullFace(gl.GL_FRONT)
    assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_FRONT)
    gl.glCullFace(gl.GL_BACK)
    assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_BACK)
    #
    gl.glDepthFunc(gl.GL_NOTEQUAL)
    assert_equal(gl.glGetParameter(gl.GL_DEPTH_FUNC), gl.GL_NOTEQUAL)
    #
    val = 0.2, 0.3
{'fraction_non_alphanumeric': 0.09331774790570817, 'fraction_numerical': 0.006234171050068186, 'mean_word_length': 3.714416896235078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '954753', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1634, 'n_words': 429}