Lines Matching refs:self
148 def get_stack_trace(self, source=None, script=None,
256 def get_gdb_repr(self, source,
273 gdb_output = self.get_stack_trace(source, breakpoint=BREAKPOINT_FN,
280 # Match '#0 builtin_id(self=..., v=...)'
281 r'#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)?\)'
289 self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))
292 def assertEndsWith(self, actual, exp_end):
294 self.assertTrue(actual.endswith(exp_end),
297 def assertMultilineMatches(self, actual, pattern):
300 self.fail(msg='%r did not match %r' % (actual, pattern))
302 def get_sample_script(self):
306 def test_getting_backtrace(self):
307 gdb_output = self.get_stack_trace('id(42)')
308 self.assertTrue(BREAKPOINT_FN in gdb_output)
310 def assertGdbRepr(self, val, exp_repr=None):
313 gdb_repr, gdb_output = self.get_gdb_repr('id(' + ascii(val) + ')')
316 self.assertEqual(gdb_repr, exp_repr,
320 def test_int(self):
322 self.assertGdbRepr(42)
323 self.assertGdbRepr(0)
324 self.assertGdbRepr(-7)
325 self.assertGdbRepr(1000000000000)
326 self.assertGdbRepr(-1000000000000000)
328 def test_singletons(self):
330 self.assertGdbRepr(True)
331 self.assertGdbRepr(False)
332 self.assertGdbRepr(None)
334 def test_dicts(self):
336 self.assertGdbRepr({})
337 self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}")
339 self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'foo': 'bar', 'douglas': 42}")
341 def test_lists(self):
343 self.assertGdbRepr([])
344 self.assertGdbRepr(list(range(5)))
346 def test_bytes(self):
348 self.assertGdbRepr(b'')
349 self.assertGdbRepr(b'And now for something hopefully the same')
350 self.assertGdbRepr(b'string with embedded NUL here \0 and then some more text')
351 self.assertGdbRepr(b'this is a tab:\t'
356 self.assertGdbRepr(b'this is byte 255:\xff and byte 128:\x80')
358 self.assertGdbRepr(bytes([b for b in range(255)]))
360 def test_strings(self):
380 self.assertGdbRepr(text, ascii(text))
382 self.assertGdbRepr(text)
384 self.assertGdbRepr('')
385 self.assertGdbRepr('And now for something hopefully the same')
386 self.assertGdbRepr('string with embedded NUL here \0 and then some more text')
404 def test_tuples(self):
406 self.assertGdbRepr(tuple(), '()')
407 self.assertGdbRepr((1,), '(1,)')
408 self.assertGdbRepr(('foo', 'bar', 'baz'))
410 def test_sets(self):
413 self.skipTest("pretty-printing of sets needs gdb 7.3 or later")
414 self.assertGdbRepr(set(), "set()")
415 self.assertGdbRepr(set(['a']), "{'a'}")
418 self.assertGdbRepr(set(['a', 'b']), "{'a', 'b'}")
419 self.assertGdbRepr(set([4, 5, 6]), "{4, 5, 6}")
423 gdb_repr, gdb_output = self.get_gdb_repr('''s = set(['a','b'])
426 self.assertEqual(gdb_repr, "{'b'}")
428 def test_frozensets(self):
431 self.skipTest("pretty-printing of frozensets needs gdb 7.3 or later")
432 self.assertGdbRepr(frozenset(), "frozenset()")
433 self.assertGdbRepr(frozenset(['a']), "frozenset({'a'})")
436 self.assertGdbRepr(frozenset(['a', 'b']), "frozenset({'a', 'b'})")
437 self.assertGdbRepr(frozenset([4, 5, 6]), "frozenset({4, 5, 6})")
439 def test_exceptions(self):
441 gdb_repr, gdb_output = self.get_gdb_repr('''
447 self.assertEqual(gdb_repr,
452 gdb_repr, gdb_output = self.get_gdb_repr('''
458 self.assertEqual(gdb_repr,
461 def test_modern_class(self):
463 gdb_repr, gdb_output = self.get_gdb_repr('''
470 self.assertTrue(m,
473 def test_subclassing_list(self):
475 gdb_repr, gdb_output = self.get_gdb_repr('''
484 self.assertTrue(m,
487 def test_subclassing_tuple(self):
491 gdb_repr, gdb_output = self.get_gdb_repr('''
499 self.assertTrue(m,
502 def assertSane(self, source, corruption, exprepr=None):
514 self.get_gdb_repr(source,
528 self.fail('Unexpected gdb representation: %r\n%s' % \
531 def test_NULL_ptr(self):
534 self.get_gdb_repr('id(42)',
539 self.assertEqual(gdb_repr, '0x0')
541 def test_NULL_ob_type(self):
543 self.assertSane('id(42)',
546 def test_corrupt_ob_type(self):
548 self.assertSane('id(42)',
552 def test_corrupt_tp_flags(self):
554 self.assertSane('id(42)',
558 def test_corrupt_tp_name(self):
560 self.assertSane('id(42)',
564 def test_builtins_help(self):
568 self.skipTest("need site module, but -S option was used")
572 gdb_repr, gdb_output = self.get_gdb_repr('id(__builtins__.help)', import_site=True)
575 self.assertTrue(m,
578 def test_selfreferential_list(self):
582 self.get_gdb_repr("a = [3, 4, 5] ; a.append(a) ; id(a)")
583 self.assertEqual(gdb_repr, '[3, 4, 5, [...]]')
586 self.get_gdb_repr("a = [3, 4, 5] ; b = [a] ; a.append(b) ; id(a)")
587 self.assertEqual(gdb_repr, '[3, 4, 5, [[...]]]')
589 def test_selfreferential_dict(self):
593 self.get_gdb_repr("a = {} ; b = {'bar':a} ; a['foo'] = b ; id(a)")
595 self.assertEqual(gdb_repr, "{'foo': {'bar': {...}}}")
597 def test_selfreferential_old_style_instance(self):
599 self.get_gdb_repr('''
605 self.assertTrue(re.match(r'<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
610 def test_selfreferential_new_style_instance(self):
612 self.get_gdb_repr('''
618 self.assertTrue(re.match(r'<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
624 self.get_gdb_repr('''
632 self.assertTrue(re.match(r'<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>',
637 def test_truncation(self):
639 gdb_repr, gdb_output = self.get_gdb_repr('id(list(range(1000)))')
640 self.assertEqual(gdb_repr,
662 self.assertEqual(len(gdb_repr),
665 def test_builtin_method(self):
666 gdb_repr, gdb_output = self.get_gdb_repr('import sys; id(sys.stdout.readlines)')
667 self.assertTrue(re.match(r'<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>',
672 def test_frames(self):
673 gdb_output = self.get_stack_trace('''
683 self.assertTrue(re.match(r'.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 4, in foo \(a=3.*',
691 def assertListing(self, expected, actual):
692 self.assertEndsWith(actual, expected)
694 def test_basic_command(self):
696 bt = self.get_stack_trace(script=self.get_sample_script(),
699 self.assertListing(' 5 \n'
709 def test_one_abs_arg(self):
711 bt = self.get_stack_trace(script=self.get_sample_script(),
714 self.assertListing(' 9 def baz(*args):\n'
720 def test_two_abs_args(self):
722 bt = self.get_stack_trace(script=self.get_sample_script(),
725 self.assertListing(' 1 # Sample script for use by test_gdb.py\n'
752 def test_pyup_command(self):
754 bt = self.get_stack_trace(source=SAMPLE_WITH_C_CALL,
756 self.assertMultilineMatches(bt,
763 def test_down_at_bottom(self):
765 bt = self.get_stack_trace(script=self.get_sample_script(),
767 self.assertEndsWith(bt,
771 def test_up_at_top(self):
773 bt = self.get_stack_trace(script=self.get_sample_script(),
775 self.assertEndsWith(bt,
781 def test_up_then_down(self):
783 bt = self.get_stack_trace(source=SAMPLE_WITH_C_CALL,
785 self.assertMultilineMatches(bt,
795 def test_bt(self):
797 bt = self.get_stack_trace(script=self.get_sample_script(),
799 self.assertMultilineMatches(bt,
815 def test_bt_full(self):
817 bt = self.get_stack_trace(script=self.get_sample_script(),
819 self.assertMultilineMatches(bt,
831 def test_threads(self):
839 def run(self):
854 gdb_output = self.get_stack_trace(cmd,
856 self.assertIn('Waiting for the GIL', gdb_output)
859 gdb_output = self.get_stack_trace(cmd,
861 self.assertIn('Waiting for the GIL', gdb_output)
868 def test_gc(self):
878 gdb_output = self.get_stack_trace(cmd,
881 self.assertIn('Garbage-collecting', gdb_output)
884 gdb_output = self.get_stack_trace(cmd,
887 self.assertIn('Garbage-collecting', gdb_output)
901 def test_pycfunction(self):
926 with self.subTest(f'{obj}.{func_name}'):
936 gdb_output = self.get_stack_trace(
944 self.assertIn(f'<built-in method {func_name}', gdb_output)
947 gdb_output = self.get_stack_trace(
957 self.assertRegex(gdb_output, regex)
961 def test_wrapper_call(self):
964 def __init__(self):
979 gdb_output = self.get_stack_trace(cmd,
981 self.assertRegex(gdb_output,
987 def test_basic_command(self):
989 bt = self.get_stack_trace(source=SAMPLE_WITH_C_CALL,
991 self.assertMultilineMatches(bt,
997 def test_print_after_up(self):
998 bt = self.get_stack_trace(source=SAMPLE_WITH_C_CALL,
1000 self.assertMultilineMatches(bt,
1005 def test_printing_global(self):
1006 bt = self.get_stack_trace(script=self.get_sample_script(),
1008 self.assertMultilineMatches(bt,
1013 def test_printing_builtin(self):
1014 bt = self.get_stack_trace(script=self.get_sample_script(),
1016 self.assertMultilineMatches(bt,
1022 def test_basic_command(self):
1023 bt = self.get_stack_trace(script=self.get_sample_script(),
1025 self.assertMultilineMatches(bt,
1031 def test_locals_after_up(self):
1032 bt = self.get_stack_trace(script=self.get_sample_script(),
1034 self.assertMultilineMatches(bt,