2015-11-16 14:04:32 -08:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-03-29 17:49:44 -05:00
|
|
|
"""Testing xonsh import hooks"""
|
|
|
|
from __future__ import unicode_literals, print_function
|
|
|
|
|
|
|
|
import nose
|
|
|
|
from nose.tools import assert_equal
|
|
|
|
|
2015-04-02 20:23:26 -05:00
|
|
|
from xonsh import imphooks # noqa
|
2015-03-29 18:25:11 -05:00
|
|
|
from xonsh import built_ins
|
|
|
|
from xonsh.execer import Execer
|
|
|
|
from xonsh.built_ins import load_builtins, unload_builtins
|
|
|
|
|
2016-05-19 15:17:42 -04:00
|
|
|
from tools import mock_xonsh_env
|
2015-03-29 18:25:11 -05:00
|
|
|
LOADED_HERE = False
|
|
|
|
|
|
|
|
def setup():
|
|
|
|
global LOADED_HERE
|
|
|
|
if built_ins.BUILTINS_LOADED:
|
|
|
|
unload_builtins() # make sure we have a clean env from other tests.
|
|
|
|
load_builtins(execer=Execer())
|
|
|
|
LOADED_HERE = True
|
|
|
|
|
|
|
|
def teardown():
|
|
|
|
if LOADED_HERE:
|
|
|
|
unload_builtins()
|
2015-03-29 17:49:44 -05:00
|
|
|
|
2015-03-29 18:29:56 -05:00
|
|
|
def test_import():
|
2016-06-10 15:02:39 -04:00
|
|
|
with mock_xonsh_env({'PATH': []}):
|
2015-12-05 15:32:38 -05:00
|
|
|
import sample
|
|
|
|
assert_equal('hello mom jawaka\n', sample.x)
|
2015-03-29 18:25:11 -05:00
|
|
|
|
|
|
|
def test_absolute_import():
|
2016-06-10 15:02:39 -04:00
|
|
|
with mock_xonsh_env({'PATH': []}):
|
2015-12-05 15:32:38 -05:00
|
|
|
from xpack import sample
|
|
|
|
assert_equal('hello mom jawaka\n', sample.x)
|
2015-03-29 18:25:11 -05:00
|
|
|
|
2015-03-29 18:29:56 -05:00
|
|
|
def test_relative_import():
|
2016-06-10 15:02:39 -04:00
|
|
|
with mock_xonsh_env({'PATH': []}):
|
2015-12-05 15:32:38 -05:00
|
|
|
from xpack import relimp
|
|
|
|
assert_equal('hello mom jawaka\n', relimp.sample.x)
|
|
|
|
assert_equal('hello mom jawaka\ndark chest of wonders', relimp.y)
|
2015-03-29 18:29:56 -05:00
|
|
|
|
2015-03-29 22:53:33 -05:00
|
|
|
def test_sub_import():
|
2016-06-10 15:02:39 -04:00
|
|
|
with mock_xonsh_env({'PATH': []}):
|
2015-12-05 15:32:38 -05:00
|
|
|
from xpack.sub import sample
|
|
|
|
assert_equal('hello mom jawaka\n', sample.x)
|
2015-03-29 22:53:33 -05:00
|
|
|
|
2015-03-29 17:49:44 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
nose.runmodule()
|