Skip to content

Instantly share code, notes, and snippets.

@minrk
Created September 4, 2013 20:26
Show Gist options
  • Save minrk/6442397 to your computer and use it in GitHub Desktop.
Save minrk/6442397 to your computer and use it in GitHub Desktop.
From ba2c0531c0d99df5ed0f9198b7b6e8a9c2a3e3f3 Mon Sep 17 00:00:00 2001
From: MinRK <benjaminrk@gmail.com>
Date: Wed, 28 Aug 2013 09:24:34 -0700
Subject: [PATCH 1/6] ConnectionFileMixin is Configurable
it has `config=True` traits
Currently in master `ipython console -h` will fail because of this.
It doesn't affect 1.0, I'm not sure why.
---
IPython/kernel/connect.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/IPython/kernel/connect.py b/IPython/kernel/connect.py
index 06db190..83167ad 100644
--- a/IPython/kernel/connect.py
+++ b/IPython/kernel/connect.py
@@ -34,14 +34,13 @@
from IPython.external.ssh import tunnel
# IPython imports
-# from IPython.config import Configurable
+from IPython.config import Configurable
from IPython.core.profiledir import ProfileDir
from IPython.utils.localinterfaces import LOCALHOST
from IPython.utils.path import filefind, get_ipython_dir
from IPython.utils.py3compat import str_to_bytes, bytes_to_str
from IPython.utils.traitlets import (
Bool, Integer, Unicode, CaselessStrEnum,
- HasTraits,
)
@@ -383,7 +382,7 @@ def tunnel_to_kernel(connection_info, sshserver, sshkey=None):
port_names = [ "%s_port" % channel for channel in ('shell', 'stdin', 'iopub', 'hb', 'control')]
-class ConnectionFileMixin(HasTraits):
+class ConnectionFileMixin(Configurable):
"""Mixin for configurable classes that work with connection files"""
# The addresses for the communication channels
--
1.8.4
From 26c3ff0cbecae80dcee55837a079ec6400d62d4b Mon Sep 17 00:00:00 2001
From: MinRK <benjaminrk@gmail.com>
Date: Wed, 28 Aug 2013 11:18:02 -0700
Subject: [PATCH 2/6] test that `-h` and `--help-all` work for various IPython
entry points
should help catch when we break these things.
---
IPython/html/tests/test_notebookapp.py | 29 +++++++++++
IPython/nbconvert/tests/test_nbconvertapp.py | 28 ++++++-----
IPython/qt/console/tests/test_app.py | 29 +++++++++++
IPython/terminal/console/tests/test_console.py | 12 ++++-
IPython/terminal/tests/test_help.py | 67 ++++++++++++++++++++++++++
IPython/testing/tools.py | 57 +++++++++++++++++++++-
6 files changed, 208 insertions(+), 14 deletions(-)
create mode 100644 IPython/html/tests/test_notebookapp.py
create mode 100644 IPython/qt/console/tests/test_app.py
create mode 100644 IPython/terminal/tests/test_help.py
diff --git a/IPython/html/tests/test_notebookapp.py b/IPython/html/tests/test_notebookapp.py
new file mode 100644
index 0000000..24c0e62
--- /dev/null
+++ b/IPython/html/tests/test_notebookapp.py
@@ -0,0 +1,29 @@
+"""Test NotebookApp"""
+
+#-----------------------------------------------------------------------------
+# Copyright (C) 2013 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
+# Imports
+#-----------------------------------------------------------------------------
+
+import nose.tools as nt
+
+import IPython.testing.tools as tt
+
+#-----------------------------------------------------------------------------
+# Test functions
+#-----------------------------------------------------------------------------
+
+def test_help_output():
+ """ipython notebook -h works"""
+ tt.help_output_test('notebook')
+
+def test_help_all_output():
+ """ipython notebook --help-all works"""
+ tt.help_all_output_test('notebook')
+
diff --git a/IPython/nbconvert/tests/test_nbconvertapp.py b/IPython/nbconvert/tests/test_nbconvertapp.py
index 1eabe13..9e680f0 100644
--- a/IPython/nbconvert/tests/test_nbconvertapp.py
+++ b/IPython/nbconvert/tests/test_nbconvertapp.py
@@ -1,12 +1,10 @@
-"""
-Contains tests for the nbconvertapp
-"""
+"""Test NbConvertApp"""
+
#-----------------------------------------------------------------------------
-#Copyright (c) 2013, the IPython Development Team.
-#
-#Distributed under the terms of the Modified BSD License.
+# Copyright (C) 2013 The IPython Development Team
#
-#The full license is in the file COPYING.txt, distributed with this software.
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
@@ -18,9 +16,10 @@
from .base import TestsBase
+import IPython.testing.tools as tt
from IPython.testing import decorators as dec
-
+
#-----------------------------------------------------------------------------
# Constants
#-----------------------------------------------------------------------------
@@ -35,13 +34,18 @@ class TestNbConvertApp(TestsBase):
def test_notebook_help(self):
- """
- Will help show if no notebooks are specified?
- """
+ """Will help show if no notebooks are specified?"""
with self.create_temp_cwd():
out, err = self.call('nbconvert --log-level 0', ignore_return_code=True)
- assert "see '--help-all'" in out
+ self.assertIn("see '--help-all'", out)
+
+ def test_help_output(self):
+ """ipython nbconvert -h works"""
+ tt.help_output_test('nbconvert')
+ def test_help_all_output(self):
+ """ipython nbconvert --help-all works"""
+ tt.help_all_output_test('nbconvert')
def test_glob(self):
"""
diff --git a/IPython/qt/console/tests/test_app.py b/IPython/qt/console/tests/test_app.py
new file mode 100644
index 0000000..8a8d446
--- /dev/null
+++ b/IPython/qt/console/tests/test_app.py
@@ -0,0 +1,29 @@
+"""Test QtConsoleApp"""
+
+#-----------------------------------------------------------------------------
+# Copyright (C) 2013 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
+# Imports
+#-----------------------------------------------------------------------------
+
+import nose.tools as nt
+
+import IPython.testing.tools as tt
+
+#-----------------------------------------------------------------------------
+# Test functions
+#-----------------------------------------------------------------------------
+
+def test_help_output():
+ """ipython qtconsole -h works"""
+ tt.help_output_test('qtconsole')
+
+def test_help_all_output():
+ """ipython qtconsole --help-all works"""
+ tt.help_all_output_test('qtconsole')
+
diff --git a/IPython/terminal/console/tests/test_console.py b/IPython/terminal/console/tests/test_console.py
index 60b9679..ab09cec 100644
--- a/IPython/terminal/console/tests/test_console.py
+++ b/IPython/terminal/console/tests/test_console.py
@@ -18,11 +18,12 @@
import nose.tools as nt
from nose import SkipTest
+import IPython.testing.tools as tt
from IPython.testing import decorators as dec
from IPython.utils import py3compat
#-----------------------------------------------------------------------------
-# Test functions begin
+# Tests
#-----------------------------------------------------------------------------
@dec.skip_win32
@@ -55,3 +56,12 @@ def test_console_starts():
p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t)
if p.isalive():
p.terminate()
+
+def test_help_output():
+ """ipython console -h works"""
+ tt.help_output_test('console')
+
+def test_help_all_output():
+ """ipython console --help-all works"""
+ tt.help_all_output_test('console')
+
diff --git a/IPython/terminal/tests/test_help.py b/IPython/terminal/tests/test_help.py
new file mode 100644
index 0000000..f217e20
--- /dev/null
+++ b/IPython/terminal/tests/test_help.py
@@ -0,0 +1,67 @@
+"""Test help output of various IPython entry points"""
+
+#-----------------------------------------------------------------------------
+# Copyright (C) 2013 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
+# Imports
+#-----------------------------------------------------------------------------
+
+from IPython.testing.tools import help, help_all
+
+#-----------------------------------------------------------------------------
+# Tests
+#-----------------------------------------------------------------------------
+
+
+@help()
+def test_ipython_help():
+ pass
+
+@help_all()
+def test_ipython_help_all():
+ pass
+
+@help("profile")
+def test_profile_help():
+ pass
+
+@help_all("profile")
+def test_profile_help_all():
+ pass
+
+@help("profile list")
+def test_profile_list_help():
+ pass
+
+@help_all("profile list")
+def test_profile_list_help_all():
+ pass
+
+@help("profile create")
+def test_profile_create_help():
+ pass
+
+@help_all("profile create")
+def test_profile_create_help_all():
+ pass
+
+@help("locate")
+def test_locate_help():
+ pass
+
+@help_all("locate")
+def test_locate_help_all():
+ pass
+
+@help("locate profile")
+def test_locate_profile_help():
+ pass
+
+@help_all("locate profile")
+def test_locate_profile_all():
+ pass
diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py
index 696c655..45c2034 100644
--- a/IPython/testing/tools.py
+++ b/IPython/testing/tools.py
@@ -8,7 +8,7 @@
from __future__ import absolute_import
#-----------------------------------------------------------------------------
-# Copyright (C) 2009-2011 The IPython Development Team
+# Copyright (C) 2009 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
@@ -18,6 +18,7 @@
# Imports
#-----------------------------------------------------------------------------
+import inspect
import os
import re
import sys
@@ -37,6 +38,7 @@
has_nose = False
from IPython.config.loader import Config
+from IPython.utils.process import get_output_error_code
from IPython.utils.text import list_strings
from IPython.utils.io import temp_pyfile, Tee
from IPython.utils import py3compat
@@ -408,3 +410,56 @@ def monkeypatch(obj, name, attr):
setattr(obj, name, attr)
yield
setattr(obj, name, orig)
+
+
+def help_output_test(subcommand=''):
+ """test that `ipython [subcommand] -h` works"""
+ cmd = ' '.join(get_ipython_cmd() + [subcommand, '-h'])
+ out, err, rc = get_output_error_code(cmd)
+ nt.assert_equal(rc, 0, err)
+ nt.assert_not_in("Traceback", err)
+ nt.assert_in("Options", out)
+ nt.assert_in("--help-all", out)
+ return out, err
+
+
+def help_all_output_test(subcommand=''):
+ """test that `ipython [subcommand] --help-all` works"""
+ cmd = ' '.join(get_ipython_cmd() + [subcommand, '--help-all'])
+ out, err, rc = get_output_error_code(cmd)
+ nt.assert_equal(rc, 0, err)
+ nt.assert_not_in("Traceback", err)
+ nt.assert_in("Options", out)
+ nt.assert_in("Class parameters", out)
+ return out, err
+
+
+def help(cmd=''):
+ """decorator for making a test for `ipython cmd -h`"""
+ def wrap_help_test(f):
+ def test_help_output():
+ out, err = help_output_test(cmd)
+ if inspect.getargspec(f).args:
+ return f(out, err)
+ else:
+ return f()
+ cmds = cmd + ' ' if cmd else ''
+ test_help_output.__doc__ = "ipython {cmds}--help-all works".format(cmds=cmds)
+
+ return test_help_output
+ return wrap_help_test
+
+
+def help_all(cmd=''):
+ """decorator for making a test for `ipython [cmd] --help-all`"""
+ def wrap_help_test(f):
+ def test_help_output():
+ out, err = help_all_output_test(cmd)
+ if inspect.getargspec(f).args:
+ return f(out, err)
+ else:
+ return f()
+ cmds = cmd + ' ' if cmd else ''
+ test_help_output.__doc__ = "ipython {cmds}--help-all works".format(cmds=cmds)
+ return test_help_output
+ return wrap_help_test
--
1.8.4
From 45c2f7b3a821bbb37871823a894ebbabf646b400 Mon Sep 17 00:00:00 2001
From: MinRK <benjaminrk@gmail.com>
Date: Wed, 28 Aug 2013 12:40:51 -0700
Subject: [PATCH 4/6] de-decorate help output tests
---
IPython/terminal/tests/test_help.py | 38 +++++++++++++------------------------
IPython/testing/tools.py | 30 -----------------------------
2 files changed, 13 insertions(+), 55 deletions(-)
diff --git a/IPython/terminal/tests/test_help.py b/IPython/terminal/tests/test_help.py
index f217e20..d21c4fb 100644
--- a/IPython/terminal/tests/test_help.py
+++ b/IPython/terminal/tests/test_help.py
@@ -11,57 +11,45 @@
# Imports
#-----------------------------------------------------------------------------
-from IPython.testing.tools import help, help_all
+import IPython.testing.tools as tt
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
-@help()
def test_ipython_help():
- pass
+ tt.help_output_test()
-@help_all()
def test_ipython_help_all():
- pass
+ tt.help_all_output_test()
-@help("profile")
def test_profile_help():
- pass
+ tt.help_output_test("profile")
-@help_all("profile")
def test_profile_help_all():
- pass
+ tt.help_all_output_test("profile")
-@help("profile list")
def test_profile_list_help():
- pass
+ tt.help_output_test("profile list")
-@help_all("profile list")
def test_profile_list_help_all():
- pass
+ tt.help_all_output_test("profile list")
-@help("profile create")
def test_profile_create_help():
- pass
+ tt.help_output_test("profile create")
-@help_all("profile create")
def test_profile_create_help_all():
- pass
+ tt.help_all_output_test("profile create")
-@help("locate")
def test_locate_help():
- pass
+ tt.help_output_test("locate")
-@help_all("locate")
def test_locate_help_all():
- pass
+ tt.help_all_output_test("locate")
-@help("locate profile")
def test_locate_profile_help():
- pass
+ tt.help_output_test("locate profile")
-@help_all("locate profile")
def test_locate_profile_all():
- pass
+ tt.help_all_output_test("locate profile")
diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py
index 45c2034..f397c11 100644
--- a/IPython/testing/tools.py
+++ b/IPython/testing/tools.py
@@ -433,33 +433,3 @@ def help_all_output_test(subcommand=''):
nt.assert_in("Class parameters", out)
return out, err
-
-def help(cmd=''):
- """decorator for making a test for `ipython cmd -h`"""
- def wrap_help_test(f):
- def test_help_output():
- out, err = help_output_test(cmd)
- if inspect.getargspec(f).args:
- return f(out, err)
- else:
- return f()
- cmds = cmd + ' ' if cmd else ''
- test_help_output.__doc__ = "ipython {cmds}--help-all works".format(cmds=cmds)
-
- return test_help_output
- return wrap_help_test
-
-
-def help_all(cmd=''):
- """decorator for making a test for `ipython [cmd] --help-all`"""
- def wrap_help_test(f):
- def test_help_output():
- out, err = help_all_output_test(cmd)
- if inspect.getargspec(f).args:
- return f(out, err)
- else:
- return f()
- cmds = cmd + ' ' if cmd else ''
- test_help_output.__doc__ = "ipython {cmds}--help-all works".format(cmds=cmds)
- return test_help_output
- return wrap_help_test
--
1.8.4
From 150bcc8ad98ad813a4c988543c10bf292f8a94b1 Mon Sep 17 00:00:00 2001
From: MinRK <benjaminrk@gmail.com>
Date: Thu, 29 Aug 2013 17:24:04 -0700
Subject: [PATCH 5/6] only test `--help-all`
help-all is a superset of `-h`, so no need to do both,
since these tests are slow.
---
IPython/html/tests/test_notebookapp.py | 4 ----
IPython/kernel/tests/test_kernel.py | 8 ++++++--
IPython/nbconvert/tests/test_nbconvertapp.py | 4 ----
IPython/qt/console/tests/test_app.py | 4 ----
IPython/terminal/console/tests/test_console.py | 4 ----
IPython/terminal/tests/test_help.py | 18 ------------------
6 files changed, 6 insertions(+), 36 deletions(-)
diff --git a/IPython/html/tests/test_notebookapp.py b/IPython/html/tests/test_notebookapp.py
index 24c0e62..56509cd 100644
--- a/IPython/html/tests/test_notebookapp.py
+++ b/IPython/html/tests/test_notebookapp.py
@@ -20,10 +20,6 @@
#-----------------------------------------------------------------------------
def test_help_output():
- """ipython notebook -h works"""
- tt.help_output_test('notebook')
-
-def test_help_all_output():
"""ipython notebook --help-all works"""
tt.help_all_output_test('notebook')
diff --git a/IPython/kernel/tests/test_kernel.py b/IPython/kernel/tests/test_kernel.py
index 253ce15..6859eda 100644
--- a/IPython/kernel/tests/test_kernel.py
+++ b/IPython/kernel/tests/test_kernel.py
@@ -23,7 +23,7 @@
from IPython.kernel import KernelManager
from IPython.kernel.tests.test_message_spec import execute, flush_channels
-from IPython.testing import decorators as dec
+from IPython.testing import decorators as dec, tools as tt
from IPython.utils import path, py3compat
#-------------------------------------------------------------------------------
@@ -206,7 +206,6 @@ def test_subprocess_error():
_check_mp_mode(kc, expected=False)
_check_mp_mode(kc, expected=False, stream="stderr")
-
# raw_input tests
def test_raw_input():
@@ -250,3 +249,8 @@ def test_eval_input():
stdout, stderr = assemble_output(iopub)
nt.assert_equal(stdout, "2\n")
+
+def test_help_output():
+ """ipython kernel --help-all works"""
+ tt.help_all_output_test('kernel')
+
diff --git a/IPython/nbconvert/tests/test_nbconvertapp.py b/IPython/nbconvert/tests/test_nbconvertapp.py
index 9e680f0..6fa82b9 100644
--- a/IPython/nbconvert/tests/test_nbconvertapp.py
+++ b/IPython/nbconvert/tests/test_nbconvertapp.py
@@ -40,10 +40,6 @@ def test_notebook_help(self):
self.assertIn("see '--help-all'", out)
def test_help_output(self):
- """ipython nbconvert -h works"""
- tt.help_output_test('nbconvert')
-
- def test_help_all_output(self):
"""ipython nbconvert --help-all works"""
tt.help_all_output_test('nbconvert')
diff --git a/IPython/qt/console/tests/test_app.py b/IPython/qt/console/tests/test_app.py
index 8a8d446..d28596e 100644
--- a/IPython/qt/console/tests/test_app.py
+++ b/IPython/qt/console/tests/test_app.py
@@ -20,10 +20,6 @@
#-----------------------------------------------------------------------------
def test_help_output():
- """ipython qtconsole -h works"""
- tt.help_output_test('qtconsole')
-
-def test_help_all_output():
"""ipython qtconsole --help-all works"""
tt.help_all_output_test('qtconsole')
diff --git a/IPython/terminal/console/tests/test_console.py b/IPython/terminal/console/tests/test_console.py
index ab09cec..09351a0 100644
--- a/IPython/terminal/console/tests/test_console.py
+++ b/IPython/terminal/console/tests/test_console.py
@@ -58,10 +58,6 @@ def test_console_starts():
p.terminate()
def test_help_output():
- """ipython console -h works"""
- tt.help_output_test('console')
-
-def test_help_all_output():
"""ipython console --help-all works"""
tt.help_all_output_test('console')
diff --git a/IPython/terminal/tests/test_help.py b/IPython/terminal/tests/test_help.py
index d21c4fb..1c45093 100644
--- a/IPython/terminal/tests/test_help.py
+++ b/IPython/terminal/tests/test_help.py
@@ -19,37 +19,19 @@
def test_ipython_help():
- tt.help_output_test()
-
-def test_ipython_help_all():
tt.help_all_output_test()
def test_profile_help():
- tt.help_output_test("profile")
-
-def test_profile_help_all():
tt.help_all_output_test("profile")
def test_profile_list_help():
- tt.help_output_test("profile list")
-
-def test_profile_list_help_all():
tt.help_all_output_test("profile list")
def test_profile_create_help():
- tt.help_output_test("profile create")
-
-def test_profile_create_help_all():
tt.help_all_output_test("profile create")
def test_locate_help():
- tt.help_output_test("locate")
-
-def test_locate_help_all():
tt.help_all_output_test("locate")
def test_locate_profile_help():
- tt.help_output_test("locate profile")
-
-def test_locate_profile_all():
tt.help_all_output_test("locate profile")
--
1.8.4
From 3294e4a1f158f110cbda0d4af4be0091f20cecf4 Mon Sep 17 00:00:00 2001
From: MinRK <benjaminrk@gmail.com>
Date: Thu, 29 Aug 2013 17:37:51 -0700
Subject: [PATCH 6/6] add missing ProfileDir to nbconvertapp.classes
---
IPython/nbconvert/nbconvertapp.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py
index e01eee3..08bc0b8 100755
--- a/IPython/nbconvert/nbconvertapp.py
+++ b/IPython/nbconvert/nbconvertapp.py
@@ -25,6 +25,7 @@
# From IPython
from IPython.core.application import BaseIPythonApplication, base_aliases, base_flags
+from IPython.core.profiledir import ProfileDir
from IPython.config import catch_config_error, Configurable
from IPython.utils.traitlets import (
Unicode, List, Instance, DottedObjectName, Type, CaselessStrEnum,
@@ -85,12 +86,13 @@ def _log_level_default(self):
return logging.INFO
def _classes_default(self):
- classes = [NbConvertBase]
+ classes = [NbConvertBase, ProfileDir]
for pkg in (exporters, transformers, writers):
for name in dir(pkg):
cls = getattr(pkg, name)
if isinstance(cls, type) and issubclass(cls, Configurable):
classes.append(cls)
+
return classes
description = Unicode(
--
1.8.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment