Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: Lib/test/test_reprlib.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_raise.py ('k') | Lib/test/test_robotparser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """ 1 """
2 Test cases for the repr module 2 Test cases for the repr module
3 Nick Mathewson 3 Nick Mathewson
4 """ 4 """
5 5
6 import sys 6 import sys
7 import os 7 import os
8 import shutil 8 import shutil
9 import unittest 9 import unittest
10 10
11 from test.support import run_unittest, create_empty_file 11 from test.support import run_unittest
12 from reprlib import repr as r # Don't shadow builtin repr 12 from reprlib import repr as r # Don't shadow builtin repr
13 from reprlib import Repr 13 from reprlib import Repr
14 from reprlib import recursive_repr 14 from reprlib import recursive_repr
15 15
16 16
17 def nestedTuple(nesting): 17 def nestedTuple(nesting):
18 t = () 18 t = ()
19 for i in range(nesting): 19 for i in range(nesting):
20 t = (t,) 20 t = (t,)
21 return t 21 return t
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 def test_unsortable(self): 186 def test_unsortable(self):
187 # Repr.repr() used to call sorted() on sets, frozensets and dicts 187 # Repr.repr() used to call sorted() on sets, frozensets and dicts
188 # without taking into account that not all objects are comparable 188 # without taking into account that not all objects are comparable
189 x = set([1j, 2j, 3j]) 189 x = set([1j, 2j, 3j])
190 y = frozenset(x) 190 y = frozenset(x)
191 z = {1j: 1, 2j: 2} 191 z = {1j: 1, 2j: 2}
192 r(x) 192 r(x)
193 r(y) 193 r(y)
194 r(z) 194 r(z)
195 195
196 def write_file(path, text): 196 def touch(path, text=''):
197 with open(path, 'w', encoding='ASCII') as fp: 197 fp = open(path, 'w')
198 fp.write(text) 198 fp.write(text)
199 fp.close()
199 200
200 class LongReprTest(unittest.TestCase): 201 class LongReprTest(unittest.TestCase):
201 def setUp(self): 202 def setUp(self):
202 longname = 'areallylongpackageandmodulenametotestreprtruncation' 203 longname = 'areallylongpackageandmodulenametotestreprtruncation'
203 self.pkgname = os.path.join(longname) 204 self.pkgname = os.path.join(longname)
204 self.subpkgname = os.path.join(longname, longname) 205 self.subpkgname = os.path.join(longname, longname)
205 # Make the package and subpackage 206 # Make the package and subpackage
206 shutil.rmtree(self.pkgname, ignore_errors=True) 207 shutil.rmtree(self.pkgname, ignore_errors=True)
207 os.mkdir(self.pkgname) 208 os.mkdir(self.pkgname)
208 create_empty_file(os.path.join(self.pkgname, '__init__.py')) 209 touch(os.path.join(self.pkgname, '__init__.py'))
209 shutil.rmtree(self.subpkgname, ignore_errors=True) 210 shutil.rmtree(self.subpkgname, ignore_errors=True)
210 os.mkdir(self.subpkgname) 211 os.mkdir(self.subpkgname)
211 create_empty_file(os.path.join(self.subpkgname, '__init__.py')) 212 touch(os.path.join(self.subpkgname, '__init__.py'))
212 # Remember where we are 213 # Remember where we are
213 self.here = os.getcwd() 214 self.here = os.getcwd()
214 sys.path.insert(0, self.here) 215 sys.path.insert(0, self.here)
215 216
216 def tearDown(self): 217 def tearDown(self):
217 actions = [] 218 actions = []
218 for dirpath, dirnames, filenames in os.walk(self.pkgname): 219 for dirpath, dirnames, filenames in os.walk(self.pkgname):
219 for name in dirnames + filenames: 220 for name in dirnames + filenames:
220 actions.append(os.path.join(dirpath, name)) 221 actions.append(os.path.join(dirpath, name))
221 actions.append(self.pkgname) 222 actions.append(self.pkgname)
222 actions.sort() 223 actions.sort()
223 actions.reverse() 224 actions.reverse()
224 for p in actions: 225 for p in actions:
225 if os.path.isdir(p): 226 if os.path.isdir(p):
226 os.rmdir(p) 227 os.rmdir(p)
227 else: 228 else:
228 os.remove(p) 229 os.remove(p)
229 del sys.path[0] 230 del sys.path[0]
230 231
231 def test_module(self): 232 def test_module(self):
232 eq = self.assertEqual 233 eq = self.assertEqual
233 create_empty_file(os.path.join(self.subpkgname, self.pkgname + '.py')) 234 touch(os.path.join(self.subpkgname, self.pkgname + '.py'))
234 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotes treprtruncation 235 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotes treprtruncation
235 eq(repr(areallylongpackageandmodulenametotestreprtruncation), 236 eq(repr(areallylongpackageandmodulenametotestreprtruncation),
236 "<module %r from %r>" % (areallylongpackageandmodulenametotestreprtru ncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__)) 237 "<module %r from %r>" % (areallylongpackageandmodulenametotestreprtru ncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
237 eq(repr(sys), "<module 'sys' (built-in)>") 238 eq(repr(sys), "<module 'sys' (built-in)>")
238 239
239 def test_type(self): 240 def test_type(self):
240 eq = self.assertEqual 241 eq = self.assertEqual
241 write_file(os.path.join(self.subpkgname, 'foo.py'), '''\ 242 touch(os.path.join(self.subpkgname, 'foo.py'), '''\
242 class foo(object): 243 class foo(object):
243 pass 244 pass
244 ''') 245 ''')
245 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import foo 246 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import foo
246 eq(repr(foo.foo), 247 eq(repr(foo.foo),
247 "<class '%s.foo'>" % foo.__name__) 248 "<class '%s.foo'>" % foo.__name__)
248 249
249 def test_object(self): 250 def test_object(self):
250 # XXX Test the repr of a type with a really long tp_name but with no 251 # XXX Test the repr of a type with a really long tp_name but with no
251 # tp_repr. WIBNI we had ::Inline? :) 252 # tp_repr. WIBNI we had ::Inline? :)
252 pass 253 pass
253 254
254 def test_class(self): 255 def test_class(self):
255 write_file(os.path.join(self.subpkgname, 'bar.py'), '''\ 256 touch(os.path.join(self.subpkgname, 'bar.py'), '''\
256 class bar: 257 class bar:
257 pass 258 pass
258 ''') 259 ''')
259 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import bar 260 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import bar
260 # Module name may be prefixed with "test.", depending on how run. 261 # Module name may be prefixed with "test.", depending on how run.
261 self.assertEqual(repr(bar.bar), "<class '%s.bar'>" % bar.__name__) 262 self.assertEqual(repr(bar.bar), "<class '%s.bar'>" % bar.__name__)
262 263
263 def test_instance(self): 264 def test_instance(self):
264 write_file(os.path.join(self.subpkgname, 'baz.py'), '''\ 265 touch(os.path.join(self.subpkgname, 'baz.py'), '''\
265 class baz: 266 class baz:
266 pass 267 pass
267 ''') 268 ''')
268 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import baz 269 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import baz
269 ibaz = baz.baz() 270 ibaz = baz.baz()
270 self.assertTrue(repr(ibaz).startswith( 271 self.assertTrue(repr(ibaz).startswith(
271 "<%s.baz object at 0x" % baz.__name__)) 272 "<%s.baz object at 0x" % baz.__name__))
272 273
273 def test_method(self): 274 def test_method(self):
274 eq = self.assertEqual 275 eq = self.assertEqual
275 write_file(os.path.join(self.subpkgname, 'qux.py'), '''\ 276 touch(os.path.join(self.subpkgname, 'qux.py'), '''\
276 class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 277 class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
277 def amethod(self): pass 278 def amethod(self): pass
278 ''') 279 ''')
279 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import qux 280 from areallylongpackageandmodulenametotestreprtruncation.areallylongpack ageandmodulenametotestreprtruncation import qux
280 # Unbound methods first 281 # Unbound methods first
281 self.assertTrue(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ametho d).startswith( 282 self.assertTrue(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ametho d).startswith(
282 '<function amethod')) 283 '<function amethod'))
283 # Bound method next 284 # Bound method next
284 iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() 285 iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
285 self.assertTrue(repr(iqux.amethod).startswith( 286 self.assertTrue(repr(iqux.amethod).startswith(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 self.assertEqual(repr(m), '<a, b, c, d, e, +++, x, +++>') 331 self.assertEqual(repr(m), '<a, b, c, d, e, +++, x, +++>')
331 332
332 def test_main(): 333 def test_main():
333 run_unittest(ReprTests) 334 run_unittest(ReprTests)
334 run_unittest(LongReprTest) 335 run_unittest(LongReprTest)
335 run_unittest(TestRecursiveRepr) 336 run_unittest(TestRecursiveRepr)
336 337
337 338
338 if __name__ == "__main__": 339 if __name__ == "__main__":
339 test_main() 340 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_raise.py ('k') | Lib/test/test_robotparser.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+