Skip to content

Commit

Permalink
add test for jupyter console (#6337)
Browse files Browse the repository at this point in the history
  • Loading branch information
EfimovVladimir authored and scottdraves committed Nov 18, 2017
1 parent 7a0bbe2 commit e5ffd79
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
# Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
import sys
import subprocess
import signal
import test_console

here = os.path.abspath(os.path.dirname(__file__))
beakerx_dir = os.path.abspath(os.path.join(here, ".."))
Expand Down Expand Up @@ -57,5 +58,8 @@
os.killpg(os.getpgid(beakerx.pid), signal.SIGKILL)
os.killpg(os.getpgid(webcontrol.pid), signal.SIGKILL)

if not result:
result = test_console.test_lsmagic()

if result:
sys.exit(20)
72 changes: 72 additions & 0 deletions test/test_console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import pexpect

# Start `jupyter console` using pexpect
def start_console():
args = ['console', '--kernel=groovy']
cmd = 'jupyter'
env = os.environ.copy()
env['JUPYTER_CONSOLE_TEST'] = '1'

p = pexpect.spawn(cmd, args=args, env=env)

# timeout
t = 10
p.expect(r'In \[\d+\]', timeout=t)
return p, pexpect, t

# Stop a running `jupyter console`
def stop_console(p, pexpect, t):
# send ctrl-D;ctrl-D to exit
p.sendeof()
p.sendeof()
p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t)
if p.isalive():
p.terminate()

os.system("kill -9 `pgrep -f jupyter`");


def test_lsmagic():
result = 0
p, pexpect, t = start_console()
p.sendline('%lsmagic')
try:
p.expect(r'Available magic commands:', timeout=t)
p.expect(r'%%javascript', timeout=t)
p.expect(r'%%html', timeout=t)
p.expect(r'%%bash', timeout=t)
p.expect(r'%lsmagic', timeout=t)
p.expect(r'%classpath add jar', timeout=t)
p.expect(r'%classpath add mvn', timeout=t)
p.expect(r'%classpath remove', timeout=t)
p.expect(r'%classpath', timeout=t)
p.expect(r'%import static <classpath>', timeout=t)
p.expect(r'%import <classpath>', timeout=t)
p.expect(r'%unimport <classpath>', timeout=t)
p.expect(r'%time', timeout=t)
p.expect(r'%%time', timeout=t)
p.expect(r'%timeit', timeout=t)
p.expect(r'%%timeit', timeout=t)
except Exception as e:
print(e)
result = 1

stop_console(p, pexpect, t)
print("test_lsmagic return code=", result)
return result

0 comments on commit e5ffd79

Please sign in to comment.