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()
|