Ejemplo n.º 1
0
def test_shell_with_json_history(xession, xonsh_execer, tmpdir_factory):
    """
    Check that shell successfully load JSON history from file.
    """
    tempdir = str(tmpdir_factory.mktemp("history"))

    history_file = os.path.join(tempdir, "history.json")
    h = JsonHistory(filename=history_file)
    h.append({
        "inp": "echo Hello world 1\n",
        "rtn": 0,
        "ts": [1615887820.7329783, 1615887820.7513437],
    })
    h.append({
        "inp": "echo Hello world 2\n",
        "rtn": 0,
        "ts": [1615887820.7329783, 1615887820.7513437],
    })
    h.flush()

    xession.env.update(
        dict(
            XONSH_DATA_DIR=tempdir,
            XONSH_INTERACTIVE=True,
            XONSH_HISTORY_BACKEND="json",
            XONSH_HISTORY_FILE=history_file,
            # XONSH_DEBUG=1  # to show errors
        ))

    Shell(xonsh_execer, shell_type="none")

    assert len([i for i in xession.history.all_items()]) == 2
Ejemplo n.º 2
0
def hist():
    h = JsonHistory(filename="xonsh-HISTORY-TEST.json",
                    here="yup",
                    sessionid="SESSIONID",
                    gc=False)
    yield h
    os.remove(h.filename)
Ejemplo n.º 3
0
def hist():
    h = JsonHistory(filename='xonsh-HISTORY-TEST.json',
                    here='yup',
                    sessionid='SESSIONID',
                    gc=False)
    yield h
    os.remove(h.filename)
Ejemplo n.º 4
0
def hist(tmpdir, xession, monkeypatch):
    file = tmpdir / "xonsh-HISTORY-TEST.json"
    h = JsonHistory(filename=str(file),
                    here="yup",
                    sessionid="SESSIONID",
                    gc=False)
    monkeypatch.setattr(xession, "history", h)
    yield h
Ejemplo n.º 5
0
def test_history_diff(tmpdir, xession, monkeypatch, capsys):
    files = [tmpdir / f"xonsh-HISTORY-TEST-{idx}.json" for idx in range(2)]
    for file in files:
        hist = JsonHistory(filename=str(file),
                           here="yup",
                           sessionid="SESSIONID",
                           gc=False)
        monkeypatch.setattr(xession, "history", hist)
        xession.env["HISTCONTROL"] = set()
        for ts, cmd in enumerate(CMDS):  # populate the shell history
            hist.append({"inp": cmd, "rtn": 0, "ts": (ts + 1, ts + 1.5)})
        flush = hist.flush()
        if flush.queue:
            # make sure that flush is complete
            time.sleep(0.1)

    left, right = [str(f) for f in files]
    history_main(["diff", left, right])
    out, err = capsys.readouterr()
    # make sure it is called
    assert out.rstrip()