1# -*- coding: utf-8 -*- 2"""(A down payment on) Testing for ``xonsh.base_shell.BaseShell`` and associated classes""" 3import os 4 5from xonsh.environ import Env 6from xonsh.base_shell import BaseShell 7from xonsh.shell import transform_command 8 9 10def test_pwd_tracks_cwd(xonsh_builtins, xonsh_execer, tmpdir_factory, monkeypatch): 11 asubdir = str(tmpdir_factory.mktemp("asubdir")) 12 cur_wd = os.getcwd() 13 xonsh_builtins.__xonsh_env__ = Env( 14 PWD=cur_wd, XONSH_CACHE_SCRIPTS=False, XONSH_CACHE_EVERYTHING=False 15 ) 16 17 monkeypatch.setattr(xonsh_execer, "cacheall", False, raising=False) 18 bc = BaseShell(xonsh_execer, None) 19 20 assert os.getcwd() == cur_wd 21 22 bc.default('os.chdir(r"' + asubdir + '")') 23 24 assert os.path.abspath(os.getcwd()) == os.path.abspath(asubdir) 25 assert os.path.abspath(os.getcwd()) == os.path.abspath( 26 xonsh_builtins.__xonsh_env__["PWD"] 27 ) 28 assert "OLDPWD" in xonsh_builtins.__xonsh_env__ 29 assert os.path.abspath(cur_wd) == os.path.abspath( 30 xonsh_builtins.__xonsh_env__["OLDPWD"] 31 ) 32 33 34def test_transform(xonsh_builtins): 35 @xonsh_builtins.events.on_transform_command 36 def spam2egg(cmd, **_): 37 if cmd == "spam": 38 return "egg" 39 else: 40 return cmd 41 42 assert transform_command("spam") == "egg" 43 assert transform_command("egg") == "egg" 44 assert transform_command("foo") == "foo" 45