def test_cdpath_simple(): with xonsh_env(Env(CDPATH=PARENT, PWD=HERE)): with chdir(os.path.normpath("/")): assert_not_equal(os.getcwd(), HERE) dirstack.cd(["tests"]) assert_equal(os.getcwd(), HERE)
def test_HISTCONTROL_empty(): env = Env(HISTCONTROL="") assert isinstance(env["HISTCONTROL"], set) assert len(env["HISTCONTROL"]) == 0
def home_env(xonsh_builtins): """Set `__xonsh__.env ` to a new Env instance on `xonsh_builtins`""" xonsh_builtins.__xonsh__.env = Env(HOME=HOME_PATH) return xonsh_builtins
def test_env_detype(): env = Env(MYPATH=["wakka", "jawaka"]) assert "wakka" + os.pathsep + "jawaka" == env.detype()["MYPATH"]
def test_env_detype_no_dict(): env = Env(YO={"hey": 42}) env.register("YO", validate=always_true, convert=None, detype=None) det = env.detype() assert "YO" not in det
def test_env_path_dirs_list(path): env = Env(MYPATH=path, MYDIRS=path) assert path == env["MYPATH"].paths assert path == env["MYDIRS"].paths
def test_env_path_str(path): env = Env(MYPATH=path) assert path == env["MYPATH"].paths
def test_env_detype_no_dict(): env = Env(YO={"hey": 42}) env.set_ensurer('YO', Ensurer(always_true, None, None)) det = env.detype() assert "YO" not in det
def imp_env(xonsh_execer): """Call `load_builtins` with `xonsh_execer`""" load_builtins(execer=xonsh_execer) builtins.__xonsh_env__ = Env({'PATH': [], 'PATHEXT': []}) yield unload_builtins()
def test_cd_dot(xonsh_builtins): xonsh_builtins.__xonsh_env__ = Env(PWD=os.getcwd()) owd = os.getcwd().casefold() dirstack.cd(['.']) assert owd == os.getcwd().casefold()
def imp_env(xession): xession.env = Env({"PATH": [], "PATHEXT": []}) imphooks.install_import_hooks(xession.execer) yield XSH.unload()
def imp_env(xession): Execer(unload=False) xession.env = Env({"PATH": [], "PATHEXT": []}) yield XSH.unload()
import builtins import inspect import importlib os.environ['XONSH_DEBUG'] = '1' from xonsh import __version__ as XONSH_VERSION from xonsh.environ import DEFAULT_DOCS, Env from xonsh.xontribs import xontrib_metadata from xonsh import main from xonsh.commands_cache import CommandsCache spec = importlib.util.find_spec('prompt_toolkit') if spec is not None: # hacky runaround to import PTK-specific events builtins.__xonsh_env__ = Env() from xonsh.ptk.shell import events else: from xonsh.events import events sys.path.insert(0, os.path.dirname(__file__)) def setup(sphinx): from xonsh.pyghooks import XonshConsoleLexer sphinx.add_lexer("xonshcon", XonshConsoleLexer()) # -- General configuration ----------------------------------------------------- # Documentation is being built on readthedocs, this will be true. on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
def test_eval_recursive_callable_partial(xonsh_builtins): xonsh_builtins.__xonsh_env__ = Env(HOME=os.path.expanduser('~')) assert ALIASES.get('indirect_cd')(['arg2', 'arg3']) == ['..', 'arg2', 'arg3']
def test_env_contains(): env = Env(VAR="wakka") assert "VAR" in env
def test_env_normal(): env = Env(VAR='wakka') assert_equal('wakka', env['VAR'])
def test_delitem(): env = Env(VAR="a value") assert env["VAR"] == "a value" del env["VAR"] with pytest.raises(Exception): env["VAR"]
def test_env_path_list(): env = Env(MYPATH=['wakka']) assert_equal(['wakka'], env['MYPATH'])
def test_register_custom_var_str(val, converted): env = Env() env.register("MY_SPECIAL_VAR", type="str") env["MY_SPECIAL_VAR"] = val assert env["MY_SPECIAL_VAR"] == converted
def test_env_path_str(): env = Env(MYPATH='wakka' + os.pathsep + 'jawaka') assert_equal(['wakka', 'jawaka'], env['MYPATH'])
def test_env_iterate(): env = Env(TEST=0) env.register(re.compile("re")) for key in env: assert isinstance(key, str)
def test_env_detype(): env = Env(MYPATH=['wakka', 'jawaka']) assert_equal({'MYPATH': 'wakka' + os.pathsep + 'jawaka'}, env.detype())
def test_env_detype_mutable_access_clear(path1, path2): env = Env(MYPATH=path1) assert path1[0] + os.pathsep + path1[1] == env.detype()["MYPATH"] env["MYPATH"][0] = path2 assert env._detyped is None assert path2 + os.pathsep + path1[1] == env.detype()["MYPATH"]
def test_env_detype_mutable_access_clear(): env = Env(MYPATH=['wakka', 'jawaka']) assert_equal({'MYPATH': 'wakka' + os.pathsep + 'jawaka'}, env.detype()) env['MYPATH'][0] = 'woah' assert_equal(None, env._detyped) assert_equal({'MYPATH': 'woah' + os.pathsep + 'jawaka'}, env.detype())
def test_histcontrol_none(): env = Env(HISTCONTROL=None) assert isinstance(env["HISTCONTROL"], set) assert len(env["HISTCONTROL"]) == 0
def test_env_detype_no_dict(): env = Env(YO={'hey': 42}) det = env.detype() assert_not_in('YO', det)
def test_histcontrol_ignoredups(): env = Env(HISTCONTROL="ignoredups") assert isinstance(env["HISTCONTROL"], set) assert len(env["HISTCONTROL"]) == 1 assert "ignoredups" in env["HISTCONTROL"] assert "ignoreerr" not in env["HISTCONTROL"]
def test_env_normal(): env = Env(VAR="wakka") assert "wakka" == env["VAR"]
def test_histcontrol_ignoreerr_ignoredups_erase_dups(): env = Env(HISTCONTROL="ignoreerr,ignoredups,ignoreerr,erasedups") assert len(env["HISTCONTROL"]) == 3 assert "ignoreerr" in env["HISTCONTROL"] assert "ignoredups" in env["HISTCONTROL"] assert "erasedups" in env["HISTCONTROL"]
def load_builtins(execer=None, config=None, login=False, ctx=None): """Loads the xonsh builtins into the Python builtins. Sets the BUILTINS_LOADED variable to True. """ global BUILTINS_LOADED # private built-ins builtins.__xonsh_config__ = {} builtins.__xonsh_env__ = env = Env(default_env(config=config, login=login)) builtins.__xonsh_help__ = helper builtins.__xonsh_superhelp__ = superhelper builtins.__xonsh_pathsearch__ = pathsearch builtins.__xonsh_globsearch__ = globsearch builtins.__xonsh_regexsearch__ = regexsearch builtins.__xonsh_glob__ = globpath builtins.__xonsh_expand_path__ = expand_path builtins.__xonsh_exit__ = False builtins.__xonsh_stdout_uncaptured__ = None builtins.__xonsh_stderr_uncaptured__ = None if hasattr(builtins, 'exit'): builtins.__xonsh_pyexit__ = builtins.exit del builtins.exit if hasattr(builtins, 'quit'): builtins.__xonsh_pyquit__ = builtins.quit del builtins.quit builtins.__xonsh_subproc_captured_stdout__ = subproc_captured_stdout builtins.__xonsh_subproc_captured_inject__ = subproc_captured_inject builtins.__xonsh_subproc_captured_object__ = subproc_captured_object builtins.__xonsh_subproc_captured_hiddenobject__ = subproc_captured_hiddenobject builtins.__xonsh_subproc_uncaptured__ = subproc_uncaptured builtins.__xonsh_execer__ = execer builtins.__xonsh_commands_cache__ = CommandsCache() builtins.__xonsh_all_jobs__ = {} builtins.__xonsh_ensure_list_of_strs__ = ensure_list_of_strs builtins.__xonsh_list_of_strs_or_callables__ = list_of_strs_or_callables builtins.__xonsh_completers__ = xonsh.completers.init.default_completers() builtins.__xonsh_call_macro__ = call_macro builtins.__xonsh_enter_macro__ = enter_macro # public built-ins builtins.XonshError = XonshError builtins.XonshBlockError = XonshBlockError builtins.XonshCalledProcessError = XonshCalledProcessError builtins.evalx = None if execer is None else execer.eval builtins.execx = None if execer is None else execer.exec builtins.compilex = None if execer is None else execer.compile builtins.events = events # sneak the path search functions into the aliases # Need this inline/lazy import here since we use locate_binary that relies on __xonsh_env__ in default aliases builtins.default_aliases = builtins.aliases = Aliases( make_default_aliases()) if login: builtins.aliases.update(load_foreign_aliases(issue_warning=False)) # history needs to be started after env and aliases # would be nice to actually include non-detyped versions. builtins.__xonsh_history__ = History(env=env.detype(), ts=[time.time(), None], locked=True) atexit.register(_lastflush) for sig in AT_EXIT_SIGNALS: resetting_signal_handle(sig, _lastflush) BUILTINS_LOADED = True