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:
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import os.path
|
|
import pytest
|
|
|
|
import builtins
|
|
from contextlib import contextmanager
|
|
from unittest.mock import MagicMock
|
|
from xonsh.aliases import source_alias
|
|
|
|
|
|
@pytest.fixture
|
|
def mockopen(xonsh_builtins, monkeypatch):
|
|
@contextmanager
|
|
def mocked_open(fpath, *args, **kwargs):
|
|
yield MagicMock(read=lambda: fpath)
|
|
|
|
monkeypatch.setattr(builtins, "open", mocked_open)
|
|
|
|
|
|
@pytest.fixture
|
|
def mocked_execx_checker(xession, monkeypatch):
|
|
checker = []
|
|
|
|
def mocked_execx(src, *args, **kwargs):
|
|
checker.append(src.strip())
|
|
|
|
monkeypatch.setattr(xession.builtins, "execx", mocked_execx)
|
|
return checker
|
|
|
|
|
|
def test_source_current_dir(mockopen, monkeypatch, mocked_execx_checker):
|
|
monkeypatch.setattr(os.path, "isfile", lambda x: True)
|
|
source_alias(["foo", "bar"])
|
|
assert mocked_execx_checker == ["foo", "bar"]
|
|
|
|
|
|
def test_source_path(mockopen, mocked_execx_checker):
|
|
source_alias(["foo", "bar"])
|
|
path_foo = os.path.join("tests", "bin", "foo")
|
|
path_bar = os.path.join("tests", "bin", "bar")
|
|
assert mocked_execx_checker[0].endswith(path_foo)
|
|
assert mocked_execx_checker[1].endswith(path_bar)
|