##// END OF EJS Templates
Add first set of cell magic tests.
Fernando Perez -
Show More
@@ -490,3 +490,48 b' def test_notebook_reformat_json():'
490 def test_env():
490 def test_env():
491 env = _ip.magic("env")
491 env = _ip.magic("env")
492 assert isinstance(env, dict), type(env)
492 assert isinstance(env, dict), type(env)
493
494
495 class CellMagicTestCase(TestCase):
496
497 def check_ident(self, magic):
498 out = _ip.cell_magic(magic, 'a', 'b')
499 nt.assert_equals(out, ('a','b'))
500 out = _ip.run_cell('%%' + magic +' a\nb')
501 nt.assert_equals(out, ('a','b'))
502
503 def test_cell_magic_func_deco(self):
504 "Cell magic using simple decorator"
505 @register_cell_magic
506 def cellm(line, cell):
507 return line, cell
508
509 self.check_ident('cellm')
510
511 def test_cell_magic_reg(self):
512 "Cell magic manually registered"
513 def cellm(line, cell):
514 return line, cell
515
516 _ip.register_magic_function(cellm, 'cell', 'cellm2')
517 self.check_ident('cellm2')
518
519 def test_cell_magic_class(self):
520 "Cell magics declared via a class"
521 @magics_class
522 class MyMagics(Magics):
523
524 @cell_magic
525 def cellm3(self, line, cell):
526 return line, cell
527
528 @cell_magic('cellm4')
529 def cellm33(self, line, cell):
530 return line, cell
531
532 _ip.register_magics(MyMagics)
533 self.check_ident('cellm3')
534 self.check_ident('cellm4')
535 # Check that nothing is registered as 'cellm33'
536 c33 = _ip.find_cell_magic('cellm33')
537 nt.assert_equals(c33, None)
General Comments 0
You need to be logged in to leave comments. Login now