You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ORPA-pyOpenRPA/Resources/WPy64-3720/python-3.7.2.amd64/Lib/site-packages/jupyter_client/tests/test_kernelapp.py

51 lines
1.5 KiB

import os
import sys
import shutil
import time
from subprocess import Popen, PIPE
from tempfile import mkdtemp
def _launch(extra_env):
env = os.environ.copy()
env.update(extra_env)
return Popen([sys.executable, '-c',
'from jupyter_client.kernelapp import main; main()'],
env=env, stderr=PIPE)
WAIT_TIME = 10
POLL_FREQ = 10
def test_kernelapp_lifecycle():
# Check that 'jupyter kernel' starts and terminates OK.
runtime_dir = mkdtemp()
startup_dir = mkdtemp()
started = os.path.join(startup_dir, 'started')
try:
p = _launch({'JUPYTER_RUNTIME_DIR': runtime_dir,
'JUPYTER_CLIENT_TEST_RECORD_STARTUP_PRIVATE': started,
})
# Wait for start
for _ in range(WAIT_TIME * POLL_FREQ):
if os.path.isfile(started):
break
time.sleep(1 / POLL_FREQ)
else:
raise AssertionError("No started file created in {} seconds"
.format(WAIT_TIME))
# Connection file should be there by now
files = os.listdir(runtime_dir)
assert len(files) == 1
cf = files[0]
assert cf.startswith('kernel')
assert cf.endswith('.json')
# Send SIGTERM to shut down
p.terminate()
_, stderr = p.communicate(timeout=WAIT_TIME)
assert cf in stderr.decode('utf-8', 'replace')
finally:
shutil.rmtree(runtime_dir)
shutil.rmtree(startup_dir)