Skip to content

Commit 6263375

Browse files
committed
Fix misleading reprs for property and associated image maps
1 parent 62eb664 commit 6263375

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

openslide/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def __init__(self, osr):
228228
self._osr = osr
229229

230230
def __repr__(self):
231-
return repr(dict(self))
231+
return '<%s %r>' % (self.__class__.__name__, dict(self))
232232

233233
def __len__(self):
234234
return len(self._keys())

tests/test_openslide.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ctypes import ArgumentError
2121
from openslide import (OpenSlide, OpenSlideError,
2222
OpenSlideUnsupportedFormatError)
23+
import re
2324
import unittest
2425

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

104107
def test_read_region(self):
105108
self.assertEqual(self.osr.read_region((-10, -10), 1, (400, 400)).size,
@@ -132,6 +135,11 @@ def test_associated_images(self):
132135
# test __len__ and __iter__
133136
self.assertEqual(len([v for v in self.osr.associated_images]),
134137
len(self.osr.associated_images))
138+
def mangle_repr(o):
139+
return re.sub('0x[0-9a-fA-F]+', '(mangled)', repr(o))
140+
self.assertEqual(mangle_repr(self.osr.associated_images),
141+
'<_AssociatedImageMap %s>' % mangle_repr(
142+
dict(self.osr.associated_images)))
135143

136144

137145
class TestUnreadableSlide(_SlideTest, unittest.TestCase):

0 commit comments

Comments
 (0)