##// END OF EJS Templates
cleanup nt.assert usage in test_magic...
MinRK -
Show More
@@ -57,7 +57,7 b' def test_rehashx():'
57 nt.assert_true(len(_ip.alias_manager.alias_table) > 10)
57 nt.assert_true(len(_ip.alias_manager.alias_table) > 10)
58 for key, val in _ip.alias_manager.alias_table.iteritems():
58 for key, val in _ip.alias_manager.alias_table.iteritems():
59 # we must strip dots from alias names
59 # we must strip dots from alias names
60 nt.assert_true('.' not in key)
60 nt.assert_not_in('.', key)
61
61
62 # rehashx must fill up syscmdlist
62 # rehashx must fill up syscmdlist
63 scoms = _ip.db['syscmdlist']
63 scoms = _ip.db['syscmdlist']
@@ -82,9 +82,9 b' def test_magic_parse_long_options():'
82 ip = get_ipython()
82 ip = get_ipython()
83 m = DummyMagics(ip)
83 m = DummyMagics(ip)
84 opts, _ = m.parse_options('--foo --bar=bubble', 'a', 'foo', 'bar=')
84 opts, _ = m.parse_options('--foo --bar=bubble', 'a', 'foo', 'bar=')
85 nt.assert_true('foo' in opts)
85 nt.assert_in('foo', opts)
86 nt.assert_true('bar' in opts)
86 nt.assert_in('bar', opts)
87 nt.assert_true(opts['bar'], "bubble")
87 nt.assert_equal(opts['bar'], "bubble")
88
88
89
89
90 @dec.skip_without('sqlite3')
90 @dec.skip_without('sqlite3')
@@ -198,8 +198,8 b' def test_macro():'
198 ip.magic("macro test 1-3")
198 ip.magic("macro test 1-3")
199 nt.assert_equal(ip.user_ns["test"].value, "\n".join(cmds)+"\n")
199 nt.assert_equal(ip.user_ns["test"].value, "\n".join(cmds)+"\n")
200
200
201 # List macros.
201 # List macros
202 assert "test" in ip.magic("macro")
202 nt.assert_in("test", ip.magic("macro"))
203
203
204
204
205 @dec.skip_without('sqlite3')
205 @dec.skip_without('sqlite3')
@@ -226,9 +226,9 b' def test_magic_magic():'
226 ip.magic("magic")
226 ip.magic("magic")
227
227
228 stdout = captured.stdout
228 stdout = captured.stdout
229 nt.assert_true('%magic' in stdout)
229 nt.assert_in('%magic', stdout)
230 nt.assert_true('IPython' in stdout)
230 nt.assert_in('IPython', stdout)
231 nt.assert_true('Available' in stdout)
231 nt.assert_in('Available', stdout)
232
232
233
233
234 @dec.skipif_not_numpy
234 @dec.skipif_not_numpy
@@ -236,9 +236,9 b' def test_numpy_reset_array_undec():'
236 "Test '%reset array' functionality"
236 "Test '%reset array' functionality"
237 _ip.ex('import numpy as np')
237 _ip.ex('import numpy as np')
238 _ip.ex('a = np.empty(2)')
238 _ip.ex('a = np.empty(2)')
239 nt.assert_true('a' in _ip.user_ns)
239 nt.assert_in('a', _ip.user_ns)
240 _ip.magic('reset -f array')
240 _ip.magic('reset -f array')
241 nt.assert_false('a' in _ip.user_ns)
241 nt.assert_not_in('a', _ip.user_ns)
242
242
243 def test_reset_out():
243 def test_reset_out():
244 "Test '%reset out' magic"
244 "Test '%reset out' magic"
@@ -248,7 +248,7 b' def test_reset_out():'
248 nt.assert_true('dead' in [_ip.user_ns[x] for x in '_','__','___'])
248 nt.assert_true('dead' in [_ip.user_ns[x] for x in '_','__','___'])
249 _ip.magic('reset -f out')
249 _ip.magic('reset -f out')
250 nt.assert_false('dead' in [_ip.user_ns[x] for x in '_','__','___'])
250 nt.assert_false('dead' in [_ip.user_ns[x] for x in '_','__','___'])
251 nt.assert_true(len(_ip.user_ns['Out']) == 0)
251 nt.assert_equal(len(_ip.user_ns['Out']), 0)
252
252
253 def test_reset_in():
253 def test_reset_in():
254 "Test '%reset in' magic"
254 "Test '%reset in' magic"
@@ -257,7 +257,7 b' def test_reset_in():'
257 nt.assert_true('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii'])
257 nt.assert_true('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii'])
258 _ip.magic('%reset -f in')
258 _ip.magic('%reset -f in')
259 nt.assert_false('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii'])
259 nt.assert_false('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii'])
260 nt.assert_true(len(set(_ip.user_ns['In'])) == 1)
260 nt.assert_equal(len(set(_ip.user_ns['In'])), 1)
261
261
262 def test_reset_dhist():
262 def test_reset_dhist():
263 "Test '%reset dhist' magic"
263 "Test '%reset dhist' magic"
@@ -266,14 +266,14 b' def test_reset_dhist():'
266 _ip.magic('cd -')
266 _ip.magic('cd -')
267 nt.assert_true(len(_ip.user_ns['_dh']) > 0)
267 nt.assert_true(len(_ip.user_ns['_dh']) > 0)
268 _ip.magic('reset -f dhist')
268 _ip.magic('reset -f dhist')
269 nt.assert_true(len(_ip.user_ns['_dh']) == 0)
269 nt.assert_equal(len(_ip.user_ns['_dh']), 0)
270 _ip.run_cell("_dh = [d for d in tmp]") #restore
270 _ip.run_cell("_dh = [d for d in tmp]") #restore
271
271
272 def test_reset_in_length():
272 def test_reset_in_length():
273 "Test that '%reset in' preserves In[] length"
273 "Test that '%reset in' preserves In[] length"
274 _ip.run_cell("print 'foo'")
274 _ip.run_cell("print 'foo'")
275 _ip.run_cell("reset -f in")
275 _ip.run_cell("reset -f in")
276 nt.assert_true(len(_ip.user_ns['In']) == _ip.displayhook.prompt_count+1)
276 nt.assert_equal(len(_ip.user_ns['In']), _ip.displayhook.prompt_count+1)
277
277
278 def test_tb_syntaxerror():
278 def test_tb_syntaxerror():
279 """test %tb after a SyntaxError"""
279 """test %tb after a SyntaxError"""
@@ -769,13 +769,13 b' def test_alias_magic():'
769
769
770 # Basic operation: both cell and line magics are created, if possible.
770 # Basic operation: both cell and line magics are created, if possible.
771 ip.run_line_magic('alias_magic', 'timeit_alias timeit')
771 ip.run_line_magic('alias_magic', 'timeit_alias timeit')
772 nt.assert_true('timeit_alias' in mm.magics['line'])
772 nt.assert_in('timeit_alias', mm.magics['line'])
773 nt.assert_true('timeit_alias' in mm.magics['cell'])
773 nt.assert_in('timeit_alias', mm.magics['cell'])
774
774
775 # --cell is specified, line magic not created.
775 # --cell is specified, line magic not created.
776 ip.run_line_magic('alias_magic', '--cell timeit_cell_alias timeit')
776 ip.run_line_magic('alias_magic', '--cell timeit_cell_alias timeit')
777 nt.assert_false('timeit_cell_alias' in mm.magics['line'])
777 nt.assert_not_in('timeit_cell_alias', mm.magics['line'])
778 nt.assert_true('timeit_cell_alias' in mm.magics['cell'])
778 nt.assert_in('timeit_cell_alias', mm.magics['cell'])
779
779
780 # Test that line alias is created successfully.
780 # Test that line alias is created successfully.
781 ip.run_line_magic('alias_magic', '--line env_alias env')
781 ip.run_line_magic('alias_magic', '--line env_alias env')
@@ -795,12 +795,12 b' def test_save():'
795 with open(file) as f:
795 with open(file) as f:
796 content = f.read()
796 content = f.read()
797 nt.assert_equal(content.count(cmds[0]), 1)
797 nt.assert_equal(content.count(cmds[0]), 1)
798 nt.assert_true('coding: utf-8' in content)
798 nt.assert_in('coding: utf-8', content)
799 ip.run_line_magic("save", "-a %s 1-10" % file)
799 ip.run_line_magic("save", "-a %s 1-10" % file)
800 with open(file) as f:
800 with open(file) as f:
801 content = f.read()
801 content = f.read()
802 nt.assert_equal(content.count(cmds[0]), 2)
802 nt.assert_equal(content.count(cmds[0]), 2)
803 nt.assert_true('coding: utf-8' in content)
803 nt.assert_in('coding: utf-8', content)
804
804
805
805
806 def test_store():
806 def test_store():
General Comments 0
You need to be logged in to leave comments. Login now