xonsh/tests/test_execer.py

69 lines
1.3 KiB
Python
Raw Normal View History

2015-02-03 02:02:57 -06:00
"""Tests the xonsh lexer."""
from __future__ import unicode_literals, print_function
import os
import sys
import ast
from xonsh.execer import Execer
2015-02-11 02:01:35 -06:00
from tools import mock_xonsh_env
2015-02-03 02:02:57 -06:00
DEBUG_LEVEL = 0
EXECER = None
2015-03-01 19:13:09 -06:00
#
# Helpers
#
2015-02-03 02:02:57 -06:00
def setup():
# only setup one parser
global EXECER
EXECER = Execer(debug_level=DEBUG_LEVEL)
def check_exec(input):
2015-02-11 02:01:35 -06:00
with mock_xonsh_env(None):
if not input.endswith('\n'):
input += '\n'
EXECER.debug_level = DEBUG_LEVEL
EXECER.exec(input)
2015-02-03 02:02:57 -06:00
2015-03-01 19:13:09 -06:00
def check_eval(input):
with mock_xonsh_env(None):
EXECER.debug_level = DEBUG_LEVEL
EXECER.eval(input)
2015-03-10 21:38:11 -05:00
def check_parse(input):
with mock_xonsh_env(None):
EXECER.debug_level = DEBUG_LEVEL
EXECER.parse(input, ctx=None)
2015-03-01 19:13:09 -06:00
#
# Tests
#
2015-02-03 02:02:57 -06:00
def test_bin_ls():
2015-03-01 19:13:09 -06:00
yield check_eval, '/bin/ls -l'
2015-02-03 02:02:57 -06:00
2015-02-11 02:01:35 -06:00
def test_ls_dashl():
2015-03-01 19:13:09 -06:00
yield check_eval, 'ls -l'
2015-02-11 02:01:35 -06:00
def test_which_ls():
2015-03-01 19:13:09 -06:00
yield check_eval, 'which ls'
2015-02-11 02:01:35 -06:00
2015-03-10 21:38:11 -05:00
def test_simple_func():
code = ('def prompt():\n'
" return '{user}'.format(user='me')\n")
yield check_parse, code
def test_simple_func_broken():
code = ('def prompt():\n'
" return '{user}'.format(\n"
" user='me')\n")
yield check_parse, code
2015-02-03 02:02:57 -06:00
if __name__ == '__main__':
nose.runmodule()