"""Tests for frame preparation helpers."""
import unittest
from unittest.mock import patch
from picogl.backend.gl.enums import GLBitMask
from picogl.backend.gl.enums.point_size import GLPointCapability
from picogl.backend.gl.wrappers.frame import prepare_viewport
[docs]
class RecordingFrame:
def __init__(self, calls):
[docs]
def viewport(self, x, y, width, height):
self.calls.append(("viewport", x, y, width, height))
[docs]
def set_clear_color(self, color):
self.calls.append(("set_clear_color", color))
[docs]
def clear(self, mask):
self.calls.append(("clear", mask))
[docs]
class RecordingDepth:
def __init__(self, calls):
[docs]
def set_depth_test(self, enabled):
self.calls.append(("depth_test", enabled))
[docs]
class RecordingCapabilities:
def __init__(self, calls):
[docs]
def enable(self, cap):
self.calls.append(("enable", cap))
[docs]
class RecordingBackend:
def __init__(self):
[docs]
self.frame = RecordingFrame(self.calls)
[docs]
self.depth = RecordingDepth(self.calls)
[docs]
self.capabilities = RecordingCapabilities(self.calls)
[docs]
class TestPrepareViewport(unittest.TestCase):
[docs]
def test_prepare_viewport_delegates_to_backend(self):
backend = RecordingBackend()
with patch("picogl.frame.platform.system", return_value="Darwin"):
prepare_viewport(320, 240, backend)
self.assertEqual(
backend.calls,
[
("viewport", 0, 0, 640, 480),
("depth_test", True),
("set_clear_color", (0.1, 0.1, 0.1, 1.0)),
("enable", GLPointCapability.PROGRAM_POINT_SIZE),
("clear", GLBitMask.COLOR_BUFFER | GLBitMask.DEPTH_BUFFER),
],
)
if __name__ == "__main__":
unittest.main()