2015-02-11 02:01:35 -06:00
|
|
|
"""Tests the xonsh lexer."""
|
|
|
|
from __future__ import unicode_literals, print_function
|
2015-09-24 19:27:19 -04:00
|
|
|
import sys
|
|
|
|
import glob
|
2015-02-11 02:01:35 -06:00
|
|
|
import builtins
|
2015-10-20 17:53:12 -04:00
|
|
|
import platform
|
2015-02-11 02:01:35 -06:00
|
|
|
import subprocess
|
|
|
|
from contextlib import contextmanager
|
|
|
|
|
2015-09-24 19:27:19 -04:00
|
|
|
from nose.plugins.skip import SkipTest
|
|
|
|
|
2015-03-28 17:55:48 -05:00
|
|
|
from xonsh.built_ins import ensure_list_of_strs
|
|
|
|
|
2015-09-24 19:27:19 -04:00
|
|
|
|
|
|
|
VER_3_4 = (3, 4)
|
|
|
|
VER_3_5 = (3, 5)
|
|
|
|
VER_MAJOR_MINOR = sys.version_info[:2]
|
2015-10-20 17:53:12 -04:00
|
|
|
ON_MAC = (platform.system() == 'Darwin')
|
2015-09-24 19:27:19 -04:00
|
|
|
|
2015-02-24 21:58:37 -06:00
|
|
|
def sp(cmd):
|
|
|
|
return subprocess.check_output(cmd, universal_newlines=True)
|
|
|
|
|
2015-02-11 02:01:35 -06:00
|
|
|
@contextmanager
|
|
|
|
def mock_xonsh_env(xenv):
|
|
|
|
builtins.__xonsh_env__ = xenv
|
|
|
|
builtins.__xonsh_help__ = lambda x: x
|
2015-02-25 00:46:11 -06:00
|
|
|
builtins.__xonsh_glob__ = glob.glob
|
2015-03-01 21:23:01 -06:00
|
|
|
builtins.__xonsh_exit__ = False
|
2015-02-11 02:01:35 -06:00
|
|
|
builtins.__xonsh_superhelp__ = lambda x: x
|
|
|
|
builtins.__xonsh_regexpath__ = lambda x: []
|
2015-02-24 21:58:37 -06:00
|
|
|
builtins.__xonsh_subproc_captured__ = sp
|
|
|
|
builtins.__xonsh_subproc_uncaptured__ = sp
|
2015-03-28 17:55:48 -05:00
|
|
|
builtins.__xonsh_ensure_list_of_strs__ = ensure_list_of_strs
|
2015-02-28 16:10:34 -06:00
|
|
|
builtins.evalx = None
|
|
|
|
builtins.execx = None
|
|
|
|
builtins.compilex = None
|
|
|
|
builtins.aliases = {}
|
2015-02-11 02:01:35 -06:00
|
|
|
yield
|
|
|
|
del builtins.__xonsh_env__
|
|
|
|
del builtins.__xonsh_help__
|
2015-02-25 00:46:11 -06:00
|
|
|
del builtins.__xonsh_glob__
|
2015-03-01 21:23:01 -06:00
|
|
|
del builtins.__xonsh_exit__
|
2015-02-11 02:01:35 -06:00
|
|
|
del builtins.__xonsh_superhelp__
|
|
|
|
del builtins.__xonsh_regexpath__
|
2015-07-29 23:58:25 +02:00
|
|
|
del builtins.__xonsh_subproc_captured__
|
|
|
|
del builtins.__xonsh_subproc_uncaptured__
|
2015-03-28 17:55:48 -05:00
|
|
|
del builtins.__xonsh_ensure_list_of_strs__
|
2015-02-28 16:10:34 -06:00
|
|
|
del builtins.evalx
|
|
|
|
del builtins.execx
|
|
|
|
del builtins.compilex
|
|
|
|
del builtins.aliases
|
2015-02-11 02:01:35 -06:00
|
|
|
|
2015-09-24 19:27:19 -04:00
|
|
|
|
|
|
|
def skipper():
|
|
|
|
"""Raises SkipTest"""
|
|
|
|
raise SkipTest
|
|
|
|
|
|
|
|
def skip_if(cond):
|
|
|
|
"""Skips a test under a given condition."""
|
|
|
|
def dec(f):
|
|
|
|
if cond:
|
|
|
|
return skipper
|
|
|
|
else:
|
|
|
|
return f
|
|
|
|
return dec
|