Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
objects = ['the', 'quick', 'brown', 'fox', 1298, 123, 234, [], {}]
summ = summary.summarize(objects)
summary._subtract(summ, 'the')
summary._subtract(summ, {})
summary._subtract(summ, (1,))
# to verify that these rows where actually included afterwards
checked_str = checked_dict = checked_tuple = False
for row in summ:
if row[0] == summary._repr(''):
totalsize = getsizeof('quick') + getsizeof('brown') +\
getsizeof('fox')
self.assert_(row[1] == 3, "%s != %s" % (row[1], 3))
self.assert_(row[2] == totalsize, totalsize)
checked_str = True
if row[0] == summary._repr({}):
self.assert_(row[1] == 0)
self.assert_(row[2] == 0)
checked_dict = True
if row[0] == summary._repr((1,)):
self.assert_(row[1] == -1)
self.assert_(row[2] == -getsizeof((1,)))
checked_tuple = True
self.assert_(checked_str, "no str found in summary")
self.assert_(checked_dict, "no dict found in summary")
self.assert_(checked_tuple, "no tuple found in summary")
summary._subtract(summ, 'quick')
summary._subtract(summ, 'brown')
checked_str = False
for row in summ:
def test_repr(self):
"""Test that the right representation is returned. """
self.assert_(summary._repr(''), "")
self.assert_(summary._repr('', 1), "")
self.assert_(summary._repr('', verbosity=1), "")
self.assert_(summary._repr('', verbosity=100), "")
def test_repr(self):
"""Test that the right representation is returned. """
self.assert_(summary._repr(''), "")
self.assert_(summary._repr('', 1), "")
self.assert_(summary._repr('', verbosity=1), "")
self.assert_(summary._repr('', verbosity=100), "")
def setUp(self):
gc.collect()
# simplify object type representation used for summaries
# for these tests it is not necessary to work with the extended repr
def simple_repr(o, verbosity=1):
return str(type(o))
self.old_repr = summary._repr
summary._repr = simple_repr
def test_subtract(self):
"""Test that a single object's data is correctly subtracted from a summary.
- result in correct total size and total number of objects
- if object was not listed before, it should be listed negative
afterwards
"""
objects = ['the', 'quick', 'brown', 'fox', 1298, 123, 234, [], {}]
summ = summary.summarize(objects)
summary._subtract(summ, 'the')
summary._subtract(summ, {})
summary._subtract(summ, (1,))
# to verify that these rows where actually included afterwards
checked_str = checked_dict = checked_tuple = False
for row in summ:
if row[0] == summary._repr(''):
totalsize = getsizeof('quick') + getsizeof('brown') +\
getsizeof('fox')
self.assert_(row[1] == 3, "%s != %s" % (row[1], 3))
self.assert_(row[2] == totalsize, totalsize)
checked_str = True
if row[0] == summary._repr({}):
self.assert_(row[1] == 0)
self.assert_(row[2] == 0)
checked_dict = True
if row[0] == summary._repr((1,)):
self.assert_(row[1] == -1)
self.assert_(row[2] == -getsizeof((1,)))
checked_tuple = True
self.assert_(checked_str, "no str found in summary")
self.assert_(checked_dict, "no dict found in summary")
def tearDown(self):
summary._repr = self.old_repr
localrows.sort(key=lambda x: summary._repr(x[0]), reverse=True)
else:
def __init__(self, rootobject, maxdepth=3, str_func=summary._repr,
repeat=True, stream=None):
"""You have to provide the root object used in the refbrowser.
keyword arguments
maxdepth -- maximum depth of the initial tree
str_func -- function used when calling str(node)
repeat -- should nodes appear repeatedly in the tree, or should be
referred to existing nodes
stream -- output stream (used in derived classes)
"""
self.root = rootobject
self.maxdepth = maxdepth
self.str_func = str_func
self.repeat = repeat
self.stream = stream
def gui_default_str_function(o):
"""Default str function for InteractiveBrowser."""
return summary._repr(o) + '(id=%s)' % id(o)