from sizer import scanner, formatting, operations, annotate def test_tutorial(): # Test some of the things in the tutorial global foo, objs foo = {} for i in range(1000): foo[i] = range(100) from sizer import scanner objs = scanner.Objects() def test_lookup(): global w formatting.printsizes(objs, count = 10) print print objs print w = objs[id(foo)] print w.size, w.type, w.children, w.keys, w.values print def test_parents(): annotate.markparents(objs) assert len(w.parents) == 1 assert isinstance(w.parents[0].obj, dict) def test_filter(): global nostr nostr = operations.fix(operations.filterouttype(objs, str)) print "*** Without strings" formatting.printsizes(nostr, count = 10) print print nostr print assert len([s for s in nostr if isinstance(nostr[s].obj, str)]) == 0 assert len(nostr) + len([s for s in objs if isinstance(objs[s].obj, str)]) == len(objs) def test_bytype(): print "*** Look for lists at the top" formatting.printsizesop(operations.bytype(objs), threshold = 1000) print lists = operations.filtertype(objs, list) print "*** Look for 420-byte lists at the top" formatting.printsizesop(operations.bysize(lists)) print def test_diff(): assert len(nostr) + len(operations.diff(nostr, objs)) == len(objs) print "*** Only strings, using operations.diff()" print operations.diff(nostr, objs) print # Can't be bothered with the rest yet...