File: camera_test.py

package info (click to toggle)
pygame 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,624 kB
  • sloc: ansic: 66,926; python: 48,742; javascript: 1,153; objc: 224; sh: 121; makefile: 59; cpp: 25
file content (35 lines) | stat: -rw-r--r-- 801 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
31
32
33
34
35
import unittest
import os
import pygame
import pygame.camera


class CameraModuleTest(unittest.TestCase):
    def setUp(self):
        pygame.init()

        pygame.camera.init()

    @unittest.skipIf(
        os.environ.get("SDL_VIDEODRIVER") in ["dummy", "android"],
        "requires the SDL_VIDEODRIVER to be non dummy",
    )
    def test_camera(self):
        cameras = pygame.camera.list_cameras()

        if len(cameras) == 0:
            self.skipTest("No cameras found")

        cam = pygame.camera.Camera(cameras[0], (640, 480))
        cam.start()
        image = cam.get_image()
        self.assertIsNotNone(image, "Could not capture image")
        cam.stop()

    def tearDown(self):
        pygame.camera.quit()
        pygame.quit()


if __name__ == "__main__":
    unittest.main()