##// END OF EJS Templates
Merge pull request #1964 from minrk/magics_class...
Fernando Perez -
r7640:6331c3d0 merge
parent child Browse files
Show More
@@ -469,13 +469,19 b' class Magics(object):'
469 # grab. Only now, that the instance exists, can we create the proper
469 # grab. Only now, that the instance exists, can we create the proper
470 # mapping to bound methods. So we read the info off the original names
470 # mapping to bound methods. So we read the info off the original names
471 # table and replace each method name by the actual bound method.
471 # table and replace each method name by the actual bound method.
472 # But we mustn't clobber the *class* mapping, in case of multiple instances.
473 class_magics = self.magics
474 self.magics = {}
472 for mtype in magic_kinds:
475 for mtype in magic_kinds:
473 tab = self.magics[mtype]
476 tab = self.magics[mtype] = {}
474 # must explicitly use keys, as we're mutating this puppy
477 cls_tab = class_magics[mtype]
475 for magic_name in tab.keys():
478 for magic_name, meth_name in cls_tab.iteritems():
476 meth_name = tab[magic_name]
477 if isinstance(meth_name, basestring):
479 if isinstance(meth_name, basestring):
480 # it's a method name, grab it
478 tab[magic_name] = getattr(self, meth_name)
481 tab[magic_name] = getattr(self, meth_name)
482 else:
483 # it's the real thing
484 tab[magic_name] = meth_name
479
485
480 def arg_err(self,func):
486 def arg_err(self,func):
481 """Print docstring if incorrect arguments were passed"""
487 """Print docstring if incorrect arguments were passed"""
@@ -711,3 +711,14 b' def test_line_cell_info():'
711 nt.assert_true(oinfo['found'])
711 nt.assert_true(oinfo['found'])
712 nt.assert_true(oinfo['ismagic'])
712 nt.assert_true(oinfo['ismagic'])
713 nt.assert_equals(oinfo['docstring'], FooFoo.line_foo.__doc__)
713 nt.assert_equals(oinfo['docstring'], FooFoo.line_foo.__doc__)
714
715 def test_multiple_magics():
716 ip = get_ipython()
717 foo1 = FooFoo(ip)
718 foo2 = FooFoo(ip)
719 mm = ip.magics_manager
720 mm.register(foo1)
721 nt.assert_true(mm.magics['line']['foo'].im_self is foo1)
722 mm.register(foo2)
723 nt.assert_true(mm.magics['line']['foo'].im_self is foo2)
724 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now