mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
added commands cache tests is_only_functional_alias()
This commit is contained in:
parent
8609bef403
commit
f572eae288
2 changed files with 36 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
import builtins
|
||||
|
||||
import pytest
|
||||
|
||||
import os
|
||||
from xonsh.commands_cache import (CommandsCache, predict_shell,
|
||||
SHELL_PREDICTOR_PARSER, predict_true, predict_false)
|
||||
from tools import skip_if_on_windows
|
||||
|
@ -82,3 +84,29 @@ def test_commands_cache_predictor_default(args):
|
|||
timeout=1, failure=None)
|
||||
expected = predict_false if use_tty else predict_true
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_cd_is_only_functional_alias(xonsh_builtins):
|
||||
cc = CommandsCache()
|
||||
builtins.aliases['cd'] = lambda args: os.chdir(args[0])
|
||||
assert cc.is_only_functional_alias('cd')
|
||||
|
||||
|
||||
def test_non_exist_is_only_functional_alias(xonsh_builtins):
|
||||
cc = CommandsCache()
|
||||
assert not cc.is_only_functional_alias('<not really a command name>')
|
||||
|
||||
|
||||
@skip_if_on_windows
|
||||
def test_bash_is_only_functional_alias(xonsh_builtins):
|
||||
builtins.__xonsh_env__['PATH'] = os.environ['PATH'].split(os.pathsep)
|
||||
cc = CommandsCache()
|
||||
assert not cc.is_only_functional_alias('bash')
|
||||
|
||||
|
||||
@skip_if_on_windows
|
||||
def test_bash_and_is_alias_is_only_functional_alias(xonsh_builtins):
|
||||
builtins.__xonsh_env__['PATH'] = os.environ['PATH'].split(os.pathsep)
|
||||
cc = CommandsCache()
|
||||
builtins.aliases['bash'] = lambda args: os.chdir(args[0])
|
||||
assert not cc.is_only_functional_alias('bash')
|
||||
|
|
|
@ -189,10 +189,12 @@ class CommandsCache(cabc.Mapping):
|
|||
None)
|
||||
if cached:
|
||||
(path, alias) = self._cmds_cache[cached]
|
||||
if not alias or ignore_alias:
|
||||
return path
|
||||
else:
|
||||
ispure = path == pathbasename(path)
|
||||
if alias and ignore_alias and ispure:
|
||||
# pure alias, which we are ignoring
|
||||
return None
|
||||
else:
|
||||
return path
|
||||
elif os.path.isfile(name) and name != pathbasename(name):
|
||||
return name
|
||||
|
||||
|
@ -212,7 +214,8 @@ class CommandsCache(cabc.Mapping):
|
|||
val = self._cmds_cache.get(name, None)
|
||||
if val is None:
|
||||
return False
|
||||
return val == (name, True)
|
||||
return val == (name, True) and \
|
||||
self.locate_binary(name, ignore_alias=True) is None
|
||||
|
||||
def predict_threadable(self, cmd):
|
||||
"""Predicts whether a command list is able to be run on a background
|
||||
|
|
Loading…
Add table
Reference in a new issue