Esempio n. 1
0
class TestImage(unittest.TestCase):
    def setUp(self):
        self.osr = ImageSlide(file_path('boxes.png'))

    def tearDown(self):
        self.osr.close()

    def test_repr(self):
        self.assertEqual(repr(self.osr),
                         'ImageSlide(%r)' % file_path('boxes.png'))

    def test_metadata(self):
        self.assertEqual(self.osr.level_count, 1)
        self.assertEqual(self.osr.level_dimensions, ((300, 250), ))
        self.assertEqual(self.osr.dimensions, (300, 250))
        self.assertEqual(self.osr.level_downsamples, (1.0, ))

        self.assertEqual(self.osr.get_best_level_for_downsample(0.5), 0)
        self.assertEqual(self.osr.get_best_level_for_downsample(3), 0)

        self.assertEqual(self.osr.properties, {})
        self.assertEqual(self.osr.associated_images, {})

    def test_read_region(self):
        self.assertEqual(
            self.osr.read_region((-10, -10), 0, (400, 400)).size, (400, 400))

    def test_read_region_size_dimension_zero(self):
        self.assertEqual(
            self.osr.read_region((0, 0), 0, (400, 0)).size, (400, 0))

    def test_read_region_bad_level(self):
        self.assertRaises(OpenSlideError, lambda: self.osr.read_region(
            (0, 0), 1, (100, 100)))

    def test_read_region_bad_size(self):
        self.assertRaises(OpenSlideError, lambda: self.osr.read_region(
            (0, 0), 0, (400, -5)))

    def test_thumbnail(self):
        self.assertEqual(self.osr.get_thumbnail((100, 100)).size, (100, 83))

    @maybe_supported
    def test_set_cache(self):
        self.osr.set_cache(OpenSlideCache(64 << 10))
        self.assertEqual(
            self.osr.read_region((0, 0), 0, (400, 400)).size, (400, 400))
 def test_operations_on_closed_handle(self):
     with image_open(file_path("boxes.png")) as img:
         osr = ImageSlide(img)
         osr.close()
         self.assertRaises(AttributeError, lambda: osr.read_region((0, 0), 0, (100, 100)))
         # If an Image is passed to the constructor, ImageSlide.close()
         # shouldn't close it
         self.assertEqual(img.getpixel((0, 0)), 3)
Esempio n. 3
0
 def test_operations_on_closed_handle(self):
     with image_open(file_path('boxes.png')) as img:
         osr = ImageSlide(img)
         osr.close()
         self.assertRaises(AttributeError, lambda: osr.read_region(
             (0, 0), 0, (100, 100)))
         # If an Image is passed to the constructor, ImageSlide.close()
         # shouldn't close it
         self.assertEqual(img.getpixel((0, 0)), 3)
class TestImage(unittest.TestCase):
    def setUp(self):
        self.osr = ImageSlide(file_path('boxes.png'))

    def tearDown(self):
        self.osr.close()

    def test_repr(self):
        self.assertEqual(repr(self.osr),
                'ImageSlide(%r)' % file_path('boxes.png'))

    def test_metadata(self):
        self.assertEqual(self.osr.level_count, 1)
        self.assertEqual(self.osr.level_dimensions, ((300, 250),))
        self.assertEqual(self.osr.dimensions, (300, 250))
        self.assertEqual(self.osr.level_downsamples, (1.0,))

        self.assertEqual(self.osr.get_best_level_for_downsample(0.5), 0)
        self.assertEqual(self.osr.get_best_level_for_downsample(3), 0)

        self.assertEqual(self.osr.properties, {})
        self.assertEqual(self.osr.associated_images, {})

    def test_read_region(self):
        self.assertEqual(self.osr.read_region((-10, -10), 0, (400, 400)).size,
                (400, 400))

    @skip_if(image_dimensions_cannot_be_zero, 'Pillow issue #2259')
    def test_read_region_size_dimension_zero(self):
        self.assertEqual(self.osr.read_region((0, 0), 0, (400, 0)).size,
                (400, 0))

    def test_read_region_bad_level(self):
        self.assertRaises(OpenSlideError,
                lambda: self.osr.read_region((0, 0), 1, (100, 100)))

    def test_read_region_bad_size(self):
        self.assertRaises(OpenSlideError,
                lambda: self.osr.read_region((0, 0), 0, (400, -5)))

    def test_thumbnail(self):
        self.assertEqual(self.osr.get_thumbnail((100, 100)).size, (100, 83))
Esempio n. 5
0
 def test_context_manager(self):
     osr = ImageSlide(file_path('boxes.png'))
     with osr:
         pass
     self.assertRaises(AttributeError, lambda: osr.read_region((0, 0), 0,
                                                               (100, 100)))
 def test_context_manager(self):
     osr = ImageSlide(file_path("boxes.png"))
     with osr:
         pass
     self.assertRaises(AttributeError, lambda: osr.read_region((0, 0), 0, (100, 100)))