# Test PyOpenGL enums try: from OpenGL import GL except ImportError: return # we cannot test PyOpenGL # assert util.check_enum(GL.GL_RGB) == 'rgb' assert util.check_enum(GL.GL_TRIANGLE_STRIP) == 'triangle_strip' def test_check_identifier(): # Tests check_identifier() assert util.check_identifier('foo') is None assert util.check_identifier('_fooBarBla') is None assert util.check_identifier('_glPosition') is None # Wrong identifier assert util.check_identifier('__').startswith('Identifier') assert util.check_identifier('gl_').startswith('Identifier') assert util.check_identifier('GL_').startswith('Identifier') assert util.check_identifier('double').startswith('Identifier') # Test check_variable() assert util.check_variable('foo') is None assert util.check_variable('a' * 30) is None assert util.check_variable('a' * 32) run_tests_if_main()
hot = get_colormap('hot') assert_allclose(hot[0].rgba, [[0, 0, 0, 1]], 1e-6, 1e-6) assert_allclose(hot[0.5].rgba, [[1, .52272022, 0, 1]], 1e-6, 1e-6) assert_allclose(hot[1.].rgba, [[1, 1, 1, 1]], 1e-6, 1e-6) # Test the GLSL and Python mapping. for name in get_colormaps(): colormap = get_colormap(name) Function(colormap.glsl_map) colors = colormap[np.linspace(-2., 2., 50)] assert colors.rgba.min() >= 0 assert colors.rgba.max() <= 1 def test_normalize(): """Test the _normalize() function.""" from vispy.color.colormap import _normalize for x in (-1, 0., .5, 1., 10., 20): assert _normalize(x) == .5 assert_allclose(_normalize((-1., 0., 1.)), (0., .5, 1.)) assert_allclose(_normalize((-1., 0., 1.), 0., 1.), (0., 0., 1.)) assert_allclose(_normalize((-1., 0., 1.), 0., 1., clip=False), (-1., 0., 1.)) y = _normalize(np.random.randn(100, 5), -10., 10.) assert_allclose([y.min(), y.max()], [0.2975, 1-0.2975], 1e-1, 1e-1) run_tests_if_main()