MCPcopy Create free account
hub / github.com/ipython/ipython / test_save

Function test_save

IPython/core/tests/test_magic.py:1079–1097  ·  view source on GitHub ↗

Test %save.

()

Source from the content-addressed store, hash-verified

1077
1078
1079def test_save():
1080 """Test %save."""
1081 ip = get_ipython()
1082 ip.history_manager.reset() # Clear any existing history.
1083 cmds = [u"a=1", u"def b():\n return a**2", u"print(a, b())"]
1084 for i, cmd in enumerate(cmds, start=1):
1085 ip.history_manager.store_inputs(i, cmd)
1086 with TemporaryDirectory() as tmpdir:
1087 file = os.path.join(tmpdir, "testsave.py")
1088 ip.run_line_magic("save", "%s 1-10" % file)
1089 with open(file) as f:
1090 content = f.read()
1091 nt.assert_equal(content.count(cmds[0]), 1)
1092 nt.assert_in('coding: utf-8', content)
1093 ip.run_line_magic("save", "-a %s 1-10" % file)
1094 with open(file) as f:
1095 content = f.read()
1096 nt.assert_equal(content.count(cmds[0]), 2)
1097 nt.assert_in('coding: utf-8', content)
1098
1099
1100def test_store():

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected