Skip to content

Commit

Permalink
Fix misleading reprs for property and associated image maps
Browse files Browse the repository at this point in the history
  • Loading branch information
bgilbert committed Jun 5, 2016
1 parent 62eb664 commit 6263375
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openslide/__init__.py
Expand Up @@ -228,7 +228,7 @@ def __init__(self, osr):
self._osr = osr

def __repr__(self):
return repr(dict(self))
return '<%s %r>' % (self.__class__.__name__, dict(self))

def __len__(self):
return len(self._keys())
Expand Down
8 changes: 8 additions & 0 deletions tests/test_openslide.py
Expand Up @@ -20,6 +20,7 @@
from ctypes import ArgumentError
from openslide import (OpenSlide, OpenSlideError,
OpenSlideUnsupportedFormatError)
import re
import unittest

from . import file_path
Expand Down Expand Up @@ -100,6 +101,8 @@ def test_properties(self):
# test __len__ and __iter__
self.assertEqual(len([v for v in self.osr.properties]),
len(self.osr.properties))
self.assertEqual(repr(self.osr.properties),
'<_PropertyMap %r>' % dict(self.osr.properties))

def test_read_region(self):
self.assertEqual(self.osr.read_region((-10, -10), 1, (400, 400)).size,
Expand Down Expand Up @@ -132,6 +135,11 @@ def test_associated_images(self):
# test __len__ and __iter__
self.assertEqual(len([v for v in self.osr.associated_images]),
len(self.osr.associated_images))
def mangle_repr(o):
return re.sub('0x[0-9a-fA-F]+', '(mangled)', repr(o))
self.assertEqual(mangle_repr(self.osr.associated_images),
'<_AssociatedImageMap %s>' % mangle_repr(
dict(self.osr.associated_images)))


class TestUnreadableSlide(_SlideTest, unittest.TestCase):
Expand Down

0 comments on commit 6263375

Please sign in to comment.