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

Function test_save

tests/test_magic.py:1696–1712  ·  view source on GitHub ↗

Test %save.

()

Source from the content-addressed store, hash-verified

1694
1695
1696def test_save():
1697 """Test %save."""
1698 ip = get_ipython()
1699 ip.history_manager.reset() # Clear any existing history.
1700 cmds = ["a=1", "def b():\n return a**2", "print(a, b())"]
1701 for i, cmd in enumerate(cmds, start=1):
1702 ip.history_manager.store_inputs(i, cmd)
1703 with TemporaryDirectory() as tmpdir:
1704 file = os.path.join(tmpdir, "testsave.py")
1705 ip.run_line_magic("save", "%s 1-10" % file)
1706 content = Path(file).read_text(encoding="utf-8")
1707 assert content.count(cmds[0]) == 1
1708 assert "coding: utf-8" in content
1709 ip.run_line_magic("save", "-a %s 1-10" % file)
1710 content = Path(file).read_text(encoding="utf-8")
1711 assert content.count(cmds[0]) == 2
1712 assert "coding: utf-8" in content
1713
1714
1715def test_save_with_no_args():

Callers

nothing calls this directly

Calls 4

get_ipythonFunction · 0.90
store_inputsMethod · 0.80
run_line_magicMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…