Esempio n. 1
0
def test_random_choice():
    lst = [1, 2, 3]
    r = simple_random_choice(lst)
    assert r in lst

    with pytest.raises(ValueError):
        simple_random_choice(range(1010101))
Esempio n. 2
0
 def choose_shell_type(init_shell_type=None, env=None):
     # pick a valid shell -- if no shell is specified by the user,
     # shell type is pulled from env
     # extracted for testability
     shell_type = init_shell_type
     if shell_type is None and env:
         shell_type = env.get("SHELL_TYPE")
         if shell_type == "none":
             # This bricks interactive xonsh
             # Can happen from the use of .xinitrc, .xsession, etc
             # odd logic.  We don't override if shell.__init__( shell_type="none"),
             # only if it come from environment?
             shell_type = "best"
     shell_type = Shell.shell_type_aliases.get(shell_type, shell_type)
     if shell_type == "best" or shell_type is None:
         shell_type = best_shell_type()
     elif env and env.get("TERM", "") == "dumb":
         shell_type = "dumb"
     elif shell_type == "random":
         shell_type = simple_random_choice(("readline", "prompt_toolkit"))
     if shell_type == "prompt_toolkit":
         if not has_prompt_toolkit():
             use_vended_prompt_toolkit()
         elif not ptk_above_min_supported():
             warnings.warn(
                 "Installed prompt-toolkit version < v{}.{}.{} is not ".
                 format(*minimum_required_ptk_version) +
                 "supported. Falling back to the builtin prompt-toolkit.")
             use_vended_prompt_toolkit()
         if init_shell_type in ("ptk1", "prompt_toolkit1"):
             warnings.warn(
                 "$SHELL_TYPE='{}' now deprecated, please update your run control file'"
                 .format(init_shell_type))
     return shell_type