-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Captures output, returns reply
- Loading branch information
Showing
2 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Tests for the KernelClient""" | ||
|
||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
|
||
import os | ||
pjoin = os.path.join | ||
from unittest import TestCase | ||
|
||
from nose import SkipTest | ||
|
||
from jupyter_client.kernelspec import KernelSpecManager, NoSuchKernel, NATIVE_KERNEL_NAME | ||
from ..manager import start_new_kernel | ||
from .utils import test_env | ||
|
||
from IPython.utils.capture import capture_output | ||
|
||
TIMEOUT = 30 | ||
|
||
class TestKernelClient(TestCase): | ||
def setUp(self): | ||
self.env_patch = test_env() | ||
self.env_patch.start() | ||
|
||
def tearDown(self): | ||
self.env_patch.stop() | ||
|
||
def test_run(self): | ||
try: | ||
KernelSpecManager().get_kernel_spec(NATIVE_KERNEL_NAME) | ||
except NoSuchKernel: | ||
raise SkipTest() | ||
km, kc = start_new_kernel(kernel_name=NATIVE_KERNEL_NAME) | ||
self.addCleanup(kc.stop_channels) | ||
self.addCleanup(km.shutdown_kernel) | ||
|
||
with capture_output() as io: | ||
reply = kc.run("print('hello')", timeout=TIMEOUT) | ||
assert 'hello' in io.stdout | ||
assert reply['content']['status'] == 'ok' |