File: test_screen.py

package info (click to toggle)
pgzero 1.2.post4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,980 kB
  • sloc: python: 4,273; makefile: 166
file content (39 lines) | stat: -rw-r--r-- 1,025 bytes parent folder | download | duplicates (2)
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
36
37
38
39
import unittest
import pygame
import pygame.image

from pgzero.screen import Screen
from pgzero.loaders import set_root, images

pygame.init()
surf = pygame.display.set_mode((200, 100))


class ScreenTest(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        set_root(__file__)

    def setUp(self):
        surf.fill((0, 0, 0))
        self.screen = Screen(surf)

    def assertImagesEqual(self, a, b):
        adata, bdata = (pygame.image.tostring(i, 'RGB') for i in (a, b))

        if adata != bdata:
            raise AssertionError("Images differ")

    def test_blit_surf(self):
        """We can blit a surface to the screen."""
        self.screen.blit(images.alien, (0, 0))
        self.assertImagesEqual(surf, images.expected_alien_blit)

    def test_blit_name(self):
        """screen.blit() accepts an image name instead of a Surface."""
        self.screen.blit('alien', (0, 0))
        self.assertImagesEqual(surf, images.expected_alien_blit)


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