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..eff88a4 100644 --- a/IPython/core/tests/test_prefilter.py +++ b/IPython/core/tests/test_prefilter.py @@ -14,7 +14,6 @@ from IPython.testing.globalipapp import get_ipython #----------------------------------------------------------------------------- ip = get_ipython() -@dec.parametric def test_prefilter(): """Test user input conversions""" @@ -23,19 +22,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 +45,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 +54,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 +67,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/kernel/tests/test_launcher.py b/IPython/kernel/tests/test_launcher.py index 5aa069e..1fa43d8 100644 --- a/IPython/kernel/tests/test_launcher.py +++ b/IPython/kernel/tests/test_launcher.py @@ -27,7 +27,6 @@ from IPython.kernel.launcher import swallow_argv # Classes and functions #----------------------------------------------------------------------------- -@dec.parametric def test_swallow_argv(): tests = [ # expected , argv , aliases, flags @@ -56,5 +55,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..4074f95 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, ) @@ -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/utils/tests/test_jsonutil.py b/IPython/utils/tests/test_jsonutil.py index 61f1df7..847f54b 100644 --- a/IPython/utils/tests/test_jsonutil.py +++ b/IPython/utils/tests/test_jsonutil.py @@ -19,7 +19,6 @@ from base64 import decodestring import nose.tools as nt # our own -from IPython.testing import decorators as dec from IPython.utils import jsonutil, tz from ..jsonutil import json_clean, encode_images from ..py3compat import unicode_to_str, str_to_bytes @@ -62,7 +61,6 @@ def test(): -@dec.parametric def test_encode_images(): # invalid data, but the header and footer are from real files pngdata = b'\x89PNG\r\n\x1a\nblahblahnotactuallyvalidIEND\xaeB`\x82' @@ -76,19 +74,19 @@ def test_encode_images(): for key, value in fmt.iteritems(): # encoded has unicode, want bytes decoded = decodestring(encoded[key].encode('ascii')) - yield nt.assert_equal(decoded, value) + nt.assert_equal(decoded, value) encoded2 = encode_images(encoded) - yield nt.assert_equal(encoded, encoded2) + nt.assert_equal(encoded, encoded2) b64_str = {} for key, encoded in encoded.iteritems(): b64_str[key] = unicode_to_str(encoded) encoded3 = encode_images(b64_str) - yield nt.assert_equal(encoded3, b64_str) + nt.assert_equal(encoded3, b64_str) for key, value in fmt.iteritems(): # encoded3 has str, want bytes decoded = decodestring(str_to_bytes(encoded3[key])) - yield nt.assert_equal(decoded, value) + nt.assert_equal(decoded, value) def test_lambda(): jc = json_clean(lambda : 1)