diff --git a/IPython/core/tests/test_magic_arguments.py b/IPython/core/tests/test_magic_arguments.py index 5d667d6..dc970ae 100644 --- a/IPython/core/tests/test_magic_arguments.py +++ b/IPython/core/tests/test_magic_arguments.py @@ -6,12 +6,11 @@ # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- -from nose.tools import assert_equal, assert_true +from nose.tools import assert_equal from IPython.external import argparse from IPython.core.magic_arguments import (argument, argument_group, kwds, magic_arguments, parse_argstring, real_name) -from IPython.testing.decorators import parametric @magic_arguments() @@ -74,48 +73,46 @@ def foo(self, args): return parse_argstring(foo, args) -@parametric def test_magic_arguments(): - # Ideally, these would be doctests, but I could not get it to work. - yield assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') - yield assert_equal(getattr(magic_foo1, 'argcmd_name', None), None) - yield assert_equal(real_name(magic_foo1), 'foo1') - yield assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None)) - yield assert_true(hasattr(magic_foo1, 'has_arguments')) - - yield assert_equal(magic_foo2.__doc__, '%foo2\n\n A docstring.\n') - yield assert_equal(getattr(magic_foo2, 'argcmd_name', None), None) - yield assert_equal(real_name(magic_foo2), 'foo2') - yield assert_equal(magic_foo2(None, ''), argparse.Namespace()) - yield assert_true(hasattr(magic_foo2, 'has_arguments')) - - yield assert_equal(magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n') - yield assert_equal(getattr(magic_foo3, 'argcmd_name', None), None) - yield assert_equal(real_name(magic_foo3), 'foo3') - yield assert_equal(magic_foo3(None, ''), + assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') + assert_equal(getattr(magic_foo1, 'argcmd_name', None), None) + assert_equal(real_name(magic_foo1), 'foo1') + assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None)) + assert hasattr(magic_foo1, 'has_arguments') + + assert_equal(magic_foo2.__doc__, '%foo2\n\n A docstring.\n') + assert_equal(getattr(magic_foo2, 'argcmd_name', None), None) + assert_equal(real_name(magic_foo2), 'foo2') + assert_equal(magic_foo2(None, ''), argparse.Namespace()) + assert hasattr(magic_foo2, 'has_arguments') + + assert_equal(magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n') + assert_equal(getattr(magic_foo3, 'argcmd_name', None), None) + assert_equal(real_name(magic_foo3), 'foo3') + assert_equal(magic_foo3(None, ''), argparse.Namespace(bar=None, baz=None, foo=None)) - yield assert_true(hasattr(magic_foo3, 'has_arguments')) - - yield assert_equal(magic_foo4.__doc__, '%foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') - yield assert_equal(getattr(magic_foo4, 'argcmd_name', None), None) - yield assert_equal(real_name(magic_foo4), 'foo4') - yield assert_equal(magic_foo4(None, ''), argparse.Namespace()) - yield assert_true(hasattr(magic_foo4, 'has_arguments')) - - yield assert_equal(magic_foo5.__doc__, '%frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') - yield assert_equal(getattr(magic_foo5, 'argcmd_name', None), 'frobnicate') - yield assert_equal(real_name(magic_foo5), 'frobnicate') - yield assert_equal(magic_foo5(None, ''), argparse.Namespace(foo=None)) - yield assert_true(hasattr(magic_foo5, 'has_arguments')) - - yield assert_equal(magic_magic_foo.__doc__, '%magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') - yield assert_equal(getattr(magic_magic_foo, 'argcmd_name', None), None) - yield assert_equal(real_name(magic_magic_foo), 'magic_foo') - yield assert_equal(magic_magic_foo(None, ''), argparse.Namespace(foo=None)) - yield assert_true(hasattr(magic_magic_foo, 'has_arguments')) - - yield assert_equal(foo.__doc__, '%foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') - yield assert_equal(getattr(foo, 'argcmd_name', None), None) - yield assert_equal(real_name(foo), 'foo') - yield assert_equal(foo(None, ''), argparse.Namespace(foo=None)) - yield assert_true(hasattr(foo, 'has_arguments')) + assert hasattr(magic_foo3, 'has_arguments') + + assert_equal(magic_foo4.__doc__, '%foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') + assert_equal(getattr(magic_foo4, 'argcmd_name', None), None) + assert_equal(real_name(magic_foo4), 'foo4') + assert_equal(magic_foo4(None, ''), argparse.Namespace()) + assert hasattr(magic_foo4, 'has_arguments') + + assert_equal(magic_foo5.__doc__, '%frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') + assert_equal(getattr(magic_foo5, 'argcmd_name', None), 'frobnicate') + assert_equal(real_name(magic_foo5), 'frobnicate') + assert_equal(magic_foo5(None, ''), argparse.Namespace(foo=None)) + assert hasattr(magic_foo5, 'has_arguments') + + assert_equal(magic_magic_foo.__doc__, '%magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') + assert_equal(getattr(magic_magic_foo, 'argcmd_name', None), None) + assert_equal(real_name(magic_magic_foo), 'magic_foo') + assert_equal(magic_magic_foo(None, ''), argparse.Namespace(foo=None)) + assert hasattr(magic_magic_foo, 'has_arguments') + + assert_equal(foo.__doc__, '%foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') + assert_equal(getattr(foo, 'argcmd_name', None), None) + assert_equal(real_name(foo), 'foo') + assert_equal(foo(None, ''), argparse.Namespace(foo=None)) + assert hasattr(foo, 'has_arguments') diff --git a/IPython/core/tests/test_prefilter.py b/IPython/core/tests/test_prefilter.py index 6f0b326..b54abf0 100644 --- a/IPython/core/tests/test_prefilter.py +++ b/IPython/core/tests/test_prefilter.py @@ -6,7 +6,6 @@ import nose.tools as nt from IPython.core.prefilter import AutocallChecker -from IPython.testing import decorators as dec from IPython.testing.globalipapp import get_ipython #----------------------------------------------------------------------------- @@ -14,7 +13,6 @@ from IPython.testing.globalipapp import get_ipython #----------------------------------------------------------------------------- ip = get_ipython() -@dec.parametric def test_prefilter(): """Test user input conversions""" @@ -23,19 +21,18 @@ def test_prefilter(): ] for raw, correct in pairs: - yield nt.assert_equal(ip.prefilter(raw), correct) + nt.assert_equal(ip.prefilter(raw), correct) -@dec.parametric def test_autocall_binops(): """See https://github.com/ipython/ipython/issues/81""" ip.magic('autocall 2') f = lambda x: x ip.user_ns['f'] = f try: - yield nt.assert_equal(ip.prefilter('f 1'),'f(1)') + nt.assert_equal(ip.prefilter('f 1'),'f(1)') for t in ['f +1', 'f -1']: - yield nt.assert_equal(ip.prefilter(t), t) + nt.assert_equal(ip.prefilter(t), t) # Run tests again with a more permissive exclude_regexp, which will # allow transformation of binary operations ('f -1' -> 'f(-1)'). @@ -47,8 +44,8 @@ def test_autocall_binops(): ac.exclude_regexp = r'^[,&^\|\*/]|^is |^not |^in |^and |^or ' pm.sort_checkers() - yield nt.assert_equal(ip.prefilter('f -1'), 'f(-1)') - yield nt.assert_equal(ip.prefilter('f +1'), 'f(+1)') + nt.assert_equal(ip.prefilter('f -1'), 'f(-1)') + nt.assert_equal(ip.prefilter('f +1'), 'f(+1)') finally: pm.unregister_checker(ac) finally: @@ -56,7 +53,6 @@ def test_autocall_binops(): del ip.user_ns['f'] -@dec.parametric def test_issue_114(): """Check that multiline string literals don't expand as magic see http://github.com/ipython/ipython/issues/114""" @@ -70,7 +66,7 @@ def test_issue_114(): try: for mgk in ip.magics_manager.lsmagic()['line']: raw = template % mgk - yield nt.assert_equal(ip.prefilter(raw), raw) + nt.assert_equal(ip.prefilter(raw), raw) finally: ip.prefilter_manager.multi_line_specials = msp diff --git a/IPython/core/tests/test_pylabtools.py b/IPython/core/tests/test_pylabtools.py index 4ee672a..a80ed96 100644 --- a/IPython/core/tests/test_pylabtools.py +++ b/IPython/core/tests/test_pylabtools.py @@ -24,7 +24,6 @@ import numpy as np # Our own imports from IPython.core.interactiveshell import InteractiveShell -from IPython.testing import decorators as dec from .. import pylabtools as pt #----------------------------------------------------------------------------- @@ -39,11 +38,10 @@ from .. import pylabtools as pt # Classes and functions #----------------------------------------------------------------------------- -@dec.parametric def test_figure_to_svg(): # simple empty-figure test fig = plt.figure() - yield nt.assert_equal(pt.print_figure(fig, 'svg'), None) + nt.assert_equal(pt.print_figure(fig, 'svg'), None) plt.close('all') @@ -53,7 +51,7 @@ def test_figure_to_svg(): ax.plot([1,2,3]) plt.draw() svg = pt.print_figure(fig, 'svg')[:100].lower() - yield nt.assert_true('doctype svg' in svg) + nt.assert_in('doctype svg', svg) def test_import_pylab(): diff --git a/IPython/external/mathjax.py b/IPython/external/mathjax.py index d222b3d..f98411e 100644 --- a/IPython/external/mathjax.py +++ b/IPython/external/mathjax.py @@ -275,7 +275,7 @@ def main() : if __name__ == '__main__' : sys.exit(main()) -__all__ = ['install_mathjax', 'main', 'dest'] +__all__ = ['install_mathjax', 'main', 'default_dest'] """ Test notes: diff --git a/IPython/kernel/tests/test_launcher.py b/IPython/kernel/tests/test_launcher.py index 5aa069e..0936790 100644 --- a/IPython/kernel/tests/test_launcher.py +++ b/IPython/kernel/tests/test_launcher.py @@ -20,14 +20,12 @@ Authors import nose.tools as nt # Our own imports -from IPython.testing import decorators as dec from IPython.kernel.launcher import swallow_argv #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- -@dec.parametric def test_swallow_argv(): tests = [ # expected , argv , aliases, flags @@ -56,5 +54,5 @@ def test_swallow_argv(): "expected : %r" % expected, "returned : %r" % stripped, ]) - yield nt.assert_equal(expected, stripped, message) + nt.assert_equal(expected, stripped, message) diff --git a/IPython/kernel/tests/test_message_spec.py b/IPython/kernel/tests/test_message_spec.py index f73cfe8..b676498 100644 --- a/IPython/kernel/tests/test_message_spec.py +++ b/IPython/kernel/tests/test_message_spec.py @@ -15,7 +15,6 @@ import nose.tools as nt from IPython.kernel import KernelManager -from IPython.testing import decorators as dec from IPython.utils.traitlets import ( HasTraits, TraitError, Bool, Unicode, Dict, Integer, List, Enum, Any, ) @@ -60,7 +59,7 @@ def flush_channels(kc=None): except Empty: break else: - list(validate_message(msg)) + validate_message(msg) def execute(code='', kc=None, **kwargs): @@ -69,14 +68,14 @@ def execute(code='', kc=None, **kwargs): kc = KC msg_id = kc.execute(code=code, **kwargs) reply = kc.get_shell_msg(timeout=TIMEOUT) - list(validate_message(reply, 'execute_reply', msg_id)) + validate_message(reply, 'execute_reply', msg_id) busy = kc.get_iopub_msg(timeout=TIMEOUT) - list(validate_message(busy, 'status', msg_id)) + validate_message(busy, 'status', msg_id) nt.assert_equal(busy['content']['execution_state'], 'busy') if not kwargs.get('silent'): pyin = kc.get_iopub_msg(timeout=TIMEOUT) - list(validate_message(pyin, 'pyin', msg_id)) + validate_message(pyin, 'pyin', msg_id) nt.assert_equal(pyin['content']['code'], code) return msg_id, reply['content'] @@ -101,14 +100,14 @@ class Reference(HasTraits): def check(self, d): """validate a dict against our traits""" for key in self.trait_names(): - yield nt.assert_true(key in d, "Missing key: %r, should be found in %s" % (key, d)) + nt.assert_in(key, d) # FIXME: always allow None, probably not a good idea if d[key] is None: continue try: setattr(self, key, d[key]) except TraitError as e: - yield nt.assert_true(False, str(e)) + nt.assert_true(False, str(e)) class RMessage(Reference): @@ -133,14 +132,11 @@ class ExecuteReply(Reference): status = Enum((u'ok', u'error')) def check(self, d): - for tst in Reference.check(self, d): - yield tst + Reference.check(self, d) if d['status'] == 'ok': - for tst in ExecuteReplyOkay().check(d): - yield tst + ExecuteReplyOkay().check(d) elif d['status'] == 'error': - for tst in ExecuteReplyError().check(d): - yield tst + ExecuteReplyError().check(d) class ExecuteReplyOkay(Reference): @@ -177,11 +173,9 @@ class OInfoReply(Reference): source = Unicode() def check(self, d): - for tst in Reference.check(self, d): - yield tst + Reference.check(self, d) if d['argspec'] is not None: - for tst in ArgSpec().check(d['argspec']): - yield tst + ArgSpec().check(d['argspec']) class ArgSpec(Reference): @@ -212,10 +206,8 @@ class KernelInfoReply(Reference): def _ipython_version_changed(self, name, old, new): for v in new: - nt.assert_true( - isinstance(v, int) or isinstance(v, basestring), - 'expected int or string as version component, got {0!r}' - .format(v)) + assert isinstance(v, int) or isinstance(v, basestring), \ + 'expected int or string as version component, got {0!r}'.format(v) # IOPub messages @@ -241,8 +233,8 @@ class DisplayData(Reference): data = Dict() def _data_changed(self, name, old, new): for k,v in new.iteritems(): - nt.assert_true(mime_pat.match(k)) - nt.assert_true(isinstance(v, basestring), "expected string data, got %r" % v) + assert mime_pat.match(k) + nt.assert_is_instance(v, basestring) class PyOut(Reference): @@ -250,8 +242,8 @@ class PyOut(Reference): data = Dict() def _data_changed(self, name, old, new): for k,v in new.iteritems(): - nt.assert_true(mime_pat.match(k)) - nt.assert_true(isinstance(v, basestring), "expected string data, got %r" % v) + assert mime_pat.match(k) + nt.assert_is_instance(v, basestring) references = { @@ -282,13 +274,12 @@ def validate_message(msg, msg_type=None, parent=None): """ RMessage().check(msg) if msg_type: - yield nt.assert_equal(msg['msg_type'], msg_type) + nt.assert_equal(msg['msg_type'], msg_type) if parent: - yield nt.assert_equal(msg['parent_header']['msg_id'], parent) + nt.assert_equal(msg['parent_header']['msg_id'], parent) content = msg['content'] ref = references[msg['msg_type']] - for tst in ref.check(content): - yield tst + ref.check(content) #----------------------------------------------------------------------------- @@ -297,54 +288,47 @@ def validate_message(msg, msg_type=None, parent=None): # Shell channel -@dec.parametric def test_execute(): flush_channels() msg_id = KC.execute(code='x=1') reply = KC.get_shell_msg(timeout=TIMEOUT) - for tst in validate_message(reply, 'execute_reply', msg_id): - yield tst + validate_message(reply, 'execute_reply', msg_id) -@dec.parametric def test_execute_silent(): flush_channels() msg_id, reply = execute(code='x=1', silent=True) # flush status=idle status = KC.iopub_channel.get_msg(timeout=TIMEOUT) - for tst in validate_message(status, 'status', msg_id): - yield tst + validate_message(status, 'status', msg_id) nt.assert_equal(status['content']['execution_state'], 'idle') - yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1) + nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1) count = reply['execution_count'] msg_id, reply = execute(code='x=2', silent=True) # flush status=idle status = KC.iopub_channel.get_msg(timeout=TIMEOUT) - for tst in validate_message(status, 'status', msg_id): - yield tst - yield nt.assert_equal(status['content']['execution_state'], 'idle') + validate_message(status, 'status', msg_id) + nt.assert_equal(status['content']['execution_state'], 'idle') - yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1) + nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1) count_2 = reply['execution_count'] - yield nt.assert_equal(count_2, count) + nt.assert_equal(count_2, count) -@dec.parametric def test_execute_error(): flush_channels() msg_id, reply = execute(code='1/0') - yield nt.assert_equal(reply['status'], 'error') - yield nt.assert_equal(reply['ename'], 'ZeroDivisionError') + nt.assert_equal(reply['status'], 'error') + nt.assert_equal(reply['ename'], 'ZeroDivisionError') pyerr = KC.iopub_channel.get_msg(timeout=TIMEOUT) - for tst in validate_message(pyerr, 'pyerr', msg_id): - yield tst + validate_message(pyerr, 'pyerr', msg_id) def test_execute_inc(): @@ -405,17 +389,14 @@ def test_user_expressions_fail(): nt.assert_equal(foo['ename'], 'NameError') -@dec.parametric def test_oinfo(): flush_channels() msg_id = KC.object_info('a') reply = KC.get_shell_msg(timeout=TIMEOUT) - for tst in validate_message(reply, 'object_info_reply', msg_id): - yield tst + validate_message(reply, 'object_info_reply', msg_id) -@dec.parametric def test_oinfo_found(): flush_channels() @@ -423,15 +404,13 @@ def test_oinfo_found(): msg_id = KC.object_info('a') reply = KC.get_shell_msg(timeout=TIMEOUT) - for tst in validate_message(reply, 'object_info_reply', msg_id): - yield tst + validate_message(reply, 'object_info_reply', msg_id) content = reply['content'] - yield nt.assert_true(content['found']) + assert content['found'] argspec = content['argspec'] - yield nt.assert_true(argspec is None, "didn't expect argspec dict, got %r" % argspec) + nt.assert_is(argspec, None) -@dec.parametric def test_oinfo_detail(): flush_channels() @@ -439,28 +418,24 @@ def test_oinfo_detail(): msg_id = KC.object_info('ip.object_inspect', detail_level=2) reply = KC.get_shell_msg(timeout=TIMEOUT) - for tst in validate_message(reply, 'object_info_reply', msg_id): - yield tst + validate_message(reply, 'object_info_reply', msg_id) content = reply['content'] - yield nt.assert_true(content['found']) + assert content['found'] argspec = content['argspec'] - yield nt.assert_true(isinstance(argspec, dict), "expected non-empty argspec dict, got %r" % argspec) - yield nt.assert_equal(argspec['defaults'], [0]) + nt.assert_is_instance(argspec, dict, "expected non-empty argspec dict, got %r" % argspec) + nt.assert_equal(argspec['defaults'], [0]) -@dec.parametric def test_oinfo_not_found(): flush_channels() msg_id = KC.object_info('dne') reply = KC.get_shell_msg(timeout=TIMEOUT) - for tst in validate_message(reply, 'object_info_reply', msg_id): - yield tst + validate_message(reply, 'object_info_reply', msg_id) content = reply['content'] - yield nt.assert_false(content['found']) + nt.assert_false(content['found']) -@dec.parametric def test_complete(): flush_channels() @@ -468,49 +443,42 @@ def test_complete(): msg_id = KC.complete('al', 'al', 2) reply = KC.get_shell_msg(timeout=TIMEOUT) - for tst in validate_message(reply, 'complete_reply', msg_id): - yield tst + validate_message(reply, 'complete_reply', msg_id) matches = reply['content']['matches'] for name in ('alpha', 'albert'): - yield nt.assert_true(name in matches, "Missing match: %r" % name) + nt.assert_in(name, matches) -@dec.parametric def test_kernel_info_request(): flush_channels() msg_id = KC.kernel_info() reply = KC.get_shell_msg(timeout=TIMEOUT) - for tst in validate_message(reply, 'kernel_info_reply', msg_id): - yield tst + validate_message(reply, 'kernel_info_reply', msg_id) # IOPub channel -@dec.parametric def test_stream(): flush_channels() msg_id, reply = execute("print('hi')") stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT) - for tst in validate_message(stdout, 'stream', msg_id): - yield tst + validate_message(stdout, 'stream', msg_id) content = stdout['content'] - yield nt.assert_equal(content['name'], u'stdout') - yield nt.assert_equal(content['data'], u'hi\n') + nt.assert_equal(content['name'], u'stdout') + nt.assert_equal(content['data'], u'hi\n') -@dec.parametric def test_display_data(): flush_channels() msg_id, reply = execute("from IPython.core.display import display; display(1)") display = KC.iopub_channel.get_msg(timeout=TIMEOUT) - for tst in validate_message(display, 'display_data', parent=msg_id): - yield tst + validate_message(display, 'display_data', parent=msg_id) data = display['content']['data'] - yield nt.assert_equal(data['text/plain'], u'1') + nt.assert_equal(data['text/plain'], u'1') diff --git a/IPython/kernel/tests/test_public_api.py b/IPython/kernel/tests/test_public_api.py index 39cd7e7..eee44c0 100644 --- a/IPython/kernel/tests/test_public_api.py +++ b/IPython/kernel/tests/test_public_api.py @@ -14,8 +14,6 @@ Authors import nose.tools as nt -from IPython.testing import decorators as dec - from IPython.kernel import launcher, connect from IPython import kernel @@ -23,25 +21,21 @@ from IPython import kernel # Classes and functions #----------------------------------------------------------------------------- -@dec.parametric def test_kms(): for base in ("", "Multi"): KM = base + "KernelManager" - yield nt.assert_true(KM in dir(kernel), KM) + nt.assert_in(KM, dir(kernel)) -@dec.parametric def test_kcs(): for base in ("", "Blocking"): KM = base + "KernelClient" - yield nt.assert_true(KM in dir(kernel), KM) + nt.assert_in(KM, dir(kernel)) -@dec.parametric def test_launcher(): for name in launcher.__all__: - yield nt.assert_true(name in dir(kernel), name) + nt.assert_in(name, dir(kernel)) -@dec.parametric def test_connect(): for name in connect.__all__: - yield nt.assert_true(name in dir(kernel), name) + nt.assert_in(name, dir(kernel)) diff --git a/IPython/kernel/zmq/tests/test_serialize.py b/IPython/kernel/zmq/tests/test_serialize.py index 65d5b28..c5f0394 100644 --- a/IPython/kernel/zmq/tests/test_serialize.py +++ b/IPython/kernel/zmq/tests/test_serialize.py @@ -46,7 +46,6 @@ DTYPES = ('uint8', 'float64', 'int32', [('g', 'float32')], '|S10') # Tests #------------------------------------------------------------------------------- -@dec.parametric def test_roundtrip_simple(): for obj in [ 'hello', @@ -55,18 +54,16 @@ def test_roundtrip_simple(): (b'123', 'hello'), ]: obj2 = roundtrip(obj) - yield nt.assert_equals(obj, obj2) + nt.assert_equal(obj, obj2) -@dec.parametric def test_roundtrip_nested(): for obj in [ dict(a=range(5), b={1:b'hello'}), [range(5),[range(3),(1,[b'whoda'])]], ]: obj2 = roundtrip(obj) - yield nt.assert_equals(obj, obj2) + nt.assert_equal(obj, obj2) -@dec.parametric def test_roundtrip_buffered(): for obj in [ dict(a=b"x"*1025), @@ -74,10 +71,10 @@ def test_roundtrip_buffered(): [b"hello"*501, 1,2,3] ]: bufs = serialize_object(obj) - yield nt.assert_equals(len(bufs), 2) + nt.assert_equal(len(bufs), 2) obj2, remainder = unserialize_object(bufs) - yield nt.assert_equals(remainder, []) - yield nt.assert_equals(obj, obj2) + nt.assert_equal(remainder, []) + nt.assert_equal(obj, obj2) def _scrub_nan(A): """scrub nans out of empty arrays @@ -93,7 +90,6 @@ def _scrub_nan(A): # e.g. str dtype pass -@dec.parametric @dec.skip_without('numpy') def test_numpy(): import numpy @@ -104,12 +100,11 @@ def test_numpy(): _scrub_nan(A) bufs = serialize_object(A) B, r = unserialize_object(bufs) - yield nt.assert_equals(r, []) - yield nt.assert_equals(A.shape, B.shape) - yield nt.assert_equals(A.dtype, B.dtype) - yield assert_array_equal(A,B) + nt.assert_equal(r, []) + nt.assert_equal(A.shape, B.shape) + nt.assert_equal(A.dtype, B.dtype) + assert_array_equal(A,B) -@dec.parametric @dec.skip_without('numpy') def test_recarray(): import numpy @@ -124,12 +119,11 @@ def test_recarray(): bufs = serialize_object(A) B, r = unserialize_object(bufs) - yield nt.assert_equals(r, []) - yield nt.assert_equals(A.shape, B.shape) - yield nt.assert_equals(A.dtype, B.dtype) - yield assert_array_equal(A,B) + nt.assert_equal(r, []) + nt.assert_equal(A.shape, B.shape) + nt.assert_equal(A.dtype, B.dtype) + assert_array_equal(A,B) -@dec.parametric @dec.skip_without('numpy') def test_numpy_in_seq(): import numpy @@ -140,15 +134,14 @@ def test_numpy_in_seq(): _scrub_nan(A) bufs = serialize_object((A,1,2,b'hello')) canned = pickle.loads(bufs[0]) - yield nt.assert_true(canned[0], CannedArray) + nt.assert_is_instance(canned[0], CannedArray) tup, r = unserialize_object(bufs) B = tup[0] - yield nt.assert_equals(r, []) - yield nt.assert_equals(A.shape, B.shape) - yield nt.assert_equals(A.dtype, B.dtype) - yield assert_array_equal(A,B) + nt.assert_equal(r, []) + nt.assert_equal(A.shape, B.shape) + nt.assert_equal(A.dtype, B.dtype) + assert_array_equal(A,B) -@dec.parametric @dec.skip_without('numpy') def test_numpy_in_dict(): import numpy @@ -159,27 +152,25 @@ def test_numpy_in_dict(): _scrub_nan(A) bufs = serialize_object(dict(a=A,b=1,c=range(20))) canned = pickle.loads(bufs[0]) - yield nt.assert_true(canned['a'], CannedArray) + nt.assert_is_instance(canned['a'], CannedArray) d, r = unserialize_object(bufs) B = d['a'] - yield nt.assert_equals(r, []) - yield nt.assert_equals(A.shape, B.shape) - yield nt.assert_equals(A.dtype, B.dtype) - yield assert_array_equal(A,B) + nt.assert_equal(r, []) + nt.assert_equal(A.shape, B.shape) + nt.assert_equal(A.dtype, B.dtype) + assert_array_equal(A,B) -@dec.parametric def test_class(): @interactive class C(object): a=5 bufs = serialize_object(dict(C=C)) canned = pickle.loads(bufs[0]) - yield nt.assert_true(canned['C'], CannedClass) + nt.assert_is_instance(canned['C'], CannedClass) d, r = unserialize_object(bufs) C2 = d['C'] - yield nt.assert_equal(C2.a, C.a) + nt.assert_equal(C2.a, C.a) -@dec.parametric def test_class_oldstyle(): @interactive class C: @@ -187,42 +178,38 @@ def test_class_oldstyle(): bufs = serialize_object(dict(C=C)) canned = pickle.loads(bufs[0]) - yield nt.assert_true(isinstance(canned['C'], CannedClass)) + nt.assert_is_instance(canned['C'], CannedClass) d, r = unserialize_object(bufs) C2 = d['C'] - yield nt.assert_equal(C2.a, C.a) + nt.assert_equal(C2.a, C.a) -@dec.parametric def test_tuple(): tup = (lambda x:x, 1) bufs = serialize_object(tup) canned = pickle.loads(bufs[0]) - yield nt.assert_true(isinstance(canned, tuple)) + nt.assert_is_instance(canned, tuple) t2, r = unserialize_object(bufs) - yield nt.assert_equal(t2[0](t2[1]), tup[0](tup[1])) + nt.assert_equal(t2[0](t2[1]), tup[0](tup[1])) point = namedtuple('point', 'x y') -@dec.parametric def test_namedtuple(): p = point(1,2) bufs = serialize_object(p) canned = pickle.loads(bufs[0]) - yield nt.assert_true(isinstance(canned, point)) + nt.assert_is_instance(canned, point) p2, r = unserialize_object(bufs, globals()) - yield nt.assert_equal(p2.x, p.x) - yield nt.assert_equal(p2.y, p.y) + nt.assert_equal(p2.x, p.x) + nt.assert_equal(p2.y, p.y) -@dec.parametric def test_list(): lis = [lambda x:x, 1] bufs = serialize_object(lis) canned = pickle.loads(bufs[0]) - yield nt.assert_true(isinstance(canned, list)) + nt.assert_is_instance(canned, list) l2, r = unserialize_object(bufs) - yield nt.assert_equal(l2[0](l2[1]), lis[0](lis[1])) + nt.assert_equal(l2[0](l2[1]), lis[0](lis[1])) -@dec.parametric def test_class_inheritance(): @interactive class C(object): @@ -234,8 +221,8 @@ def test_class_inheritance(): bufs = serialize_object(dict(D=D)) canned = pickle.loads(bufs[0]) - yield nt.assert_true(canned['D'], CannedClass) + nt.assert_is_instance(canned['D'], CannedClass) d, r = unserialize_object(bufs) D2 = d['D'] - yield nt.assert_equal(D2.a, D.a) - yield nt.assert_equal(D2.b, D.b) + nt.assert_equal(D2.a, D.a) + nt.assert_equal(D2.b, D.b) diff --git a/IPython/nbconvert/filters/tests/test_ansi.py b/IPython/nbconvert/filters/tests/test_ansi.py index c6d9d17..e24c10c 100644 --- a/IPython/nbconvert/filters/tests/test_ansi.py +++ b/IPython/nbconvert/filters/tests/test_ansi.py @@ -39,7 +39,7 @@ class TestAnsi(TestsBase): 'hello' : 'hello'} for inval, outval in correct_outputs.items(): - yield self._try_strip_ansi(inval, outval) + self._try_strip_ansi(inval, outval) def _try_strip_ansi(self, inval, outval): @@ -58,7 +58,7 @@ class TestAnsi(TestsBase): 'hello' : 'hello'} for inval, outval in correct_outputs.items(): - yield self._try_ansi2html(inval, outval) + self._try_ansi2html(inval, outval) def _try_ansi2html(self, inval, outval): @@ -77,7 +77,7 @@ class TestAnsi(TestsBase): 'hello' : 'hello'} for inval, outval in correct_outputs.items(): - yield self._try_ansi2latex(inval, outval) + self._try_ansi2latex(inval, outval) def _try_ansi2latex(self, inval, outval): diff --git a/IPython/nbconvert/filters/tests/test_highlight.py b/IPython/nbconvert/filters/tests/test_highlight.py index 04f9107..df25a42 100644 --- a/IPython/nbconvert/filters/tests/test_highlight.py +++ b/IPython/nbconvert/filters/tests/test_highlight.py @@ -49,13 +49,13 @@ class TestHighlight(TestsBase): def test_highlight2html(self): """highlight2html test""" for index, test in enumerate(self.tests): - yield self._try_highlight(highlight2html, test, self.tokens[index]) + self._try_highlight(highlight2html, test, self.tokens[index]) def test_highlight2latex(self): """highlight2latex test""" for index, test in enumerate(self.tests): - yield self._try_highlight(highlight2latex, test, self.tokens[index]) + self._try_highlight(highlight2latex, test, self.tokens[index]) def _try_highlight(self, method, test, tokens): diff --git a/IPython/nbconvert/filters/tests/test_latex.py b/IPython/nbconvert/filters/tests/test_latex.py index ae2914c..282e3c9 100644 --- a/IPython/nbconvert/filters/tests/test_latex.py +++ b/IPython/nbconvert/filters/tests/test_latex.py @@ -35,7 +35,7 @@ class TestLatex(TestsBase): ('','')] for test in tests: - yield self._try_escape_latex(test[0], test[1]) + self._try_escape_latex(test[0], test[1]) def _try_escape_latex(self, test, result): @@ -56,7 +56,7 @@ class TestLatex(TestsBase): ('','')] for test in tests: - yield self._try_strip_math_space(test[0], test[1]) + self._try_strip_math_space(test[0], test[1]) def _try_strip_math_space(self, test, result): diff --git a/IPython/nbconvert/filters/tests/test_markdown.py b/IPython/nbconvert/filters/tests/test_markdown.py index d0b5b3c..54e100a 100644 --- a/IPython/nbconvert/filters/tests/test_markdown.py +++ b/IPython/nbconvert/filters/tests/test_markdown.py @@ -61,14 +61,14 @@ class TestMarkdown(TestsBase): def test_markdown2latex(self): """markdown2latex test""" for index, test in enumerate(self.tests): - yield self._try_markdown(markdown2latex, test, self.tokens[index]) + self._try_markdown(markdown2latex, test, self.tokens[index]) @dec.onlyif_cmds_exist('pandoc') def test_markdown2html(self): """markdown2html test""" for index, test in enumerate(self.tests): - yield self._try_markdown(markdown2html, test, self.tokens[index]) + self._try_markdown(markdown2html, test, self.tokens[index]) @dec.onlyif_cmds_exist('pandoc') @@ -81,7 +81,7 @@ class TestMarkdown(TestsBase): tokens[1] = r'\*\*test' for index, test in enumerate(self.tests): - yield self._try_markdown(markdown2rst, test, tokens[index]) + self._try_markdown(markdown2rst, test, tokens[index]) def _try_markdown(self, method, test, tokens): diff --git a/IPython/nbconvert/filters/tests/test_strings.py b/IPython/nbconvert/filters/tests/test_strings.py index f0739c3..5c64c02 100644 --- a/IPython/nbconvert/filters/tests/test_strings.py +++ b/IPython/nbconvert/filters/tests/test_strings.py @@ -15,7 +15,6 @@ Module with tests for Strings #----------------------------------------------------------------------------- import os -from IPython.testing import decorators as dec from ...tests.base import TestsBase from ..strings import (wrap_text, html2text, add_anchor, strip_dollars, strip_files_prefix, get_lines, comment_lines, ipython2python, posix_path, @@ -36,7 +35,7 @@ class TestStrings(TestsBase): As if the strings were thine, shouldst know of this. """ for length in [30,5,1]: - yield self._confirm_wrap_text(test_text, length) + self._confirm_wrap_text(test_text, length) def _confirm_wrap_text(self, text, length): @@ -73,7 +72,7 @@ class TestStrings(TestsBase): ('Hello', 'Hello'), ('W$o$rld', 'W$o$rld')] for test in tests: - yield self._try_strip_dollars(test[0], test[1]) + self._try_strip_dollars(test[0], test[1]) def _try_strip_dollars(self, test, result): @@ -89,7 +88,7 @@ class TestStrings(TestsBase): ('My files are in `files/`', 'My files are in `files/`'), ('files/test.html', 'files/test.html')] for test in tests: - yield self._try_files_prefix(test[0], test[1]) + self._try_files_prefix(test[0], test[1]) def _try_files_prefix(self, test, result): diff --git a/IPython/nbconvert/tests/base.py b/IPython/nbconvert/tests/base.py index 81df37b..c84cde8 100644 --- a/IPython/nbconvert/tests/base.py +++ b/IPython/nbconvert/tests/base.py @@ -16,12 +16,12 @@ Contains base test class for nbconvert import os import glob import shutil +import unittest import IPython from IPython.utils.tempdir import TemporaryWorkingDirectory from IPython.utils.process import get_output_error_code from IPython.testing.tools import get_ipython_cmd -from IPython.testing.ipunittest import ParametricTestCase # a trailing space allows for simpler concatenation with the other arguments ipy_cmd = get_ipython_cmd(as_string=True) + " " @@ -31,7 +31,7 @@ ipy_cmd = get_ipython_cmd(as_string=True) + " " #----------------------------------------------------------------------------- -class TestsBase(ParametricTestCase): +class TestsBase(unittest.TestCase): """Base tests class. Contains useful fuzzy comparison and nbconvert functions.""" @@ -86,7 +86,7 @@ class TestsBase(ParametricTestCase): For example: Replace "ii" with "i" in the string "Hiiii" yields "Hii" - Another replacement yields "Hi" (the desired output) + Another replacement cds "Hi" (the desired output) Parameters: ----------- diff --git a/IPython/parallel/tests/test_magics.py b/IPython/parallel/tests/test_magics.py index 102e40c..c8ec444 100644 --- a/IPython/parallel/tests/test_magics.py +++ b/IPython/parallel/tests/test_magics.py @@ -17,20 +17,14 @@ Authors: #------------------------------------------------------------------------------- import re -import sys import time -import zmq -from nose import SkipTest from IPython.testing import decorators as dec -from IPython.testing.ipunittest import ParametricTestCase from IPython.utils.io import capture_output from IPython import parallel as pmod -from IPython.parallel import error from IPython.parallel import AsyncResult -from IPython.parallel.util import interactive from IPython.parallel.tests import add_engines @@ -39,7 +33,7 @@ from .clienttest import ClusterTestCase, generate_output def setup(): add_engines(3, total=True) -class TestParallelMagics(ClusterTestCase, ParametricTestCase): +class TestParallelMagics(ClusterTestCase): def test_px_blocking(self): ip = get_ipython() diff --git a/IPython/parallel/tests/test_view.py b/IPython/parallel/tests/test_view.py index 40b0353..3cc704e 100644 --- a/IPython/parallel/tests/test_view.py +++ b/IPython/parallel/tests/test_view.py @@ -22,20 +22,16 @@ import platform import time from collections import namedtuple from tempfile import mktemp -from StringIO import StringIO import zmq -from nose import SkipTest from nose.plugins.attrib import attr from IPython.testing import decorators as dec -from IPython.testing.ipunittest import ParametricTestCase from IPython.utils.io import capture_output from IPython import parallel as pmod from IPython.parallel import error from IPython.parallel import AsyncResult, AsyncHubResult, AsyncMapResult -from IPython.parallel import DirectView from IPython.parallel.util import interactive from IPython.parallel.tests import add_engines @@ -47,7 +43,7 @@ def setup(): point = namedtuple("point", "x y") -class TestView(ClusterTestCase, ParametricTestCase): +class TestView(ClusterTestCase): def setUp(self): # On Win XP, wait for resource cleanup, else parallel test group fails @@ -242,7 +238,7 @@ class TestView(ClusterTestCase, ParametricTestCase): @skip_without('numpy') def test_scatter_gather_numpy(self): import numpy - from numpy.testing.utils import assert_array_equal, assert_array_almost_equal + from numpy.testing.utils import assert_array_equal view = self.client[:] a = numpy.arange(64) view.scatter('a', a, block=True) @@ -280,7 +276,7 @@ class TestView(ClusterTestCase, ParametricTestCase): def test_apply_numpy(self): """view.apply(f, ndarray)""" import numpy - from numpy.testing.utils import assert_array_equal, assert_array_almost_equal + from numpy.testing.utils import assert_array_equal A = numpy.random.random((100,100)) view = self.client[-1] @@ -368,7 +364,7 @@ class TestView(ClusterTestCase, ParametricTestCase): @skip_without('numpy') def test_scatter_gather_numpy_nonblocking(self): import numpy - from numpy.testing.utils import assert_array_equal, assert_array_almost_equal + from numpy.testing.utils import assert_array_equal a = numpy.arange(64) view = self.client[:] ar = view.scatter('a', a, block=False) @@ -512,19 +508,17 @@ class TestView(ClusterTestCase, ParametricTestCase): def test_len(self): """len(view) makes sense""" e0 = self.client[self.client.ids[0]] - yield self.assertEqual(len(e0), 1) + self.assertEqual(len(e0), 1) v = self.client[:] - yield self.assertEqual(len(v), len(self.client.ids)) + self.assertEqual(len(v), len(self.client.ids)) v = self.client.direct_view('all') - yield self.assertEqual(len(v), len(self.client.ids)) + self.assertEqual(len(v), len(self.client.ids)) v = self.client[:2] - yield self.assertEqual(len(v), 2) + self.assertEqual(len(v), 2) v = self.client[:1] - yield self.assertEqual(len(v), 1) + self.assertEqual(len(v), 1) v = self.client.load_balanced_view() - yield self.assertEqual(len(v), len(self.client.ids)) - # parametric tests seem to require manual closing? - self.client.close() + self.assertEqual(len(v), len(self.client.ids)) # begin execute tests diff --git a/IPython/testing/_paramtestpy2.py b/IPython/testing/_paramtestpy2.py deleted file mode 100644 index 102bc85..0000000 --- a/IPython/testing/_paramtestpy2.py +++ /dev/null @@ -1,97 +0,0 @@ -"""Implementation of the parametric test support for Python 2.x -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2009-2011 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 sys -import unittest -from compiler.consts import CO_GENERATOR - -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- - -def isgenerator(func): - try: - return func.func_code.co_flags & CO_GENERATOR != 0 - except AttributeError: - return False - -class ParametricTestCase(unittest.TestCase): - """Write parametric tests in normal unittest testcase form. - - Limitations: the last iteration misses printing out a newline when running - in verbose mode. - """ - def run_parametric(self, result, testMethod): - # But if we have a test generator, we iterate it ourselves - testgen = testMethod() - while True: - try: - # Initialize test - result.startTest(self) - - # SetUp - try: - self.setUp() - except KeyboardInterrupt: - raise - except: - result.addError(self, sys.exc_info()) - return - # Test execution - ok = False - try: - next(testgen) - ok = True - except StopIteration: - # We stop the loop - break - except self.failureException: - result.addFailure(self, sys.exc_info()) - except KeyboardInterrupt: - raise - except: - result.addError(self, sys.exc_info()) - # TearDown - try: - self.tearDown() - except KeyboardInterrupt: - raise - except: - result.addError(self, sys.exc_info()) - ok = False - if ok: result.addSuccess(self) - - finally: - result.stopTest(self) - - def run(self, result=None): - if result is None: - result = self.defaultTestResult() - testMethod = getattr(self, self._testMethodName) - # For normal tests, we just call the base class and return that - if isgenerator(testMethod): - return self.run_parametric(result, testMethod) - else: - return super(ParametricTestCase, self).run(result) - - -def parametric(func): - """Decorator to make a simple function into a normal test via unittest.""" - - class Tester(ParametricTestCase): - test = staticmethod(func) - - Tester.__name__ = func.__name__ - - return Tester diff --git a/IPython/testing/_paramtestpy3.py b/IPython/testing/_paramtestpy3.py deleted file mode 100644 index 5956b5f..0000000 --- a/IPython/testing/_paramtestpy3.py +++ /dev/null @@ -1,71 +0,0 @@ -"""Implementation of the parametric test support for Python 3.x. - -Thanks for the py3 version to Robert Collins, from the Testing in Python -mailing list. -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2009-2011 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 unittest -from unittest import TestSuite - -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- - - -def isgenerator(func): - return hasattr(func,'_generator') - - -class IterCallableSuite(TestSuite): - def __init__(self, iterator, adapter): - self._iter = iterator - self._adapter = adapter - def __iter__(self): - yield self._adapter(self._iter.__next__) - -class ParametricTestCase(unittest.TestCase): - """Write parametric tests in normal unittest testcase form. - - Limitations: the last iteration misses printing out a newline when - running in verbose mode. - """ - - def run(self, result=None): - testMethod = getattr(self, self._testMethodName) - # For normal tests, we just call the base class and return that - if isgenerator(testMethod): - def adapter(next_test): - ftc = unittest.FunctionTestCase(next_test, - self.setUp, - self.tearDown) - self._nose_case = ftc # Nose 1.0 rejects the test without this - return ftc - - return IterCallableSuite(testMethod(),adapter).run(result) - else: - return super(ParametricTestCase, self).run(result) - - -def parametric(func): - """Decorator to make a simple function into a normal test via -unittest.""" - # Hack, until I figure out how to write isgenerator() for python3!! - func._generator = True - - class Tester(ParametricTestCase): - test = staticmethod(func) - - Tester.__name__ = func.__name__ - - return Tester diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index 8763002..d556783 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -16,10 +16,6 @@ Included decorators: Lightweight testing that remains unittest-compatible. -- @parametric, for parametric test support that is vastly easier to use than - nose's for debugging. With ours, if a test fails, the stack under inspection - is that of the test and not that of the test framework. - - An @as_unittest decorator can be used to tag any normal parameter-less function as a unittest TestCase. Then, both nose and normal unittest will recognize it as such. This will make it easier to migrate away from Nose if @@ -58,12 +54,6 @@ import unittest # This is Michele Simionato's decorator module, kept verbatim. from IPython.external.decorator import decorator -# We already have python3-compliant code for parametric tests -if sys.version[0]=='2': - from _paramtestpy2 import parametric -else: - from _paramtestpy3 import parametric - # Expose the unittest-driven decorators from ipunittest import ipdoctest, ipdocstring diff --git a/IPython/testing/ipunittest.py b/IPython/testing/ipunittest.py index 67f0f83..ae134f2 100644 --- a/IPython/testing/ipunittest.py +++ b/IPython/testing/ipunittest.py @@ -37,16 +37,9 @@ from __future__ import absolute_import # Stdlib import re -import sys import unittest from doctest import DocTestFinder, DocTestRunner, TestResults -# We already have python3-compliant code for parametric tests -if sys.version[0]=='2': - from ._paramtestpy2 import ParametricTestCase -else: - from ._paramtestpy3 import ParametricTestCase - #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- diff --git a/IPython/testing/tests/test_decorators.py b/IPython/testing/tests/test_decorators.py index cb87d2f..340c00a 100644 --- a/IPython/testing/tests/test_decorators.py +++ b/IPython/testing/tests/test_decorators.py @@ -12,7 +12,6 @@ import nose.tools as nt # Our own from IPython.testing import decorators as dec from IPython.testing.skipdoctest import skip_doctest -from IPython.testing.ipunittest import ParametricTestCase #----------------------------------------------------------------------------- # Utilities @@ -47,24 +46,6 @@ def trivial(): """A trivial test""" pass -# Some examples of parametric tests. - -def is_smaller(i,j): - assert i