Ejemplo n.º 1
0
def test_loads_zsh(tmp_path):
    environment = {
        "ENVPROBE_SHELL_PID": str(random.randint(1024, 65536)),
        "ENVPROBE_CONFIG": str(tmp_path),
        "ENVPROBE_SHELL_TYPE": 'zsh'
    }
    sh = shell.get_current_shell(environment)

    assert (sh.shell_type == environment["ENVPROBE_SHELL_TYPE"])
    assert (sh.shell_pid == environment["ENVPROBE_SHELL_PID"])
    assert (sh.configuration_directory == environment["ENVPROBE_CONFIG"])
Ejemplo n.º 2
0
def dummy_shell(mock_shell, tmp_path):
    cfg = {"ENVPROBE_SHELL_PID": str(random.randint(1024, 65536)),
           "ENVPROBE_CONFIG": str(tmp_path),
           "ENVPROBE_SHELL_TYPE": mock_shell}

    env = {"USER": "******",
           "CURRENT_DAY": random.randint(1, 31),
           "INIT_PID": 1,
           "PATH": "/bin:/usr/bin",
           "CMAKE_LIST": "MyModule;FooBar",
           **cfg}

    return get_current_shell(env), env
Ejemplo n.º 3
0
def get_shell_and_env_always(env_dict=None, vartype_pipeline=None):
    """Return an :py:class:`environment.Environment` and
    :py:class:`shell.Shell`, no matter what.

    Parameters
    ----------
    env_dict : dict, optional
        The raw mapping of environment variables to their values, as in
        :py:data:`os.environ`.
    vartype_pipeline : envprobe.environment.HeuristicStack, optional
        The type resolution heuristics pipeline to use.
        If not specified, the :py:data:`.environment.default_heuristic` will
        be used.

    Returns
    -------
    shell : .shell.Shell
        The shell which use can be deduced from the current environment (by
        calling :py:func:`.shell.get_current_shell`).
        If none such can be deduced, a :py:class:`.shell.FakeShell` is
        returned, which is a **valid** :py:class:`.shell.Shell` subclass that
        tells the client code it is not capable of anything.
    env : .environment.Environment
        The environment associated with the current context and the
        instantiated `Shell`.
    """
    if not env_dict:
        env_dict = os.environ
    if not vartype_pipeline:
        vartype_pipeline = default_heuristic

    try:
        sh = get_current_shell(env_dict)
    except KeyError:
        sh = FakeShell()

    env = Environment(sh, env_dict, vartype_pipeline)

    return sh, env
Ejemplo n.º 4
0
def test_unknown_fails_to_load():
    with pytest.raises(ModuleNotFoundError):
        shell.get_current_shell({"ENVPROBE_SHELL_TYPE": "false"})
Ejemplo n.º 5
0
def test_empty_environment():
    with pytest.raises(KeyError):
        shell.get_current_shell({})