import imageop SIZES = (1, 2, 3, 4) _VALUES = (1, 2, 2**10, 2**15-1, 2**15, 2**15+1, 2**31-2, 2**31-1) VALUES = tuple( -x for x in reversed(_VALUES) ) + (0,) + _VALUES AAAAA = "A" * 1024 MAX_LEN = 2**20 def _test(name, size=None, *extra): func = getattr(imageop, name) for height in VALUES: for width in VALUES: strlen = abs(width * height) if size: strlen *= size message = "%s: %sx%s (size=%s)" % (name, width, height, size) else: message = "%s: %sx%s" % (name, width, height) if strlen < MAX_LEN: data = "A" * strlen else: data = AAAAA message += " (datalen=%s)" % len(data) if size: arguments = (data, size, width, height) + extra else: arguments = (data, width, height) + extra print message+"..." try: func(*arguments) except ValueError: message += ' -> ValueError' except imageop.error: message += ' -> imageop.error' print message def test(name, *extra): _test(name, None, *extra) def testSize(name, *extra): for size in SIZES: _test(name, size, *extra) testSize("crop", 0, 0, 0, 0) testSize("scale", 1, 0) testSize("scale", -1, -1) testSize("tovideo") test("grey2mono", 128) test("grey2grey4") test("grey2grey2") test("dither2mono") test("dither2grey2") test("mono2grey", 0, 0) test("grey22grey") test("rgb2rgb8") # nlen*4 == len test("rgb82rgb") test("rgb2grey") test("grey2rgb")