picogl.tests.test_glmesh

Unit tests for the GLMesh 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.renderer.glmesh.GLMesh class, which manages GPU-resident mesh data and rendering.

The tests cover:

  • Object initialization with various mesh data

  • from_mesh_data class method

  • GPU buffer upload and allocation

  • OpenGL binding/unbinding operations

  • Drawing operations

  • Context manager functionality

  • Resource cleanup and memory management

  • Error handling and edge cases

  • Data validation and type conversion

Dependencies:
  • unittest (standard library)

  • unittest.mock.MagicMock for OpenGL function mocking

  • numpy for test data

  • picogl.renderer.glmesh.GLMesh

  • picogl.renderer.meshdata.MeshData

To run the tests:

python -m unittest picogl.tests.test_glmesh

Classes

TestGLMesh

Test cases for GLMesh class.

Module Contents

class picogl.tests.test_glmesh.TestGLMesh(methodName='runTest')[source]

Bases: unittest.TestCase

Test cases for GLMesh class.

setUp()[source]

Set up test fixtures before each test method.

tearDown()[source]

Clean up after each test method.

test_initialization_with_all_parameters()[source]

Test GLMesh initialization with all parameters.

test_initialization_with_minimal_parameters()[source]

Test GLMesh initialization with only vertices and faces.

test_initialization_with_empty_faces()[source]

Test GLMesh initialization with empty faces raises error.

test_initialization_with_none_faces()[source]

Test GLMesh initialization with None faces raises error.

test_initialization_data_type_conversion()[source]

Test that data is properly converted to correct types.

test_initialization_array_reshaping()[source]

Test that arrays are properly reshaped.

test_from_mesh_data_with_all_attributes()[source]

Test from_mesh_data with all MeshData attributes.

test_from_mesh_data_with_minimal_attributes()[source]

Test from_mesh_data with minimal MeshData attributes.

test_from_mesh_data_without_uvs()[source]

Test from_mesh_data without UVs attribute.

test_upload_first_time()[source]

Test upload method for the first time.

test_upload_already_uploaded()[source]

Test upload method when already uploaded.

test_upload_with_uvs()[source]

Test upload method with UVs.

test_upload_without_uvs()[source]

Test upload method without UVs.

test_bind_with_uploaded_mesh()[source]

Test bind method with uploaded mesh.

test_bind_without_upload()[source]

Test bind method without upload raises error.

test_unbind_with_vao()[source]

Test unbind method with VAO.

test_unbind_without_vao()[source]

Test unbind method without VAO.

test_delete_with_vao()[source]

Test delete method with VAO.

test_delete_without_vao()[source]

Test delete method without VAO.

test_context_manager()[source]

Test that GLMesh can be used as a context manager.

test_draw_with_uploaded_mesh()[source]

Test draw method with uploaded mesh.

test_draw_without_upload()[source]

Test draw method without upload handles error.

test_draw_with_exception_handling()[source]

Test draw method with exception handling.

test_vertex_count_calculation()[source]

Test vertex count calculation.

test_data_validation()[source]

Test data validation and type checking.

test_default_color_generation()[source]

Test default colour generation.

test_default_normal_generation()[source]

Test default normal generation.

test_default_uv_generation()[source]

Test default UV generation.

test_mesh_data_integration()[source]

Test integration with MeshData class.

test_upload_vbo_parameters()[source]

Test that VBOs are added with correct parameters.

test_ebo_parameters()[source]

Test that EBO is added with correct parameters.