Back to index

python3.2  3.2.2
Public Member Functions
test.test_reprlib.ReprTests Class Reference

List of all members.

Public Member Functions

def test_string
def test_tuple
def test_container
def test_numbers
def test_instance
def test_lambda
def test_builtin_function
def test_range
def test_nesting
def test_cell
def test_descriptors
def test_unsortable

Detailed Description

Definition at line 23 of file test_reprlib.py.


Member Function Documentation

Definition at line 136 of file test_reprlib.py.

00136 
00137     def test_builtin_function(self):
00138         eq = self.assertEqual
00139         # Functions
00140         eq(repr(hash), '<built-in function hash>')
00141         # Methods
00142         self.assertTrue(repr(''.split).startswith(
00143             '<built-in method split of str object at 0x'))

Here is the call graph for this function:

Definition at line 167 of file test_reprlib.py.

00167 
00168     def test_cell(self):
00169         # XXX Hmm? How to get at a cell object?
00170         pass

Definition at line 51 of file test_reprlib.py.

00051 
00052     def test_container(self):
00053         from array import array
00054         from collections import deque
00055 
00056         eq = self.assertEqual
00057         # Tuples give up after 6 elements
00058         eq(r(()), "()")
00059         eq(r((1,)), "(1,)")
00060         eq(r((1, 2, 3)), "(1, 2, 3)")
00061         eq(r((1, 2, 3, 4, 5, 6)), "(1, 2, 3, 4, 5, 6)")
00062         eq(r((1, 2, 3, 4, 5, 6, 7)), "(1, 2, 3, 4, 5, 6, ...)")
00063 
00064         # Lists give up after 6 as well
00065         eq(r([]), "[]")
00066         eq(r([1]), "[1]")
00067         eq(r([1, 2, 3]), "[1, 2, 3]")
00068         eq(r([1, 2, 3, 4, 5, 6]), "[1, 2, 3, 4, 5, 6]")
00069         eq(r([1, 2, 3, 4, 5, 6, 7]), "[1, 2, 3, 4, 5, 6, ...]")
00070 
00071         # Sets give up after 6 as well
00072         eq(r(set([])), "set([])")
00073         eq(r(set([1])), "set([1])")
00074         eq(r(set([1, 2, 3])), "set([1, 2, 3])")
00075         eq(r(set([1, 2, 3, 4, 5, 6])), "set([1, 2, 3, 4, 5, 6])")
00076         eq(r(set([1, 2, 3, 4, 5, 6, 7])), "set([1, 2, 3, 4, 5, 6, ...])")
00077 
00078         # Frozensets give up after 6 as well
00079         eq(r(frozenset([])), "frozenset([])")
00080         eq(r(frozenset([1])), "frozenset([1])")
00081         eq(r(frozenset([1, 2, 3])), "frozenset([1, 2, 3])")
00082         eq(r(frozenset([1, 2, 3, 4, 5, 6])), "frozenset([1, 2, 3, 4, 5, 6])")
00083         eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "frozenset([1, 2, 3, 4, 5, 6, ...])")
00084 
00085         # collections.deque after 6
00086         eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])")
00087 
00088         # Dictionaries give up after 4.
00089         eq(r({}), "{}")
00090         d = {'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}
00091         eq(r(d), "{'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}")
00092         d['arthur'] = 1
00093         eq(r(d), "{'alice': 1, 'arthur': 1, 'bob': 2, 'charles': 3, ...}")
00094 
00095         # array.array after 5.
00096         eq(r(array('i')), "array('i', [])")
00097         eq(r(array('i', [1])), "array('i', [1])")
00098         eq(r(array('i', [1, 2])), "array('i', [1, 2])")
00099         eq(r(array('i', [1, 2, 3])), "array('i', [1, 2, 3])")
00100         eq(r(array('i', [1, 2, 3, 4])), "array('i', [1, 2, 3, 4])")
00101         eq(r(array('i', [1, 2, 3, 4, 5])), "array('i', [1, 2, 3, 4, 5])")
00102         eq(r(array('i', [1, 2, 3, 4, 5, 6])),
00103                    "array('i', [1, 2, 3, 4, 5, ...])")

Here is the call graph for this function:

Definition at line 171 of file test_reprlib.py.

00171 
00172     def test_descriptors(self):
00173         eq = self.assertEqual
00174         # method descriptors
00175         eq(repr(dict.items), "<method 'items' of 'dict' objects>")
00176         # XXX member descriptors
00177         # XXX attribute descriptors
00178         # XXX slot descriptors
00179         # static and class methods
00180         class C:
00181             def foo(cls): pass
00182         x = staticmethod(C.foo)
00183         self.assertTrue(repr(x).startswith('<staticmethod object at 0x'))
00184         x = classmethod(C.foo)
00185         self.assertTrue(repr(x).startswith('<classmethod object at 0x'))

Here is the call graph for this function:

Definition at line 114 of file test_reprlib.py.

00114 
00115     def test_instance(self):
00116         eq = self.assertEqual
00117         i1 = ClassWithRepr("a")
00118         eq(r(i1), repr(i1))
00119 
00120         i2 = ClassWithRepr("x"*1000)
00121         expected = repr(i2)[:13] + "..." + repr(i2)[-14:]
00122         eq(r(i2), expected)
00123 
00124         i3 = ClassWithFailingRepr()
00125         eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%id(i3)))
00126 
00127         s = r(ClassWithFailingRepr)
00128         self.assertTrue(s.startswith("<class "))
00129         self.assertTrue(s.endswith(">"))
00130         self.assertIn(s.find("..."), [12, 13])

