Skip to content

Commit 7d592e7

Browse files
authored
Support bash kernel in notebook-http mode (#382)
* Support bash kernel in notebook-http mode * Add tests for bash kernel and startup banner
1 parent 5269af0 commit 7d592e7

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

kernel_gateway/gatewayapp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,18 @@ def init_http_server(self):
562562
'no available port could be found.')
563563
self.exit(1)
564564

565-
def start(self):
566-
"""Starts an IO loop for the application."""
565+
def start_app(self):
566+
"""Starts the application (with ioloop to follow). """
567567
super(KernelGatewayApp, self).start()
568568
self.log.info('Jupyter Kernel Gateway {} is available at http{}://{}:{}'.format(
569569
KernelGatewayApp.version, 's' if self.keyfile else '', self.ip, self.port
570570
))
571+
572+
def start(self):
573+
"""Starts an IO loop for the application."""
574+
575+
self.start_app()
576+
571577
self.io_loop = ioloop.IOLoop.current()
572578

573579
if sys.platform != 'win32':

kernel_gateway/notebook_http/request_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def format_request(bundle, kernel_language=''):
2525
bundle = json.dumps(bundle)
2626
if kernel_language.lower() == 'perl':
2727
statement = "my $REQUEST = {}".format(bundle)
28+
elif kernel_language.lower() == 'bash':
29+
statement = "REQUEST={}".format(bundle)
2830
else:
2931
statement = "REQUEST = {}".format(bundle)
3032
return statement

kernel_gateway/tests/notebook_http/test_request_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ def test_format_request_with_a_kernel_language_perl(self):
162162
test_request = ('''{"body": "", "headers": {}, "args": {}, "path": {}}''')
163163
request_code = format_request(test_request, 'perl')
164164
self.assertTrue(request_code.startswith("my $REQUEST"), 'Call format_request with a kernel language "perl" was not formatted correctly')
165+
166+
def test_format_request_with_a_kernel_language_bash(self):
167+
test_request = ('''{"body": "", "headers": {}, "args": {}, "path": {}}''')
168+
request_code = format_request(test_request, 'bash')
169+
self.assertTrue(request_code.startswith("REQUEST=\"{"), 'Call format_request with a kernel language "bash" was not formatted correctly')

kernel_gateway/tests/test_gatewayapp.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import logging
77
import nbformat
88
import os
9+
from io import StringIO
910
import unittest
11+
from unittest.mock import patch
1012
from kernel_gateway.gatewayapp import KernelGatewayApp, ioloop
13+
from kernel_gateway import __version__
1114
from ..notebook_http.swagger.handlers import SwaggerSpecHandler
1215
from tornado.testing import AsyncHTTPTestCase, ExpectLog
1316

@@ -101,6 +104,15 @@ def test_load_notebook_local(self):
101104
app.init_configurables()
102105
self.assertEqual(app.seed_notebook, nb_contents)
103106

107+
@patch('sys.stderr', new_callable=StringIO)
108+
def test_start_banner(self, stderr):
109+
110+
app = KernelGatewayApp()
111+
app.init_configurables()
112+
app.start_app()
113+
banner = stderr.getvalue()
114+
self.assertIn(f"Jupyter Kernel Gateway {__version__}", banner)
115+
104116

105117
class TestGatewayAppBase(AsyncHTTPTestCase, ExpectLog):
106118
"""Base class for integration style tests using HTTP/Websockets against an

0 commit comments

Comments
 (0)