Example #1
0
    def test_instantiate(self):
        class Subclass(Image):
            pass

        self.assertIsInstance(blank(30, 30), Image)
        self.assertIsInstance(blank(30, 30, factory=Subclass), Subclass)

        registry.image_factory = Subclass
        self.assertIsInstance(blank(30, 30), Subclass)
        registry.image_factory = Image
Example #2
0
    def test_get_pixel(self):
        img = blank(5, 5, color.from_string('red'))
        self.assertEqual(img.get_pixel(0, 0), color.from_string('red'))
        img.close()

        img = blank(5, 5, color.from_string('blue'))
        self.assertEqual(img.get_pixel(0, 1), color.from_string('blue'))
        img.close()

        img = blank(5, 5, color.from_string('white'))
        self.assertEqual(img.get_pixel(1, 1), color.from_string('white'))
        img.close()
Example #3
0
    def test_blank(self):
        img = blank(10, 20)

        self.assertEqual(img.get_pixel(5, 5).alpha, 0)
        self.assertEqual(img.size, (10, 20))

        img.close()

        background = color.from_rgba(1, 0, 0, 0.5)
        img = blank(30, 40, background)
        self.assertEqual(img.size, (30, 40))
        self.assertEqual(img.get_pixel(10, 10), background)

        img.close()
Example #4
0
    def test_checkerboard(self):
        img = self.img
        img2 = img.copy().checkerboard()

        checkerboard_ = checkerboard(*img.size)

        self.assertTrue(img.is_same(img2))

        blank_ = blank(*img.size).checkerboard()

        self.assertTrue(blank_.is_same(checkerboard_))
Example #5
0
    def test_get_range(self):
        img = self.img

        range = img.get_range()  # @ReservedAssignment

        self.assertNotEqual(range[0], range[1])

        img = blank(10, 10, 'white')

        self.assertEqual(range[0], range[1])
        self.assertEqual(range[0], 1)
Example #6
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])
Example #7
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])
Example #8
0
 def thread():
     imgs = [blank(512, 512) for _ in range(randint(1, 10))]
     [i.close() for i in imgs]