xonsh/tests/test_aliases.py

54 lines
1.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2015-03-22 02:46:33 +01:00
"""Testing built_ins.Aliases"""
from __future__ import unicode_literals, print_function
2015-03-25 18:32:10 -05:00
2015-12-19 17:29:48 -05:00
import os
2016-06-22 22:45:42 +03:00
import pytest
2015-03-25 18:32:10 -05:00
2015-12-19 17:29:48 -05:00
import xonsh.built_ins as built_ins
2016-04-10 12:13:36 -04:00
from xonsh.aliases import Aliases
2015-12-19 17:29:48 -05:00
from xonsh.environ import Env
2015-03-22 02:46:33 +01:00
from tools import skip_if_on_windows
2015-12-19 18:09:06 -05:00
2015-03-22 02:46:33 +01:00
def cd(args, stdin=None):
return args
ALIASES = Aliases({'o': ['omg', 'lala']},
color_ls=['ls', '--color=true'],
ls="ls '- -'",
cd=cd,
indirect_cd='cd ..')
RAW = ALIASES._raw
2015-03-22 02:46:33 +01:00
def test_imports():
2016-06-22 22:45:42 +03:00
expected = {
2015-03-22 02:46:33 +01:00
'o': ['omg', 'lala'],
'ls': ['ls', '- -'],
'color_ls': ['ls', '--color=true'],
'cd': cd,
'indirect_cd': ['cd', '..']
2016-06-22 22:45:42 +03:00
}
assert RAW == expected
2015-03-22 02:46:33 +01:00
2015-07-29 23:58:25 +02:00
2016-06-26 02:05:26 +03:00
def test_eval_normal(xonsh_builtins):
assert ALIASES.get('o') == ['omg', 'lala']
2016-06-26 02:05:26 +03:00
def test_eval_self_reference(xonsh_builtins):
assert ALIASES.get('ls') == ['ls', '- -']
2016-06-26 02:05:26 +03:00
def test_eval_recursive(xonsh_builtins):
assert ALIASES.get('color_ls') == ['ls', '- -', '--color=true']
2015-07-29 23:58:25 +02:00
@skip_if_on_windows
2016-06-26 02:05:26 +03:00
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']