Merge pull request #65 from minrk/six

use six instead of IPython.py3compat
This commit is contained in:
Min RK
2014-10-18 20:21:10 -07:00
4 changed files with 27 additions and 10 deletions

View File

@@ -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)

View File

@@ -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):

View File

@@ -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

View File

@@ -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
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