Here is the call graph for this function:

Definition at line 131 of file test_reprlib.py.

00131 
00132     def test_lambda(self):
00133         self.assertTrue(repr(lambda x: x).startswith(
00134             "<function <lambda"))
00135         # XXX anonymous functions?  see func_repr

Here is the call graph for this function:

Definition at line 150 of file test_reprlib.py.

00150 
00151     def test_nesting(self):
00152         eq = self.assertEqual
00153         # everything is meant to give up after 6 levels.
00154         eq(r([[[[[[[]]]]]]]), "[[[[[[[]]]]]]]")
00155         eq(r([[[[[[[[]]]]]]]]), "[[[[[[[...]]]]]]]")
00156 
00157         eq(r(nestedTuple(6)), "(((((((),),),),),),)")
00158         eq(r(nestedTuple(7)), "(((((((...),),),),),),)")
00159 
00160         eq(r({ nestedTuple(5) : nestedTuple(5) }),
00161            "{((((((),),),),),): ((((((),),),),),)}")
00162         eq(r({ nestedTuple(6) : nestedTuple(6) }),
00163            "{((((((...),),),),),): ((((((...),),),),),)}")
00164 
00165         eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
00166         eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")

Here is the call graph for this function:

Definition at line 104 of file test_reprlib.py.

00104 
00105     def test_numbers(self):
00106         eq = self.assertEqual
00107         eq(r(123), repr(123))
00108         eq(r(123), repr(123))
00109         eq(r(1.0/3), repr(1.0/3))
00110 
00111         n = 10**100
00112         expected = repr(n)[:18] + "..." + repr(n)[-19:]
00113         eq(r(n), expected)

Here is the call graph for this function:

Definition at line 144 of file test_reprlib.py.

00144 
00145     def test_range(self):
00146         eq = self.assertEqual
00147         eq(repr(range(1)), 'range(0, 1)')
00148         eq(repr(range(1, 2)), 'range(1, 2)')
00149         eq(repr(range(1, 4, 3)), 'range(1, 4, 3)')

Here is the call graph for this function:

Definition at line 25 of file test_reprlib.py.

00025 
00026     def test_string(self):
00027         eq = self.assertEqual
00028         eq(r("abc"), "'abc'")
00029         eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'")
00030 
00031         s = "a"*30+"b"*30
00032         expected = repr(s)[:13] + "..." + repr(s)[-14:]
00033         eq(r(s), expected)
00034 
00035         eq(r("\"'"), repr("\"'"))
00036         s = "\""*30+"'"*100
00037         expected = repr(s)[:13] + "..." + repr(s)[-14:]
00038         eq(r(s), expected)

Here is the call graph for this function:

Definition at line 39 of file test_reprlib.py.

00039 
00040     def test_tuple(self):
00041         eq = self.assertEqual
00042         eq(r((1,)), "(1,)")
00043 
00044         t3 = (1, 2, 3)
00045         eq(r(t3), "(1, 2, 3)")
00046 
00047         r2 = Repr()
00048         r2.maxtuple = 2
00049         expected = repr(t3)[:-2] + "...)"
00050         eq(r2.repr(t3), expected)

Here is the call graph for this function:

Definition at line 186 of file test_reprlib.py.

00186 
00187     def test_unsortable(self):
00188         # Repr.repr() used to call sorted() on sets, frozensets and dicts
00189         # without taking into account that not all objects are comparable
00190         x = set([1j, 2j, 3j])
00191         y = frozenset(x)
00192         z = {1j: 1, 2j: 2}
00193         r(x)
00194         r(y)
00195         r(z)

Here is the call graph for this function:


The documentation for this class was generated from the following file: