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

Function test_ipython_embed

tests/test_embed.py:42–71  ·  view source on GitHub ↗

test that `IPython.embed()` works

()

Source from the content-addressed store, hash-verified

40
41
42def test_ipython_embed():
43 """test that `IPython.embed()` works"""
44 with NamedFileInTemporaryDirectory("file_with_embed.py", "w") as f:
45 f.write(_sample_embed)
46 f.flush()
47 f.close() # otherwise msft won't be able to read the file
48
49 # run `python file_with_embed.py`
50 cmd = [sys.executable, f.name]
51 env = os.environ.copy()
52 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
53
54 p = subprocess.Popen(
55 cmd,
56 env=env,
57 stdin=subprocess.PIPE,
58 stdout=subprocess.PIPE,
59 stderr=subprocess.PIPE,
60 text=True,
61 encoding="UTF-8",
62 )
63 std, err = p.communicate(_exit)
64 assert isinstance(std, str), (std, err, p.returncode)
65
66 assert p.returncode == 0, (p.returncode, std)
67 assert "3 . 14" in std
68 if os.name != "nt":
69 # TODO: Fix up our different stdout references, see issue gh-14
70 assert "IPython" in std
71 assert "bye!" in std
72
73
74@skip_win32

Callers

nothing calls this directly

Calls 5

writeMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…