MCPcopy Index your code
hub / github.com/python/cpython / test_repr

Method test_repr

Lib/test/test_genericalias.py:226–247  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

224 self.assertEqual(t.__parameters__, ())
225
226 def test_repr(self):
227 class MyList(list):
228 pass
229 class MyGeneric:
230 __class_getitem__ = classmethod(GenericAlias)
231
232 self.assertEqual(repr(list[str]), 'list[str]')
233 self.assertEqual(repr(list[()]), 'list[()]')
234 self.assertEqual(repr(tuple[int, ...]), 'tuple[int, ...]')
235 x1 = tuple[*tuple[int]]
236 self.assertEqual(repr(x1), 'tuple[*tuple[int]]')
237 x2 = tuple[*tuple[int, str]]
238 self.assertEqual(repr(x2), 'tuple[*tuple[int, str]]')
239 x3 = tuple[*tuple[int, ...]]
240 self.assertEqual(repr(x3), 'tuple[*tuple[int, ...]]')
241 self.assertEndsWith(repr(MyList[int]), '.BaseTest.test_repr.<locals>.MyList[int]')
242 self.assertEqual(repr(list[str]()), '[]') # instances should keep their normal repr
243
244 # gh-105488
245 self.assertEndsWith(repr(MyGeneric[int]), 'MyGeneric[int]')
246 self.assertEndsWith(repr(MyGeneric[[]]), 'MyGeneric[[]]')
247 self.assertEndsWith(repr(MyGeneric[[int, str]]), 'MyGeneric[[int, str]]')
248
249 def test_evil_repr1(self):
250 # gh-143635

Callers

nothing calls this directly

Calls 2

assertEndsWithMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected