mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00

* refactor: remove usage of global variables in abbrevs.py * chore: add flake8-mutable to prevent mutable defaults * fix: abbrevs expand test * refactor: add xonsh session singleton * refactor: fix circular errors when using xonshSession as singleton * refactor: remove black magicked builtin attributes * style: black format tests as well * refactor: update tests to use xonsh-session singleton * refactor: update abbrevs to not use builtins * test: remove DummyCommandsCache and patch orig class * fix: failing test_command_completers * test: use monkeypatch to update xession fixture * fix: failing test_pipelines * fix: failing test_main * chore: run test suit as single invocation * test: fix tests/test_xonsh.xsh * refactor: remove builtins from docs/conf.py * fix: mypy error in jobs * fix: test error from test_main * test: close xession error in test_command_completers * chore: use pytest-cov for reporting coverage this will include subprocess calls, and will increase coverage * style:
71 lines
1.5 KiB
Python
71 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Testing xonsh import hooks"""
|
|
import os
|
|
from importlib import import_module
|
|
|
|
import pytest
|
|
|
|
from xonsh import imphooks
|
|
from xonsh.execer import Execer
|
|
from xonsh.environ import Env
|
|
from xonsh.built_ins import XSH
|
|
|
|
imphooks.install_import_hooks()
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def imp_env(xession):
|
|
Execer(unload=False)
|
|
xession.env = Env({"PATH": [], "PATHEXT": []})
|
|
yield
|
|
XSH.unload()
|
|
|
|
|
|
def test_import():
|
|
import sample
|
|
|
|
assert "hello mom jawaka\n" == sample.x
|
|
|
|
|
|
def test_absolute_import():
|
|
from xpack import sample
|
|
|
|
assert "hello mom jawaka\n" == sample.x
|
|
|
|
|
|
def test_relative_import():
|
|
from xpack import relimp
|
|
|
|
assert "hello mom jawaka\n" == relimp.sample.x
|
|
assert "hello mom jawaka\ndark chest of wonders" == relimp.y
|
|
|
|
|
|
def test_sub_import():
|
|
from xpack.sub import sample
|
|
|
|
assert "hello mom jawaka\n" == sample.x
|
|
|
|
|
|
TEST_DIR = os.path.dirname(__file__)
|
|
|
|
|
|
def test_module_dunder_file_attribute():
|
|
import sample
|
|
|
|
exp = os.path.join(TEST_DIR, "sample.xsh")
|
|
assert os.path.abspath(sample.__file__) == exp
|
|
|
|
|
|
def test_module_dunder_file_attribute_sub():
|
|
from xpack.sub import sample
|
|
|
|
exp = os.path.join(TEST_DIR, "xpack", "sub", "sample.xsh")
|
|
assert os.path.abspath(sample.__file__) == exp
|
|
|
|
|
|
def test_get_source():
|
|
mod = import_module("sample")
|
|
loader = mod.__loader__
|
|
source = loader.get_source("sample")
|
|
with open(os.path.join(TEST_DIR, "sample.xsh"), "rt") as srcfile:
|
|
assert source == srcfile.read()
|