update tests to have __xonsh_shell__

This commit is contained in:
adam j hartz 2015-12-05 15:32:38 -05:00
parent 0c132528c4
commit 07176d664d
3 changed files with 21 additions and 12 deletions

View file

@ -10,6 +10,7 @@ from xonsh import built_ins
from xonsh.execer import Execer
from xonsh.built_ins import load_builtins, unload_builtins
from tests.tools import mock_xonsh_env
LOADED_HERE = False
def setup():
@ -24,21 +25,25 @@ def teardown():
unload_builtins()
def test_import():
import sample
assert_equal('hello mom jawaka\n', sample.x)
with mock_xonsh_env({}):
import sample
assert_equal('hello mom jawaka\n', sample.x)
def test_absolute_import():
from xpack import sample
assert_equal('hello mom jawaka\n', sample.x)
with mock_xonsh_env({}):
from xpack import sample
assert_equal('hello mom jawaka\n', sample.x)
def test_relative_import():
from xpack import relimp
assert_equal('hello mom jawaka\n', relimp.sample.x)
assert_equal('hello mom jawaka\ndark chest of wonders', relimp.y)
with mock_xonsh_env({}):
from xpack import relimp
assert_equal('hello mom jawaka\n', relimp.sample.x)
assert_equal('hello mom jawaka\ndark chest of wonders', relimp.y)
def test_sub_import():
from xpack.sub import sample
assert_equal('hello mom jawaka\n', sample.x)
with mock_xonsh_env({}):
from xpack.sub import sample
assert_equal('hello mom jawaka\n', sample.x)
if __name__ == '__main__':

View file

@ -21,9 +21,14 @@ ON_MAC = (platform.system() == 'Darwin')
def sp(cmd):
return subprocess.check_output(cmd, universal_newlines=True)
class DummyShell:
def settitle():
pass
@contextmanager
def mock_xonsh_env(xenv):
builtins.__xonsh_env__ = xenv
builtins.__xonsh_shell__ = DummyShell()
builtins.__xonsh_help__ = lambda x: x
builtins.__xonsh_glob__ = glob.glob
builtins.__xonsh_exit__ = False
@ -38,6 +43,7 @@ def mock_xonsh_env(xenv):
builtins.aliases = {}
yield
del builtins.__xonsh_env__
del builtins.__xonsh_shell__
del builtins.__xonsh_help__
del builtins.__xonsh_glob__
del builtins.__xonsh_exit__

View file

@ -613,10 +613,8 @@ def run_subproc(cmds, captured=True):
'obj': prev_proc,
'bg': background
})
try:
if ENV.get('XONSH_INTERACTIVE'):
builtins.__xonsh_shell__.settitle()
except AttributeError:
pass
if background:
return
if prev_is_proxy: