Source

pygame / test / sdl_image_test.py

import os, sys
import unittest
try:
    import StringIO as stringio
except ImportError:
    import io as stringio

import pygame2
import pygame2.sdl.image as image
import pygame2.sdl.video as video
import pygame2.sdl.constants as constants

class SDLImageTest (unittest.TestCase):
    __tags__ = [ "sdl" ]

    def setUp (self):
        video.init ()

    def tearDown (self):
        video.quit ()

    def test_pygame2_sdl_image_load_bmp(self):

        # __doc__ (as of 2009-05-14) for pygame2.sdl.image.load_bmp:

        # load_bmp (file) -> pygame2.sdl.video.Surface
        # 
        # Loads a BMP file and creates a pygame2.sdl.video.Surface from it.
        # 
        # load_bmp (file) -> pygame2.sdl.video.Surface  Loads a BMP file and
        # creates a pygame2.sdl.video.Surface from it.  Loads a BMP file and
        # creates a pygame2.sdl.video.Surface from it. The file argument can
        # be either a file object or the filename.
        imgdir = os.path.dirname (os.path.abspath (__file__))
        sf = image.load_bmp (os.path.join (imgdir, "test.bmp"))
        self.assertEqual (sf.size, (16, 16))

    def test_pygame2_sdl_image_save_bmp(self):

        # __doc__ (as of 2009-05-14) for pygame2.sdl.image.save_bmp:

        # save_bmp (surface, file) -> None
        # 
        # Saves a surface to a bitmap file.
        # 
        # save_bmp (surface, file) -> None  Saves a surface to a bitmap file.
        # Saves a pygame2.sdl.video.Surface to the specified file, where file
        # can be a filename or file object.
        imgdir = os.path.dirname (os.path.abspath (__file__))
        sf = image.load_bmp (os.path.join (imgdir, "test.bmp"))
        buf = None
        if sys.version_info[0] >= 3:
            buf = stringio.BytesIO ()
        else:
            buf = stringio.StringIO ()
        self.assert_ (image.save_bmp (sf, buf) == None)
        self.assertEqual (os.stat (os.path.join (imgdir, "test.bmp")).st_size,
                          len (buf.getvalue ()))

if __name__ == "__main__":
    unittest.main ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.