more mocks for test_xonfig_kernel

This commit is contained in:
Bob Hyman 2020-09-23 04:35:44 -04:00
parent 0fc9098aad
commit 48238beec1
2 changed files with 14 additions and 1 deletions

View file

@ -1,2 +1,6 @@
class KernelSpecManager:
pass
class NoSuchKernel(Exception):
pass

View file

@ -79,6 +79,8 @@ def test_xonfig_kernel_with_jupyter(monkeypatch, capsys, fake_lib, xonsh_builtin
cap_args = None
cap_spec = None
import jupyter_client.kernelspec # from fake_lib, hopefully.
def mock_install_kernel_spec(*args, **kwargs): # arg[0] is self
nonlocal cap_args
nonlocal cap_spec
@ -86,7 +88,8 @@ def test_xonfig_kernel_with_jupyter(monkeypatch, capsys, fake_lib, xonsh_builtin
spec_file = os.path.join(args[1], "kernel.json")
cap_spec = json.load(open(spec_file, "r"))
import jupyter_client.kernelspec # from fake_lib, hopefully.
def mock_get_kernel_spec(*args, **kwargs):
raise jupyter_client.kernelspec.NoSuchKernel
monkeypatch.setattr(
jupyter_client.kernelspec.KernelSpecManager,
@ -94,6 +97,12 @@ def test_xonfig_kernel_with_jupyter(monkeypatch, capsys, fake_lib, xonsh_builtin
value=mock_install_kernel_spec,
raising=False,
)
monkeypatch.setattr(
jupyter_client.kernelspec.KernelSpecManager,
"get_kernel_spec",
value=mock_get_kernel_spec,
raising=False,
)
rc = xonfig_main(["jupyter-kernel"])
assert rc == 0