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

Function test_split_dict

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

Source from the content-addressed store, hash-verified

217@ALL_PYTHONS
218@ALL_SOURCES
219def test_split_dict(generate_threads, python, tmpdir):
220 # GIVE
221 _, python_executable = python
222
223 program_template = """
224import sys
225import time
226
227class A:
228 def __init__(self, x, y):
229 self.x = x
230 self.y = y
231
232a = A(1, "barbaridad")
233
234def first_func():
235 the_local = a.__dict__
236 second_func(a.__dict__)
237
238def second_func(the_argument):
239 fifo = sys.argv[1]
240 with open(sys.argv[1], "w") as fifo:
241 fifo.write("ready")
242 time.sleep(1000)
243
244first_func()
245 """
246
247 script = tmpdir / "the_script.py"
248 script.write_text(program_template, encoding="utf-8")
249
250 # WHEN
251
252 threads = generate_threads(python_executable, script, tmpdir)
253
254 # THEN
255
256 assert len(threads) == 1
257 (thread,) = threads
258
259 frames = list(thread.frames)
260 assert (len(frames)) == 3
261
262 first_func_frame = find_frame(frames, "first_func")
263 assert "the_local" in first_func_frame.locals
264 assert eval(first_func_frame.locals["the_local"]) == {
265 "x": 1,
266 "y": "barbaridad",
267 }
268
269 second_func_frame = find_frame(frames, "second_func")
270 assert "the_argument" in second_func_frame.arguments
271 assert eval(second_func_frame.arguments["the_argument"]) == {
272 "x": 1,
273 "y": "barbaridad",
274 }
275
276

Callers

nothing calls this directly

Calls 1

find_frameFunction · 0.85

Tested by

no test coverage detected