How to use the xonsh.environ.Env function in xonsh

To help you get started, we’ve selected a few xonsh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xonsh / xonsh / tests / test_dirstack.py View on Github external
def test_cdpath_expansion(xonsh_builtins):
    xonsh_builtins.__xonsh__.env = Env(HERE=HERE, CDPATH=("~", "$HERE"))
    test_dirs = (
        os.path.join(HERE, "xonsh-test-cdpath-here"),
        os.path.expanduser("~/xonsh-test-cdpath-home"),
    )
    try:
        for d in test_dirs:
            if not os.path.exists(d):
                os.mkdir(d)
            assert os.path.exists(
                dirstack._try_cdpath(d)
            ), "dirstack._try_cdpath: could not resolve {0}".format(d)
    finally:
        for d in test_dirs:
            if os.path.exists(d):
                os.rmdir(d)
github xonsh / xonsh / tests / test_imphooks.py View on Github external
def imp_env():
    execer = Execer(unload=False)
    builtins.__xonsh_env__ = Env({"PATH": [], "PATHEXT": []})
    yield
    unload_builtins()
github xonsh / xonsh / tests / test_dirstack.py View on Github external
def test_cdpath_events(xonsh_builtins, tmpdir):
    xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=os.getcwd())
    target = str(tmpdir)

    ev = None

    @xonsh_builtins.events.on_chdir
    def handler(olddir, newdir, **kw):
        nonlocal ev
        ev = olddir, newdir

    old_dir = os.getcwd()
    try:
        dirstack.cd([target])
    except:
        raise
    else:
        assert (old_dir, target) == ev
github xonsh / xonsh / tests / test_environ.py View on Github external
def test_delitem_default():
    env = Env()
    a_key, a_value = next(
        (k, v) for (k, v) in env._defaults.items() if isinstance(v, str)
    )
    del env[a_key]
    assert env[a_key] == a_value
    del env[a_key]
    assert env[a_key] == a_value
github donnemartin / gitsome / tests / test_dirstack.py View on Github external
def test_cdpath_simple():
    with xonsh_env(Env(CDPATH=PARENT)):
        with chdir(os.path.normpath("/")):
            assert_not_equal(os.getcwd(), HERE)
            dirstack.cd(["tests"])
            assert_equal(os.getcwd(), HERE)
github xonsh / xonsh / tests / test_environ.py View on Github external
def test_event_on_envvar_change_from_none_value(xonsh_builtins):
    env = Env(TEST=None)
    xonsh_builtins.__xonsh__.env = env
    share = []
    # register
    @xonsh_builtins.events.on_envvar_change
    def handler(name, oldvalue, newvalue, **kwargs):
        share.extend((name, oldvalue, newvalue))

    # trigger
    env["TEST"] = 1

    assert share == ["TEST", None, 1]
github xonsh / xonsh / tests / test_base_shell.py View on Github external
def test_pwd_tracks_cwd(xonsh_builtins, xonsh_execer, tmpdir_factory, monkeypatch):
    asubdir = str(tmpdir_factory.mktemp("asubdir"))
    cur_wd = os.getcwd()
    xonsh_builtins.__xonsh__.env = Env(
        PWD=cur_wd, XONSH_CACHE_SCRIPTS=False, XONSH_CACHE_EVERYTHING=False
    )

    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(
        xonsh_builtins.__xonsh__.env["PWD"]
    )
    assert "OLDPWD" in xonsh_builtins.__xonsh__.env
    assert os.path.abspath(cur_wd) == os.path.abspath(
github donnemartin / gitsome / tests / test_environ.py View on Github external
def test_env_detype_no_dict():
    env = Env(YO={'hey': 42})
    det = env.detype()
    assert_not_in('YO', det)
github xonsh / xonsh / tests / test_environ.py View on Github external
def test_env_detype():
    env = Env(MYPATH=["wakka", "jawaka"])
    assert "wakka" + os.pathsep + "jawaka" == env.detype()["MYPATH"]
github xonsh / xonsh / tests / test_environ.py View on Github external
def test_env_path_list(path):
    env = Env(MYPATH=path)
    assert path == env["MYPATH"].paths