Changeset 391 for python/trunk/Lib/test/test_repr.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_repr.py
r2 r391 9 9 import unittest 10 10 11 from test.test_support import run_unittest 11 from test.test_support import run_unittest, check_py3k_warnings 12 12 from repr import repr as r # Don't shadow builtin repr 13 13 from repr import Repr … … 23 23 24 24 def test_string(self): 25 eq = self.assertEqual s25 eq = self.assertEqual 26 26 eq(r("abc"), "'abc'") 27 27 eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'") … … 37 37 38 38 def test_tuple(self): 39 eq = self.assertEqual s39 eq = self.assertEqual 40 40 eq(r((1,)), "(1,)") 41 41 … … 52 52 from collections import deque 53 53 54 eq = self.assertEqual s54 eq = self.assertEqual 55 55 # Tuples give up after 6 elements 56 56 eq(r(()), "()") … … 102 102 103 103 def test_numbers(self): 104 eq = self.assertEqual s104 eq = self.assertEqual 105 105 eq(r(123), repr(123)) 106 106 eq(r(123L), repr(123L)) … … 112 112 113 113 def test_instance(self): 114 eq = self.assertEqual s114 eq = self.assertEqual 115 115 i1 = ClassWithRepr("a") 116 116 eq(r(i1), repr(i1)) … … 124 124 125 125 s = r(ClassWithFailingRepr) 126 self. failUnless(s.startswith("<class "))127 self. failUnless(s.endswith(">"))128 self. failUnless(s.find("...") == 8)126 self.assertTrue(s.startswith("<class ")) 127 self.assertTrue(s.endswith(">")) 128 self.assertTrue(s.find("...") == 8) 129 129 130 130 def test_file(self): 131 131 fp = open(unittest.__file__) 132 self. failUnless(repr(fp).startswith(133 "<open file '%s', mode 'r' at 0x" % unittest.__file__))132 self.assertTrue(repr(fp).startswith( 133 "<open file %r, mode 'r' at 0x" % unittest.__file__)) 134 134 fp.close() 135 self. failUnless(repr(fp).startswith(136 "<closed file '%s', mode 'r' at 0x" % unittest.__file__))135 self.assertTrue(repr(fp).startswith( 136 "<closed file %r, mode 'r' at 0x" % unittest.__file__)) 137 137 138 138 def test_lambda(self): 139 self. failUnless(repr(lambda x: x).startswith(139 self.assertTrue(repr(lambda x: x).startswith( 140 140 "<function <lambda")) 141 141 # XXX anonymous functions? see func_repr 142 142 143 143 def test_builtin_function(self): 144 eq = self.assertEqual s144 eq = self.assertEqual 145 145 # Functions 146 146 eq(repr(hash), '<built-in function hash>') 147 147 # Methods 148 self. failUnless(repr(''.split).startswith(148 self.assertTrue(repr(''.split).startswith( 149 149 '<built-in method split of str object at 0x')) 150 150 151 151 def test_xrange(self): 152 eq = self.assertEqual s152 eq = self.assertEqual 153 153 eq(repr(xrange(1)), 'xrange(1)') 154 154 eq(repr(xrange(1, 2)), 'xrange(1, 2)') … … 156 156 157 157 def test_nesting(self): 158 eq = self.assertEqual s158 eq = self.assertEqual 159 159 # everything is meant to give up after 6 levels. 160 160 eq(r([[[[[[[]]]]]]]), "[[[[[[[]]]]]]]") … … 175 175 # XXX doesn't test buffers with no b_base or read-write buffers (see 176 176 # bufferobject.c). The test is fairly incomplete too. Sigh. 177 x = buffer('foo') 178 self.failUnless(repr(x).startswith('<read-only buffer for 0x')) 177 with check_py3k_warnings(): 178 x = buffer('foo') 179 self.assertTrue(repr(x).startswith('<read-only buffer for 0x')) 179 180 180 181 def test_cell(self): … … 183 184 184 185 def test_descriptors(self): 185 eq = self.assertEqual s186 eq = self.assertEqual 186 187 # method descriptors 187 188 eq(repr(dict.items), "<method 'items' of 'dict' objects>") … … 193 194 def foo(cls): pass 194 195 x = staticmethod(C.foo) 195 self. failUnless(repr(x).startswith('<staticmethod object at 0x'))196 self.assertTrue(repr(x).startswith('<staticmethod object at 0x')) 196 197 x = classmethod(C.foo) 197 self. failUnless(repr(x).startswith('<classmethod object at 0x'))198 self.assertTrue(repr(x).startswith('<classmethod object at 0x')) 198 199 199 200 def test_unsortable(self): … … 244 245 245 246 def test_module(self): 246 eq = self.assertEqual s247 eq = self.assertEqual 247 248 touch(os.path.join(self.subpkgname, self.pkgname + os.extsep + 'py')) 248 249 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation … … 252 253 253 254 def test_type(self): 254 eq = self.assertEqual s255 eq = self.assertEqual 255 256 touch(os.path.join(self.subpkgname, 'foo'+os.extsep+'py'), '''\ 256 257 class foo(object): … … 273 274 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar 274 275 # Module name may be prefixed with "test.", depending on how run. 275 self. failUnless(repr(bar.bar).startswith(276 self.assertTrue(repr(bar.bar).startswith( 276 277 "<class %s.bar at 0x" % bar.__name__)) 277 278 … … 283 284 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz 284 285 ibaz = baz.baz() 285 self. failUnless(repr(ibaz).startswith(286 self.assertTrue(repr(ibaz).startswith( 286 287 "<%s.baz instance at 0x" % baz.__name__)) 287 288 288 289 def test_method(self): 289 eq = self.assertEqual s290 eq = self.assertEqual 290 291 touch(os.path.join(self.subpkgname, 'qux'+os.extsep+'py'), '''\ 291 292 class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: … … 298 299 # Bound method next 299 300 iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() 300 self. failUnless(repr(iqux.amethod).startswith(301 self.assertTrue(repr(iqux.amethod).startswith( 301 302 '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa instance at 0x' \ 302 303 % (qux.__name__,) )) … … 320 321 def test_main(): 321 322 run_unittest(ReprTests) 322 if os.name != 'mac': 323 run_unittest(LongReprTest) 323 run_unittest(LongReprTest) 324 324 325 325
Note:
See TracChangeset
for help on using the changeset viewer.