MCPcopy Index your code
hub / github.com/ipython/ipython / check_cpaste

Function check_cpaste

tests/test_magic_terminal.py:43–65  ·  view source on GitHub ↗

Execute code via 'cpaste' and ensure it was executed, unless should_fail is set.

(code, should_fail=False)

Source from the content-addressed store, hash-verified

41
42
43def check_cpaste(code, should_fail=False):
44 """Execute code via 'cpaste' and ensure it was executed, unless
45 should_fail is set.
46 """
47 ip.user_ns["code_ran"] = False
48
49 src = StringIO()
50 src.write(code)
51 src.write("\n--\n")
52 src.seek(0)
53
54 stdin_save = sys.stdin
55 sys.stdin = src
56
57 try:
58 context = tt.AssertPrints if should_fail else tt.AssertNotPrints
59 with context("Traceback (most recent call last)"):
60 ip.run_line_magic("cpaste", "")
61
62 if not should_fail:
63 assert ip.user_ns["code_ran"], "%r failed" % code
64 finally:
65 sys.stdin = stdin_save
66
67
68def test_cpaste():

Callers 1

test_cpasteFunction · 0.85

Calls 3

seekMethod · 0.80
run_line_magicMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…