MCPcopy Create free account
hub / github.com/bloomberg/pystack / test_custom_object

Function test_custom_object

tests/integration/test_local_variables.py:396–445  ·  view source on GitHub ↗
(generate_threads, python, tmpdir)

Source from the content-addressed store, hash-verified

394@ALL_PYTHONS
395@ALL_SOURCES
396def test_custom_object(generate_threads, python, tmpdir):
397 # GIVEN
398 _, python_executable = python
399
400 program_template = """
401import sys
402import time
403
404class A:
405 pass
406
407def first_func():
408 the_local = A()
409 second_func(the_local)
410
411def second_func(the_argument):
412 fifo = sys.argv[1]
413 with open(sys.argv[1], "w") as fifo:
414 fifo.write("ready")
415 time.sleep(1000)
416
417first_func()
418 """
419
420 script = tmpdir / "the_script.py"
421 script.write_text(program_template, encoding="utf-8")
422
423 # WHEN
424
425 threads = generate_threads(python_executable, script, tmpdir)
426
427 # THEN
428
429 assert len(threads) == 1
430 (thread,) = threads
431
432 frames = list(thread.frames)
433 assert (len(frames)) == 3
434
435 repr_regex = re.compile(r"<(?:A|instance|\?\?\?) at 0[xX][0-9a-fA-F]+>")
436
437 first_func_frame = find_frame(frames, "first_func")
438 assert "the_local" in first_func_frame.locals
439 argument_repr = first_func_frame.locals["the_local"]
440 assert repr_regex.match(argument_repr)
441
442 second_func_frame = find_frame(frames, "second_func")
443 assert "the_argument" in second_func_frame.arguments
444 argument_repr = second_func_frame.arguments["the_argument"]
445 assert repr_regex.match(argument_repr)
446
447
448@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 1

find_frameFunction · 0.85

Tested by

no test coverage detected