mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
Make utils.python.collect_extra_debug_data support objects with __slots__.
This commit is contained in:
parent
0f82f89eec
commit
969b9ed341
@ -159,10 +159,12 @@ def collect_extra_debug_data():
|
||||
frame_locals = frame.f_locals
|
||||
for inspected in ('self', 'cls'):
|
||||
if inspected in frame_locals:
|
||||
if hasattr(frame_locals[inspected], '__dict__') and \
|
||||
frame_locals[inspected].__dict__:
|
||||
for (key, value) in frame_locals[inspected].__dict__.items():
|
||||
frame_locals['%s.%s' % (inspected, key)] = value
|
||||
for attr_name in dir(frame_locals[inspected]):
|
||||
try:
|
||||
v = getattr(frame_locals[inspected], attr_name)
|
||||
except Exception:
|
||||
v = '<ERROR WHILE GETTING VALUE>'
|
||||
frame_locals['%s.%s' % (inspected, attr_name)] = v
|
||||
for key, value in frame_locals.items():
|
||||
if key == '__builtins__':
|
||||
# This is flooding
|
||||
@ -173,7 +175,7 @@ def collect_extra_debug_data():
|
||||
#error we don't want.
|
||||
try:
|
||||
data += repr(value) + '\n'
|
||||
except:
|
||||
except Exception:
|
||||
data += '<ERROR WHILE PRINTING VALUE>\n'
|
||||
data += '\n'
|
||||
data += '+-----------------------+\n'
|
||||
|
@ -1175,6 +1175,45 @@ class TestTruncatableSet(SupyTestCase):
|
||||
s.truncate(3)
|
||||
self.assertEqual(s, set(['foo', 'baz', 'qux']))
|
||||
|
||||
class UtilsPythonTest(SupyTestCase):
|
||||
def test_dict(self):
|
||||
class Foo:
|
||||
def __hasattr__(self, n):
|
||||
raise Exception()
|
||||
def __getattr__(self, n):
|
||||
raise Exception()
|
||||
|
||||
def f():
|
||||
self = Foo()
|
||||
self.bar = 'baz'
|
||||
raise Exception('f')
|
||||
|
||||
try:
|
||||
f()
|
||||
except:
|
||||
res = utils.python.collect_extra_debug_data()
|
||||
|
||||
self.assertTrue(re.search('self.bar.*=.*baz', res), res)
|
||||
|
||||
def test_slots(self):
|
||||
class Foo:
|
||||
__slots__ = ('bar',)
|
||||
def __hasattr__(self, n):
|
||||
raise Exception()
|
||||
def __getattr__(self, n):
|
||||
raise Exception(n)
|
||||
|
||||
def f():
|
||||
self = Foo()
|
||||
self.bar = 'baz'
|
||||
raise Exception('f')
|
||||
|
||||
try:
|
||||
f()
|
||||
except:
|
||||
res = utils.python.collect_extra_debug_data()
|
||||
|
||||
self.assertTrue(re.search('self.bar.*=.*baz', res), res)
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user