10a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport pprint 20a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport test.test_support 30a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest 40a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport test.test_set 50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 60a8c90248264a8b26970b4473770bcc3df8515fJosh Gaotry: 70a8c90248264a8b26970b4473770bcc3df8515fJosh Gao uni = unicode 80a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoexcept NameError: 90a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def uni(x): 100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return x 110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# list, tuple and dict subclasses that do or don't overwrite __repr__ 130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass list2(list): 140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 160a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass list3(list): 170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def __repr__(self): 180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return list.__repr__(self) 190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 200a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass tuple2(tuple): 210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 230a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass tuple3(tuple): 240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def __repr__(self): 250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return tuple.__repr__(self) 260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 270a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass dict2(dict): 280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 300a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass dict3(dict): 310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def __repr__(self): 320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return dict.__repr__(self) 330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 340a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass QueryTestCase(unittest.TestCase): 350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def setUp(self): 370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.a = range(100) 380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.b = range(200) 390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.a[-12] = self.b 400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_basic(self): 420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Verify .isrecursive() and .isreadable() w/o recursion 430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pp = pprint.PrettyPrinter() 440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, uni("yaddayadda"), 450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.a, self.b): 460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # module-level convenience functions 470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pprint.isrecursive(safe), 480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isrecursive for %r" % (safe,)) 490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(pprint.isreadable(safe), 500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected isreadable for %r" % (safe,)) 510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # PrettyPrinter methods 520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pp.isrecursive(safe), 530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isrecursive for %r" % (safe,)) 540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(pp.isreadable(safe), 550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected isreadable for %r" % (safe,)) 560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_knotted(self): 580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Verify .isrecursive() and .isreadable() w/ recursion 590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Tie a knot. 600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.b[67] = self.a 610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Messy dict. 620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.d = {} 630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.d[0] = self.d[1] = self.d[2] = self.d 640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pp = pprint.PrettyPrinter() 660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for icky in self.a, self.b, self.d, (self.d, self.d): 680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(pprint.isrecursive(icky), "expected isrecursive") 690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pprint.isreadable(icky), "expected not isreadable") 700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(pp.isrecursive(icky), "expected isrecursive") 710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pp.isreadable(icky), "expected not isreadable") 720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Break the cycles. 740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.d.clear() 750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao del self.a[:] 760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao del self.b[:] 770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for safe in self.a, self.b, self.d, (self.d, self.d): 790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # module-level convenience functions 800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pprint.isrecursive(safe), 810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isrecursive for %r" % (safe,)) 820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(pprint.isreadable(safe), 830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected isreadable for %r" % (safe,)) 840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # PrettyPrinter methods 850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pp.isrecursive(safe), 860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isrecursive for %r" % (safe,)) 870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(pp.isreadable(safe), 880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected isreadable for %r" % (safe,)) 890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_unreadable(self): 910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Not recursive but not readable anyway 920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pp = pprint.PrettyPrinter() 930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for unreadable in type(3), pprint, pprint.isrecursive: 940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # module-level convenience functions 950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pprint.isrecursive(unreadable), 960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isrecursive for %r" % (unreadable,)) 970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pprint.isreadable(unreadable), 980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isreadable for %r" % (unreadable,)) 990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # PrettyPrinter methods 1000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pp.isrecursive(unreadable), 1010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isrecursive for %r" % (unreadable,)) 1020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(pp.isreadable(unreadable), 1030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected not isreadable for %r" % (unreadable,)) 1040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_same_as_repr(self): 1060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Simple objects, small containers and classes that overwrite __repr__ 1070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # For those the result should be the same as repr(). 1080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Ahem. The docs don't say anything about that -- this appears to 1090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # be testing an implementation quirk. Starting in Python 2.5, it's 1100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # not true for dicts: pprint always sorts dicts by key now; before, 1110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # it sorted a dict display if and only if the display required 1120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # multiple lines. For that reason, dicts with more than one element 1130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # aren't tested here. 1140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for simple in (0, 0L, 0+0j, 0.0, "", uni(""), 1150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao (), tuple2(), tuple3(), 1160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao [], list2(), list3(), 1170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}, dict2(), dict3(), 1180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue, pprint, 1190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao -6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6}, 1200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao (1,2), [3,4], {5: 6}, 1210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao tuple2((1,2)), tuple3((1,2)), tuple3(range(100)), 1220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao [3,4], list2([3,4]), list3([3,4]), list3(range(100)), 1230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao dict2({5: 6}), dict3({5: 6}), 1240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao range(10, -11, -1) 1250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ): 1260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao native = repr(simple) 1270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for function in "pformat", "saferepr": 1280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao f = getattr(pprint, function) 1290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao got = f(simple) 1300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(native, got, 1310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "expected %s got %s from pprint.%s" % 1320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao (native, got, function)) 1330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_basic_line_wrap(self): 1350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # verify basic line-wrapping operation 1360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o = {'RPM_cal': 0, 1370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'RPM_cal2': 48059, 1380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'Speed_cal': 0, 1390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'controldesk_runtime_us': 0, 1400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'main_code_runtime_us': 0, 1410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'read_io_runtime_us': 0, 1420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'write_io_runtime_us': 43690} 1430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao exp = """\ 1440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{'RPM_cal': 0, 1450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'RPM_cal2': 48059, 1460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'Speed_cal': 0, 1470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'controldesk_runtime_us': 0, 1480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'main_code_runtime_us': 0, 1490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'read_io_runtime_us': 0, 1500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'write_io_runtime_us': 43690}""" 1510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for type in [dict, dict2]: 1520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(type(o)), exp) 1530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o = range(100) 1550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao exp = '[%s]' % ',\n '.join(map(str, o)) 1560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for type in [list, list2]: 1570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(type(o)), exp) 1580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o = tuple(range(100)) 1600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao exp = '(%s)' % ',\n '.join(map(str, o)) 1610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for type in [tuple, tuple2]: 1620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(type(o)), exp) 1630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # indent parameter 1650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o = range(100) 1660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao exp = '[ %s]' % ',\n '.join(map(str, o)) 1670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for type in [list, list2]: 1680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(type(o), indent=4), exp) 1690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_nested_indentations(self): 1710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o1 = list(range(10)) 1720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o2 = dict(first=1, second=2, third=3) 1730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o = [o1, o2] 1740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao expected = """\ 1750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao[ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao { 'first': 1, 1770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'second': 2, 1780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'third': 3}]""" 1790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(o, indent=4, width=42), expected) 1800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_sorted_dict(self): 1820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Starting in Python 2.5, pprint sorts dict displays by key regardless 1830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # of how small the dictionary may be. 1840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Before the change, on 32-bit Windows pformat() gave order 1850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # 'a', 'c', 'b' here, so this test failed. 1860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao d = {'a': 1, 'b': 1, 'c': 1} 1870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(d), "{'a': 1, 'b': 1, 'c': 1}") 1880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat([d, d]), 1890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao "[{'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 1}]") 1900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # The next one is kind of goofy. The sorted order depends on the 1920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # alphabetic order of type names: "int" < "str" < "tuple". Before 1930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Python 2.5, this was in the test_same_as_repr() test. It's worth 1940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # keeping around for now because it's one of few tests of pprint 1950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # against a crazy mix of types. 1960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat({"xy\tab\n": (3,), 5: [[]], (): {}}), 1970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao r"{5: [[]], 'xy\tab\n': (3,), (): {}}") 1980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_subclassing(self): 2000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao o = {'names with spaces': 'should be presented using repr()', 2010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'others.should.not.be': 'like.this'} 2020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao exp = """\ 2030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{'names with spaces': 'should be presented using repr()', 2040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao others.should.not.be: like.this}""" 2050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(DottedPrettyPrinter().pformat(o), exp) 2060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_set_reprs(self): 2080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(set()), 'set()') 2090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(set(range(3))), 'set([0, 1, 2])') 2100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(frozenset()), 'frozenset()') 2110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(frozenset(range(3))), 'frozenset([0, 1, 2])') 2120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cube_repr_tgt = """\ 2130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{frozenset([]): frozenset([frozenset([2]), frozenset([0]), frozenset([1])]), 2140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0]): frozenset([frozenset(), 2150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2]), 2160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1])]), 2170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1]): frozenset([frozenset(), 2180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 2]), 2190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1])]), 2200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([2]): frozenset([frozenset(), 2210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 2]), 2220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2])]), 2230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 2]): frozenset([frozenset([2]), 2240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1]), 2250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1, 2])]), 2260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2]): frozenset([frozenset([2]), 2270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0]), 2280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1, 2])]), 2290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1]): frozenset([frozenset([0]), 2300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1]), 2310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1, 2])]), 2320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1, 2]): frozenset([frozenset([1, 2]), 2330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2]), 2340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 1])])}""" 2350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cube = test.test_set.cube(3) 2360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(cube), cube_repr_tgt) 2370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cubo_repr_tgt = """\ 2380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{frozenset([frozenset([0, 2]), frozenset([0])]): frozenset([frozenset([frozenset([0, 2390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 2400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 2420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), 2440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])]), 2460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 2470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0])]), 2480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), 2490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])])]), 2510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0, 1]), frozenset([1])]): frozenset([frozenset([frozenset([0, 2520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1]), 2530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 2550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), 2570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])]), 2590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 2600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 2610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 2630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1])])]), 2640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1, 2]), frozenset([1])]): frozenset([frozenset([frozenset([1, 2650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 2660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 2680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), 2700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 2710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 2730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1])]), 2740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 2750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])])]), 2770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1, 2]), frozenset([2])]): frozenset([frozenset([frozenset([1, 2780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 2790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 2810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 2830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 2840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), 2860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 2890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([2])])]), 2900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([]), frozenset([0])]): frozenset([frozenset([frozenset([0]), 2910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])]), 2930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), 2940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 2950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 2960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 2970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1])]), 2980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 2990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([2])])]), 3000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([]), frozenset([1])]): frozenset([frozenset([frozenset(), 3010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0])]), 3020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 3030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 3040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 3060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([2])]), 3070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 3080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])])]), 3100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), frozenset([])]): frozenset([frozenset([frozenset([2]), 3110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 3120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 3140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0])]), 3150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 3160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1])]), 3170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), 3180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])])]), 3200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0, 1, 2]), frozenset([0, 1])]): frozenset([frozenset([frozenset([1, 3210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 3220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0, 3260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 3270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), 3310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])]), 3330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 3340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])])]), 3360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), frozenset([0, 1])]): frozenset([frozenset([frozenset(), 3370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0])]), 3380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0, 3390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1]), 3400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), 3440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 3470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1])])]), 3490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), frozenset([0, 2])]): frozenset([frozenset([frozenset([0, 3500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 3510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), 3550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 3560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), 3580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset(), 3610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([2])])]), 3620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0, 1, 2]), frozenset([0, 2])]): frozenset([frozenset([frozenset([1, 3630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 3640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0, 3680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1]), 3690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0]), 3730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), 3760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])])]), 3780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1, 2]), frozenset([0, 1, 2])]): frozenset([frozenset([frozenset([0, 3790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2]), 3800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([0, 3840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1]), 3850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([0, 3860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1, 3870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([2]), 3890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 3900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])]), 3910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([frozenset([1]), 3920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao frozenset([1, 3930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2])])])}""" 3940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cubo = test.test_set.linegraph(cube) 3960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(cubo), cubo_repr_tgt) 3970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_depth(self): 3990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao nested_tuple = (1, (2, (3, (4, (5, 6))))) 4000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao nested_dict = {1: {2: {3: {4: {5: {6: 6}}}}}} 4010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao nested_list = [1, [2, [3, [4, [5, [6, []]]]]]] 4020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(nested_tuple), repr(nested_tuple)) 4030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(nested_dict), repr(nested_dict)) 4040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(nested_list), repr(nested_list)) 4050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lv1_tuple = '(1, (...))' 4070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lv1_dict = '{1: {...}}' 4080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lv1_list = '[1, [...]]' 4090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(nested_tuple, depth=1), lv1_tuple) 4100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(nested_dict, depth=1), lv1_dict) 4110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(pprint.pformat(nested_list, depth=1), lv1_list) 4120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4140a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DottedPrettyPrinter(pprint.PrettyPrinter): 4150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def format(self, object, context, maxlevels, level): 4170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if isinstance(object, str): 4180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if ' ' in object: 4190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return repr(object), 1, 0 4200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 4210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return object, 0, 0 4220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 4230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return pprint.PrettyPrinter.format( 4240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self, object, context, maxlevels, level) 4250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4270a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_main(): 4280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test.test_support.run_unittest(QueryTestCase) 4290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4310a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == "__main__": 4320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_main() 433