xonsh/tests/test_base_shell.py

39 lines
1.2 KiB
Python
Raw Normal View History

2016-08-22 21:34:25 -04:00
"""(A down payment on) Testing for ``xonsh.base_shell.BaseShell`` and associated classes"""
import os
from xonsh.base_shell import BaseShell
2017-01-07 15:31:30 -05:00
from xonsh.shell import transform_command
2016-08-22 21:34:25 -04:00
def test_pwd_tracks_cwd(xession, xonsh_execer, tmpdir_factory, monkeypatch):
2016-08-22 21:34:25 -04:00
asubdir = str(tmpdir_factory.mktemp("asubdir"))
cur_wd = os.getcwd()
update test xsh usage (#4581) * 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.
2022-01-08 04:03:22 +05:30
xession.env.update(
dict(PWD=cur_wd, XONSH_CACHE_SCRIPTS=False, XONSH_CACHE_EVERYTHING=False)
2018-08-30 09:18:49 -05:00
)
2016-08-22 21:34:25 -04:00
monkeypatch.setattr(xonsh_execer, "cacheall", False, raising=False)
bc = BaseShell(xonsh_execer, None)
assert os.getcwd() == cur_wd
bc.default('os.chdir(r"' + asubdir + '")')
assert os.path.abspath(os.getcwd()) == os.path.abspath(asubdir)
assert os.path.abspath(os.getcwd()) == os.path.abspath(xession.env["PWD"])
assert "OLDPWD" in xession.env
assert os.path.abspath(cur_wd) == os.path.abspath(xession.env["OLDPWD"])
2016-08-22 21:34:25 -04:00
def test_transform(xession):
@xession.builtins.events.on_transform_command
2017-01-14 18:13:27 -05:00
def spam2egg(cmd, **_):
2018-08-30 09:18:49 -05:00
if cmd == "spam":
return "egg"
2017-01-07 15:31:30 -05:00
else:
return cmd
2018-08-30 09:18:49 -05:00
assert transform_command("spam") == "egg"
assert transform_command("egg") == "egg"
assert transform_command("foo") == "foo"