Test %save.
()
| 1694 | |
| 1695 | |
| 1696 | def 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 | |
| 1715 | def test_save_with_no_args(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…