1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
from pathlib import Path
from unittest import mock
from moderngl_window import screenshot
from headless import HeadlessTestCase
from utils import settings_context
class ScreenshotTestCase(HeadlessTestCase):
@mock.patch('PIL.Image.Image.save', new=mock.MagicMock())
def test_fbo(self):
"""Create screenshot from fbo"""
screenshot.create(self.window.fbo)
@mock.patch('PIL.Image.Image.save', new=mock.MagicMock())
def test_texture(self):
"""Create screenshot from texture"""
texture = self.ctx.texture((16, 16), 4)
screenshot.create(texture)
@mock.patch('os.makedirs', new=mock.MagicMock())
def test_with_screenshot_path(self):
"""Create screenshot with SCREENSHOT_PATH defined in settings"""
with settings_context({'SCREENSHOT_PATH': (Path.cwd() / 'screenshots')}):
self.test_fbo()
def test_incorrect_source(self):
"""Attempt to pass invalid source"""
with self.assertRaises(ValueError):
screenshot.create("Hello")
|