mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00

* todo * test: remove usage of DummyEnv and setting .env attribute on xession fixture one step closer to making too much of tweaking to xession during tests * test: fix tests vox and gitstatus-prompt * docs: update test-fixture usage * fix: import flake8 error * test: remove direct access to XSH in tests * test: remove usage of XSH in test files * todo * test: use tmp-dir to create stubs * refactor: use fixture factory to mock out XonshSession * refactor: remove direct access of XSH from functions * refactor: remove direct access of XSH from functions * fix: qa checks * refactor: rename variables to match their values * test: update failing tests because it had no PATH set previously * fix: remove builtins usage from pyghooks.py * style: * refactor: update tests to use fixtures * fix: env varialbe is setup per function some tests accidentally update the env variables and that is leaking into next tests * fix: failing vox tests * test: set commands_cache per test * test: fix failing tests * fix: failing tests on linux ptk-highlight * fix: failing tests on Windows cwd-prompt * test: copy env as to not affect original object * fix: lazily evaluate cmds-cache in pyghooks * test: fix failing tests * fix: qa errors import * test: set commands-cache per test while caching path results * test: speedup test_thread_local_swap * fix: failing tests on windows * refactor: Execer doesn't control session * refactor: XSH.unload will take care of reversing builtins attrs set * test: use env.update over monkeypatch * Revert "test: use env.update over monkeypatch" This reverts commit 010a5022247a098f1741966b8af1bf758663480e.
95 lines
2.5 KiB
Python
95 lines
2.5 KiB
Python
"""Testing for ``xonsh.shell.Shell``"""
|
|
import os
|
|
|
|
from xonsh.shell import Shell
|
|
from xonsh.history.json import JsonHistory
|
|
from xonsh.history.sqlite import SqliteHistory
|
|
from xonsh.history.dummy import DummyHistory
|
|
|
|
|
|
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
|
|
|
|
|
|
def test_shell_with_sqlite_history(xession, xonsh_execer, tmpdir_factory):
|
|
"""
|
|
Check that shell successfully load SQLite history from file.
|
|
"""
|
|
tempdir = str(tmpdir_factory.mktemp("history"))
|
|
|
|
history_file = os.path.join(tempdir, "history.db")
|
|
h = SqliteHistory(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="sqlite",
|
|
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
|
|
|
|
|
|
def test_shell_with_dummy_history_in_not_interactive(xession, xonsh_execer):
|
|
"""
|
|
Check that shell use Dummy history in not interactive mode.
|
|
"""
|
|
xession.env["XONSH_INTERACTIVE"] = False
|
|
xession.history = None
|
|
Shell(xonsh_execer, shell_type="none")
|
|
assert isinstance(xession.history, DummyHistory)
|