picogl.tests.test_vertex_array_object

Unit tests for the VertexArrayObject class in the PicoGL OpenGL backend.

This module contains a comprehensive suite of unit tests for verifying the correctness, robustness, and interface of the picogl.backend.modern.core.vertex.array.object.VertexArrayObject class, which manages OpenGL Vertex Array Objects (VAOs) in modern OpenGL rendering workflows.

The tests cover:

  • Object initialization with and without handle parameter

  • VAO binding/unbinding operations

  • VBO management and attribute configuration

  • EBO (Element Buffer Object) management

  • Layout descriptor configuration

  • Drawing operations with various modes

  • Buffer cleanup and memory management

  • Error handling and edge cases

Dependencies:
  • unittest (standard library)

  • unittest.mock.MagicMock for OpenGL function mocking

  • numpy for test data

  • picogl.backend.modern.core.vertex.array.object.VertexArrayObject

  • picogl.buffers.attributes.LayoutDescriptor

To run the tests:

python -m unittest picogl.tests.test_vertex_array_object

Classes

_StubVBO

VertexBuffer stand-in that skips GL construction for unit tests.

TestVertexArrayObject

Test cases for VertexArrayObject class.

Module Contents

class picogl.tests.test_vertex_array_object._StubVBO(handle=None)[source]

Bases: picogl.backend.modern.core.vertex.base.VertexBuffer

VertexBuffer stand-in that skips GL construction for unit tests.

handle = None[source]
bind[source]

Bind this buffer.

unbind[source]

Release this buffer target.

glBindBuffer(target, 0) does not need the previous name. Raising when glIsBuffer is false aborts the draw that is leaving its with block, which is how a stale or array handle shows up as Invalid buffer handle for atoms, ribbons, and selections.

set_data[source]

Upload data to the GPU.

Parameters:
  • data – NumPy array containing buffer data.

  • usage – gl usage hint (e.g., GL_STATIC_DRAW, GL_DYNAMIC_DRAW).

set_vertex_attributes[source]

Set the vertex attribute pointer configuration.

Parameters:
  • index – Attribute index in the VAO.

  • data – Optional data array to store alongside attribute info.

  • size – Number of components per vertex (1-4).

  • normalized – Whether values should be normalized.

  • stride – Byte offset between consecutive attributes.

  • offset – Byte offset of the first attribute.

  • dtype – gl data type (e.g., GL_FLOAT).

  • pointer – Offset pointer for glVertexAttribPointer.

configure[source]

Enable and configure the vertex attribute array.

class picogl.tests.test_vertex_array_object.TestVertexArrayObject(methodName='runTest')[source]

Bases: unittest.TestCase

Test cases for VertexArrayObject class.

setUp()[source]

Set up test fixtures before each test method.

tearDown()[source]

Clean up after each test method.

test_initialization_with_handle()[source]

Test VertexArrayObject initialization with provided handle.

test_initialization_without_handle()[source]

Test VertexArrayObject initialization without handle (auto-generate).

test_initialization_raises_error_when_no_context()[source]

Test that initialization raises error when OpenGL context is not ready.

test_bind()[source]

Test bind method.

test_unbind()[source]

Test unbind method.

test_delete()[source]

Test delete method.

test_add_vbo()[source]

Test add_vbo method.

test_add_ebo()[source]

Test add_ebo method.

test_set_ebo()[source]

Test set_ebo method.

test_set_layout()[source]

Test set_layout method with LayoutDescriptor.

test_set_layout_empty_attributes()[source]

Test set_layout with an empty descriptor still configures the VAO.

test_set_layout_skips_ebo_attribute()[source]

Element-buffer layout entries are not vertex attributes.

test_add_vbo_object()[source]

Test add_vbo_object method for VBO management.

test_get_vbo_object()[source]

Test get_vbo_object method for VBO retrieval.

test_index_count_property()[source]

Test index_count property.

test_draw_with_arrays()[source]

Test draw method with vertex arrays (no EBO).

test_draw_with_elements()[source]

Test draw method with element arrays (EBO present).

test_draw_with_auto_index_count()[source]

Test draw method with automatic index count from EBO.

test_draw_explicit_zero_count_is_noop()[source]

Explicit count=0 must not fall back to the EBO length.

test_delete_buffers()[source]

Test delete_buffers method.

test_context_manager()[source]

Test that VertexArrayObject can be used as a context manager.

test_repr_string()[source]

Test string representation of VertexArrayObject.

test_set_layout_missing_vbo_raises()[source]

set_layout raises when a layout attribute has no registered VBO.

test_error_handling_in_index_count()[source]

Test error handling in index_count property.