xonsh/tests/test_aliases.py

52 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
2015-03-25 18:32:10 -05:00
import nose
2015-03-22 02:46:33 +01:00
from nose.tools import assert_equal
2015-03-25 18:32:10 -05:00
2015-12-19 17:29:48 -05:00
import xonsh.built_ins as built_ins
2015-03-22 02:46:33 +01:00
from xonsh.built_ins import Aliases
2015-12-19 17:29:48 -05:00
from xonsh.environ import Env
2015-03-22 02:46:33 +01:00
2015-12-19 18:09:06 -05:00
from tools import mock_xonsh_env
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
def test_imports():
assert_equal(RAW, {
'o': ['omg', 'lala'],
'ls': ['ls', '- -'],
'color_ls': ['ls', '--color=true'],
'cd': cd,
'indirect_cd': ['cd', '..']
})
def test_eval_normal():
assert_equal(ALIASES.get('o'), ['omg', 'lala'])
2015-07-29 23:58:25 +02:00
2015-03-22 02:46:33 +01:00
def test_eval_self_reference():
assert_equal(ALIASES.get('ls'), ['ls', '- -'])
2015-07-29 23:58:25 +02:00
2015-03-22 02:46:33 +01:00
def test_eval_recursive():
assert_equal(ALIASES.get('color_ls'), ['ls', '- -', '--color=true'])
def test_eval_recursive_callable_partial():
2015-12-19 17:29:48 -05:00
built_ins.ENV = Env(HOME=os.path.expanduser('~'))
2015-12-19 18:09:06 -05:00
with mock_xonsh_env(built_ins.ENV):
assert_equal(ALIASES.get('indirect_cd')(['arg2', 'arg3']),
['..', 'arg2', 'arg3'])
2015-07-29 23:58:25 +02:00
2015-03-22 02:46:33 +01:00
if __name__ == '__main__':
nose.runmodule()