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_image_getpixel.py

from tester import *

from PIL import Image

def color(mode):
    bands = Image.getmodebands(mode)
    if bands == 1:
        return 1
    else:
        return tuple(range(1, bands+1))

def test_pixel():
    
    def pixel(mode):
        c = color(mode)
        im = Image.new(mode, (1, 1), None)
        im.putpixel((0, 0), c)
        return im.getpixel((0, 0))

    assert_equal(pixel("1"), 1)
    assert_equal(pixel("L"), 1)
    assert_equal(pixel("LA"), (1, 2))
    assert_equal(pixel("I"), 1)
    assert_equal(pixel("I;16"), 1)
    assert_equal(pixel("I;16B"), 1)
    assert_equal(pixel("F"), 1.0)
    assert_equal(pixel("P"), 1)
    assert_equal(pixel("PA"), (1, 2))
    assert_equal(pixel("RGB"), (1, 2, 3))
    assert_equal(pixel("RGBA"), (1, 2, 3, 4))
    assert_equal(pixel("RGBX"), (1, 2, 3, 4))
    assert_equal(pixel("CMYK"), (1, 2, 3, 4))
    assert_equal(pixel("YCbCr"), (1, 2, 3))

def test_image():
    
    def pixel(mode):
        im = Image.new(mode, (1, 1), color(mode))
        return im.getpixel((0, 0))

    assert_equal(pixel("1"), 1)
    assert_equal(pixel("L"), 1)
    assert_equal(pixel("LA"), (1, 2))
    assert_equal(pixel("I"), 1)
    assert_equal(pixel("I;16"), 1)
    assert_equal(pixel("I;16B"), 1)
    assert_equal(pixel("F"), 1.0)
    assert_equal(pixel("P"), 1)
    assert_equal(pixel("PA"), (1, 2))
    assert_equal(pixel("RGB"), (1, 2, 3))
    assert_equal(pixel("RGBA"), (1, 2, 3, 4))
    assert_equal(pixel("RGBX"), (1, 2, 3, 4))
    assert_equal(pixel("CMYK"), (1, 2, 3, 4))
    assert_equal(pixel("YCbCr"), (1, 2, 3))