Fredrik Lundh is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

effbot / pil-2009-raclette http://effbot.org/zone/pil-index.htm

Work repository for PIL 1.1.7 and beyond. The "default" branch should be fairly solid, the other branches less so. For production use, see the pil-117 repository.

Clone this repository (size: 1.6 MB): HTTPS / SSH
hg clone https://bitbucket.org/effbot/pil-2009-raclette
hg clone ssh://hg@bitbucket.org/effbot/pil-2009-raclette

pil-2009-raclette / Tests / test_lib_image.py

from tester import *

from PIL import Image

def test_setmode():

    im = Image.new("L", (1, 1), 255)
    im.im.setmode("1")
    assert_equal(im.im.getpixel((0, 0)), 255)
    im.im.setmode("L")
    assert_equal(im.im.getpixel((0, 0)), 255)

    im = Image.new("1", (1, 1), 1)
    im.im.setmode("L")
    assert_equal(im.im.getpixel((0, 0)), 255)
    im.im.setmode("1")
    assert_equal(im.im.getpixel((0, 0)), 255)

    im = Image.new("RGB", (1, 1), (1, 2, 3))
    im.im.setmode("RGB")
    assert_equal(im.im.getpixel((0, 0)), (1, 2, 3))
    im.im.setmode("RGBA")
    assert_equal(im.im.getpixel((0, 0)), (1, 2, 3, 255))
    im.im.setmode("RGBX")
    assert_equal(im.im.getpixel((0, 0)), (1, 2, 3, 255))
    im.im.setmode("RGB")
    assert_equal(im.im.getpixel((0, 0)), (1, 2, 3))

    assert_exception(ValueError, lambda: im.im.setmode("L"))
    assert_exception(ValueError, lambda: im.im.setmode("RGBABCDE"))