(hmmax2)
| 59 | |
| 60 | |
| 61 | def test_history(hmmax2): |
| 62 | ip = get_ipython() |
| 63 | with TemporaryDirectory() as tmpdir: |
| 64 | tmp_path = Path(tmpdir) |
| 65 | hist_manager_ori = ip.history_manager |
| 66 | hist_file = tmp_path / "history_test_history1.sqlite" |
| 67 | try: |
| 68 | ip.history_manager = HistoryManager(shell=ip, hist_file=hist_file) |
| 69 | hist = ["a=1", "def f():\n test = 1\n return test", "b='€Æ¾÷ß'"] |
| 70 | for i, h in enumerate(hist, start=1): |
| 71 | ip.history_manager.store_inputs(i, h) |
| 72 | |
| 73 | ip.history_manager.db_log_output = True |
| 74 | # Doesn't match the input, but we'll just check it's stored. |
| 75 | ip.history_manager.output_hist_reprs[3] = "spam" |
| 76 | ip.history_manager.store_output(3) |
| 77 | |
| 78 | assert ip.history_manager.input_hist_raw == [""] + hist |
| 79 | |
| 80 | # Detailed tests for _get_range_session |
| 81 | grs = ip.history_manager._get_range_session |
| 82 | assert list(grs(start=2, stop=-1)) == list(zip([0], [2], hist[1:-1])) |
| 83 | assert list(grs(start=-2)) == list(zip([0, 0], [2, 3], hist[-2:])) |
| 84 | assert list(grs(output=True)) == list( |
| 85 | zip([0, 0, 0], [1, 2, 3], zip(hist, [None, None, "spam"])) |
| 86 | ) |
| 87 | |
| 88 | # Check whether specifying a range beyond the end of the current |
| 89 | # session results in an error (gh-804) |
| 90 | ip.run_line_magic("hist", "2-500") |
| 91 | |
| 92 | # Check that we can write non-ascii characters to a file |
| 93 | ip.run_line_magic("hist", "-f %s" % (tmp_path / "test1")) |
| 94 | ip.run_line_magic("hist", "-pf %s" % (tmp_path / "test2")) |
| 95 | ip.run_line_magic("hist", "-nf %s" % (tmp_path / "test3")) |
| 96 | ip.run_line_magic("save", "%s 1-10" % (tmp_path / "test4")) |
| 97 | |
| 98 | # New session |
| 99 | ip.history_manager.reset() |
| 100 | newcmds = ["z=5", "class X(object):\n pass", "k='p'", "z=5"] |
| 101 | for i, cmd in enumerate(newcmds, start=1): |
| 102 | ip.history_manager.store_inputs(i, cmd) |
| 103 | gothist = ip.history_manager.get_range(start=1, stop=4) |
| 104 | assert list(gothist) == list(zip([0, 0, 0], [1, 2, 3], newcmds)) |
| 105 | # Previous session: |
| 106 | gothist = ip.history_manager.get_range(-1, 1, 4) |
| 107 | assert list(gothist) == list(zip([1, 1, 1], [1, 2, 3], hist)) |
| 108 | |
| 109 | newhist = [(2, i, c) for (i, c) in enumerate(newcmds, 1)] |
| 110 | |
| 111 | # Check get_hist_tail |
| 112 | gothist = ip.history_manager.get_tail(5, output=True, include_latest=True) |
| 113 | expected = [(1, 3, (hist[-1], "spam"))] + [ |
| 114 | (s, n, (c, None)) for (s, n, c) in newhist |
| 115 | ] |
| 116 | assert list(gothist) == expected |
| 117 | |
| 118 | gothist = ip.history_manager.get_tail(2) |
nothing calls this directly
no test coverage detected
searching dependent graphs…