2016-08-22 21:34:25 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""(A down payment on) Testing for ``xonsh.base_shell.BaseShell`` and associated classes"""
|
|
|
|
import os
|
|
|
|
|
|
|
|
from xonsh.environ import Env
|
|
|
|
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
|
|
|
|
|
|
|
|
2018-08-30 09:18:49 -05:00
|
|
|
def test_pwd_tracks_cwd(xonsh_builtins, xonsh_execer, tmpdir_factory, monkeypatch):
|
2016-08-22 21:34:25 -04:00
|
|
|
asubdir = str(tmpdir_factory.mktemp("asubdir"))
|
|
|
|
cur_wd = os.getcwd()
|
2018-09-13 14:03:35 -04:00
|
|
|
xonsh_builtins.__xonsh__.env = Env(
|
2018-08-30 09:18:49 -05:00
|
|
|
PWD=cur_wd, XONSH_CACHE_SCRIPTS=False, XONSH_CACHE_EVERYTHING=False
|
|
|
|
)
|
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)
|
2018-08-30 09:18:49 -05:00
|
|
|
assert os.path.abspath(os.getcwd()) == os.path.abspath(
|
2018-09-13 14:03:35 -04:00
|
|
|
xonsh_builtins.__xonsh__.env["PWD"]
|
2018-08-30 09:18:49 -05:00
|
|
|
)
|
2018-09-13 14:03:35 -04:00
|
|
|
assert "OLDPWD" in xonsh_builtins.__xonsh__.env
|
2018-08-30 09:18:49 -05:00
|
|
|
assert os.path.abspath(cur_wd) == os.path.abspath(
|
2018-09-13 14:03:35 -04:00
|
|
|
xonsh_builtins.__xonsh__.env["OLDPWD"]
|
2018-08-30 09:18:49 -05:00
|
|
|
)
|
2016-09-05 20:36:45 -04:00
|
|
|
|
2016-08-22 21:34:25 -04:00
|
|
|
|
2017-01-07 15:31:30 -05:00
|
|
|
def test_transform(xonsh_builtins):
|
|
|
|
@xonsh_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"
|