Test %save.
()
| 1077 | |
| 1078 | |
| 1079 | def 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 | |
| 1100 | def test_store(): |
nothing calls this directly
no test coverage detected