def test(self): if not lena_available(): del data['lena'] for sample, params in data.items(): img = getattr(image, sample)() for param, value in params.items(): self.assertEqual(getattr(img, param), value) img.close()
class Lena(TestCase): @skipIf(not lena_available(), 'Lena not available') def test(self): img = image.lena() self.assertEqual(img.size, (512, 512)) self.assertEqual(img.type, types.truecolor) img.close() img = image.lena(32) self.assertEqual(img.size, (32, 32)) img.close()
def test(self): import pystacia from pystacia import image with catch_warnings(record=True) as w: simplefilter('always') self.assertTrue( image.blank(30, 30).is_same(pystacia.blank(30, 30))) self.assertTrue('blank' in w[-1].message.args[0]) if lena_available(): self.assertTrue(image.lena().is_same(pystacia.lena())) self.assertTrue('lena' in w[-1].message.args[0]) tmpname = mkstemp()[1] + '.bmp' img = sample() img.write(tmpname) self.assertTrue( pystacia.read(tmpname).is_same(image.read(tmpname))) self.assertTrue('read' in w[-1].message.args[0]) self.assertTrue( pystacia.read_blob(img.get_blob('bmp')).is_same( image.read_blob(img.get_blob('bmp')))) self.assertTrue( pystacia.read_raw(**img.get_raw('rgb')).is_same( image.read_raw(**img.get_raw('rgb')))) img.close() for symbol in [ 'magick_logo', 'wizard', 'netscape', 'granite', 'rose' ]: self.assertTrue( getattr(image, symbol)().is_same(getattr(pystacia, symbol)())) self.assertTrue(symbol in w[-1].message.args[0]) self.assertIsInstance(pystacia.Image(), image.Image) names = [ 'composites', 'types', 'filters', 'colorspaces', 'compressions', 'axes' ] for name in names: self.assertEqual( getattr(pystacia, name).x, getattr(image, name).x) self.assertTrue(name in w[-1].message.args[0])
def test(self): import pystacia from pystacia import image with catch_warnings(record=True) as w: simplefilter('always') self.assertTrue(image.blank(30, 30). is_same(pystacia.blank(30, 30))) self.assertTrue('blank' in w[-1].message.args[0]) if lena_available(): self.assertTrue(image.lena().is_same(pystacia.lena())) self.assertTrue('lena' in w[-1].message.args[0]) tmpname = mkstemp()[1] + '.bmp' img = sample() img.write(tmpname) self.assertTrue(pystacia.read(tmpname). is_same(image.read(tmpname))) self.assertTrue('read' in w[-1].message.args[0]) self.assertTrue(pystacia.read_blob(img.get_blob('bmp')). is_same(image.read_blob(img.get_blob('bmp')))) self.assertTrue(pystacia.read_raw(**img.get_raw('rgb')). is_same(image.read_raw(**img.get_raw('rgb')))) img.close() for symbol in ['magick_logo', 'wizard', 'netscape', 'granite', 'rose']: self.assertTrue(getattr(image, symbol)(). is_same(getattr(pystacia, symbol)())) self.assertTrue(symbol in w[-1].message.args[0]) self.assertIsInstance(pystacia.Image(), image.Image) names = ['composites', 'types', 'filters', 'colorspaces', 'compressions', 'axes'] for name in names: self.assertEqual(getattr(pystacia, name).x, getattr(image, name).x) self.assertTrue(name in w[-1].message.args[0])
def __weakrefed(factory): """Perform weakref memoization of factory call value.""" global __sample if not __sample: with __lock: sample = factory() if not __sample: __sample = weakref.ref(sample) else: sample = __sample() if not sample: with __lock: if not sample: sample = factory() __sample = weakref.ref(sample) return sample.copy() if lena_available(): sample = partial(__weakrefed, image.lena) sample_size = (512, 512) sample_type = types.truecolor else: sample = partial(__weakrefed, image.magick_logo) sample_size = (640, 480) sample_type = types.palette