xonsh/tests/test_jupyter_kernel.py
Noorhteen Raja NJ 38295a1dd9
Remove globals (#4280)
* 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:
2021-05-20 13:14:26 +03:00

50 lines
1.4 KiB
Python

import sys
import pytest
from inspect import signature
from unittest.mock import MagicMock
from xonsh.aliases import Aliases
from xonsh.completer import Completer
from tests.test_ptk_completer import EXPANSION_CASES
XonshKernel = None
@pytest.fixture(autouse=True)
def setup(monkeypatch):
global XonshKernel
if XonshKernel is None:
monkeypatch.setitem(sys.modules, "zmq", MagicMock())
monkeypatch.setitem(sys.modules, "zmq.eventloop", MagicMock())
monkeypatch.setitem(sys.modules, "zmq.error", MagicMock())
import xonsh.jupyter_kernel
XonshKernel = xonsh.jupyter_kernel.XonshKernel
@pytest.mark.parametrize("code, index, expected_args", EXPANSION_CASES)
def test_completion_alias_expansion(
code,
index,
expected_args,
monkeypatch,
xession,
):
xonsh_completer_mock = MagicMock(spec=Completer)
xonsh_completer_mock.complete.return_value = set(), 0
kernel = MagicMock()
kernel.completer = xonsh_completer_mock
monkeypatch.setattr(xession, "aliases", Aliases(gb=["git branch"]))
monkeypatch.setattr(xession.shell, "ctx", None, raising=False)
XonshKernel.do_complete(kernel, code, index)
mock_call = xonsh_completer_mock.complete.call_args
args, kwargs = mock_call
expected_args["self"] = None
expected_args["ctx"] = None
assert (
signature(Completer.complete).bind(None, *args, **kwargs).arguments
== expected_args
)