diff --git a/jupyterhub/app.py b/jupyterhub/app.py index 7e47a72f..f3acbb8b 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -9,7 +9,6 @@ import io import logging import os from datetime import datetime -from six import text_type from subprocess import Popen try: @@ -667,8 +666,10 @@ class JupyterHubApp(Application): answer = ask() if answer.startswith('n'): return - - config_text = text_type(self.generate_config_file(), 'utf8') + + config_text = self.generate_config_file() + if isinstance(config_text, bytes): + config_text = config_text.decode('utf8') print("Writing default config to: %s" % self.config_file) with io.open(self.config_file, encoding='utf8', mode='w') as f: f.write(config_text) diff --git a/jupyterhub/orm.py b/jupyterhub/orm.py index 50aa83d8..9b385d97 100644 --- a/jupyterhub/orm.py +++ b/jupyterhub/orm.py @@ -9,6 +9,8 @@ import json import socket import uuid +from six import text_type + from tornado import gen from tornado.log import app_log from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError @@ -24,8 +26,6 @@ from sqlalchemy.orm import sessionmaker, relationship, backref from sqlalchemy.pool import StaticPool from sqlalchemy import create_engine -from IPython.utils.py3compat import str_to_unicode - from .utils import random_port, url_path_join, wait_for_server, wait_for_http_server @@ -34,7 +34,7 @@ def new_token(*args, **kwargs): For now, just UUIDs. """ - return str_to_unicode(uuid.uuid4().hex) + return text_type(uuid.uuid4().hex) class JSONDict(TypeDecorator): diff --git a/jupyterhub/tests/mocking.py b/jupyterhub/tests/mocking.py index 7f844a51..9f771261 100644 --- a/jupyterhub/tests/mocking.py +++ b/jupyterhub/tests/mocking.py @@ -10,7 +10,7 @@ except ImportError: from tornado.ioloop import IOLoop -from IPython.utils.py3compat import unicode_type +from six import text_type from ..spawner import LocalProcessSpawner from ..app import JupyterHubApp @@ -19,9 +19,9 @@ from .. import orm def mock_authenticate(username, password, service='login'): # mimic simplepam's failure to handle unicode - if isinstance(username, unicode_type): + if isinstance(username, text_type): return False - if isinstance(password, unicode_type): + if isinstance(password, text_type): return False # just use equality for testing diff --git a/jupyterhub/tests/test_app.py b/jupyterhub/tests/test_app.py index 5332e9e4..ed31b701 100644 --- a/jupyterhub/tests/test_app.py +++ b/jupyterhub/tests/test_app.py @@ -1,11 +1,27 @@ """Test the JupyterHubApp entry point""" +import io +import os import sys from subprocess import check_output +from tempfile import NamedTemporaryFile def test_help_all(): out = check_output([sys.executable, '-m', 'jupyterhub', '--help-all']).decode('utf8', 'replace') assert u'--ip' in out assert u'--JupyterHubApp.ip' in out - \ No newline at end of file +def test_generate_config(): + with NamedTemporaryFile(prefix='jupyter_hub_config', suffix='.py') as tf: + cfg_file = tf.name + + out = check_output([sys.executable, '-m', 'jupyterhub', + '--generate-config', '-f', cfg_file] + ).decode('utf8', 'replace') + assert os.path.exists(cfg_file) + with io.open(cfg_file) as f: + cfg_text = f.read() + os.remove(cfg_file) + assert cfg_file in out + assert 'Spawner.cmd' in cfg_text + assert 'Authenticator.whitelist' in cfg_text