File: test_screenshot.py

package info (click to toggle)
python-moderngl-window 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 69,260 kB
  • sloc: python: 11,225; makefile: 20
file content (30 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download
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")