def test_enableDisableAttribute(type, offset, stride, type_result, tuple_size): shader = ShaderProgram() mocked_shader_program = MagicMock() shader._shader_program = mocked_shader_program attribute_index = MagicMock() mocked_shader_program.attributeLocation = MagicMock( return_value=attribute_index) shader.enableAttribute("blorp", type, offset, stride) # Validate mocked_shader_program.setAttributeBuffer.assert_called_once_with( attribute_index, type_result, offset, tuple_size, stride) mocked_shader_program.enableAttributeArray.assert_called_once_with( attribute_index) # Disable it again shader.disableAttribute("blorp") mocked_shader_program.disableAttributeArray.assert_called_once_with( attribute_index) # Disable unknown attribute shader.disableAttribute("BEEP") mocked_shader_program.disableAttributeArray.assert_called_once_with( attribute_index)
def test_load(): shader = ShaderProgram() mocked_shader_program = MagicMock() shader._shader_program = mocked_shader_program shader.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Shaders", "test.shader")) # It should be called 3 times, once for vertex, once for fragment and once for geometry call_arg_list = mocked_shader_program.addShaderFromSourceCode.call_args_list assert call(QOpenGLShader.Vertex, "vertex_code") in call_arg_list assert call(QOpenGLShader.Fragment, "fragment_code") in call_arg_list assert call(QOpenGLShader.Geometry, "geometry_code") in call_arg_list
def test_bindAndRelease(): shader = ShaderProgram() mocked_shader_program = MagicMock() shader._shader_program = mocked_shader_program shader.bind() assert mocked_shader_program.bind.call_count == 1 # Doing it without releasing in between shouldn't cause another bind. shader.bind() assert mocked_shader_program.bind.call_count == 1 shader.release() assert mocked_shader_program.release.call_count == 1 shader.release() assert mocked_shader_program.release.call_count == 1 # We left it unbound, so now binding should work. shader.bind() assert mocked_shader_program.bind.call_count == 2
def test_bindAndRelease(): shader = ShaderProgram() mocked_shader_program = MagicMock() shader._shader_program = mocked_shader_program shader.bind() assert mocked_shader_program.bind.call_count == 1 # Doing it without releasing in between shouldn't cause another bind. shader.bind() assert mocked_shader_program.bind.call_count == 1 shader.release() assert mocked_shader_program.release.call_count == 1 shader.release() assert mocked_shader_program.release.call_count == 1 # We left it unbound, so now binding should work. shader.bind() assert mocked_shader_program.bind.call_count == 2