##// END OF EJS Templates
[core][tests][interactiveshell] Remove nose
Samuel Gaist -
Show More
@@ -21,8 +21,6 b' from unittest import mock'
21
21
22 from os.path import join
22 from os.path import join
23
23
24 import nose.tools as nt
25
26 from IPython.core.error import InputRejected
24 from IPython.core.error import InputRejected
27 from IPython.core.inputtransformer import InputTransformer
25 from IPython.core.inputtransformer import InputTransformer
28 from IPython.core import interactiveshell
26 from IPython.core import interactiveshell
@@ -220,33 +218,39 b' class InteractiveShellTestCase(unittest.TestCase):'
220 def test_var_expand_local(self):
218 def test_var_expand_local(self):
221 """Test local variable expansion in !system and %magic calls"""
219 """Test local variable expansion in !system and %magic calls"""
222 # !system
220 # !system
223 ip.run_cell('def test():\n'
221 ip.run_cell(
224 ' lvar = "ttt"\n'
222 "def test():\n"
225 ' ret = !echo {lvar}\n'
223 ' lvar = "ttt"\n'
226 ' return ret[0]\n')
224 " ret = !echo {lvar}\n"
227 res = ip.user_ns['test']()
225 " return ret[0]\n"
228 nt.assert_in('ttt', res)
226 )
229
227 res = ip.user_ns["test"]()
228 self.assertIn("ttt", res)
229
230 # %magic
230 # %magic
231 ip.run_cell('def makemacro():\n'
231 ip.run_cell(
232 ' macroname = "macro_var_expand_locals"\n'
232 "def makemacro():\n"
233 ' %macro {macroname} codestr\n')
233 ' macroname = "macro_var_expand_locals"\n'
234 ip.user_ns['codestr'] = "str(12)"
234 " %macro {macroname} codestr\n"
235 ip.run_cell('makemacro()')
235 )
236 nt.assert_in('macro_var_expand_locals', ip.user_ns)
236 ip.user_ns["codestr"] = "str(12)"
237
237 ip.run_cell("makemacro()")
238 self.assertIn("macro_var_expand_locals", ip.user_ns)
239
238 def test_var_expand_self(self):
240 def test_var_expand_self(self):
239 """Test variable expansion with the name 'self', which was failing.
241 """Test variable expansion with the name 'self', which was failing.
240
242
241 See https://github.com/ipython/ipython/issues/1878#issuecomment-7698218
243 See https://github.com/ipython/ipython/issues/1878#issuecomment-7698218
242 """
244 """
243 ip.run_cell('class cTest:\n'
245 ip.run_cell(
244 ' classvar="see me"\n'
246 "class cTest:\n"
245 ' def test(self):\n'
247 ' classvar="see me"\n'
246 ' res = !echo Variable: {self.classvar}\n'
248 " def test(self):\n"
247 ' return res[0]\n')
249 " res = !echo Variable: {self.classvar}\n"
248 nt.assert_in('see me', ip.user_ns['cTest']().test())
250 " return res[0]\n"
249
251 )
252 self.assertIn("see me", ip.user_ns["cTest"]().test())
253
250 def test_bad_var_expand(self):
254 def test_bad_var_expand(self):
251 """var_expand on invalid formats shouldn't raise"""
255 """var_expand on invalid formats shouldn't raise"""
252 # SyntaxError
256 # SyntaxError
@@ -346,7 +350,7 b' class InteractiveShellTestCase(unittest.TestCase):'
346 info = dict(found=True, isalias=False, ismagic=True,
350 info = dict(found=True, isalias=False, ismagic=True,
347 namespace = 'IPython internal', obj= lmagic.__wrapped__,
351 namespace = 'IPython internal', obj= lmagic.__wrapped__,
348 parent = None)
352 parent = None)
349 nt.assert_equal(lfind, info)
353 self.assertEqual(lfind, info)
350
354
351 def test_ofind_cell_magic(self):
355 def test_ofind_cell_magic(self):
352 from IPython.core.magic import register_cell_magic
356 from IPython.core.magic import register_cell_magic
@@ -360,7 +364,7 b' class InteractiveShellTestCase(unittest.TestCase):'
360 info = dict(found=True, isalias=False, ismagic=True,
364 info = dict(found=True, isalias=False, ismagic=True,
361 namespace = 'IPython internal', obj= cmagic.__wrapped__,
365 namespace = 'IPython internal', obj= cmagic.__wrapped__,
362 parent = None)
366 parent = None)
363 nt.assert_equal(find, info)
367 self.assertEqual(find, info)
364
368
365 def test_ofind_property_with_error(self):
369 def test_ofind_property_with_error(self):
366 class A(object):
370 class A(object):
@@ -372,7 +376,7 b' class InteractiveShellTestCase(unittest.TestCase):'
372 found = ip._ofind('a.foo', [('locals', locals())])
376 found = ip._ofind('a.foo', [('locals', locals())])
373 info = dict(found=True, isalias=False, ismagic=False,
377 info = dict(found=True, isalias=False, ismagic=False,
374 namespace='locals', obj=A.foo, parent=a)
378 namespace='locals', obj=A.foo, parent=a)
375 nt.assert_equal(found, info)
379 self.assertEqual(found, info)
376
380
377 def test_ofind_multiple_attribute_lookups(self):
381 def test_ofind_multiple_attribute_lookups(self):
378 class A(object):
382 class A(object):
@@ -387,7 +391,7 b' class InteractiveShellTestCase(unittest.TestCase):'
387 found = ip._ofind('a.a.a.foo', [('locals', locals())])
391 found = ip._ofind('a.a.a.foo', [('locals', locals())])
388 info = dict(found=True, isalias=False, ismagic=False,
392 info = dict(found=True, isalias=False, ismagic=False,
389 namespace='locals', obj=A.foo, parent=a.a.a)
393 namespace='locals', obj=A.foo, parent=a.a.a)
390 nt.assert_equal(found, info)
394 self.assertEqual(found, info)
391
395
392 def test_ofind_slotted_attributes(self):
396 def test_ofind_slotted_attributes(self):
393 class A(object):
397 class A(object):
@@ -399,12 +403,12 b' class InteractiveShellTestCase(unittest.TestCase):'
399 found = ip._ofind('a.foo', [('locals', locals())])
403 found = ip._ofind('a.foo', [('locals', locals())])
400 info = dict(found=True, isalias=False, ismagic=False,
404 info = dict(found=True, isalias=False, ismagic=False,
401 namespace='locals', obj=a.foo, parent=a)
405 namespace='locals', obj=a.foo, parent=a)
402 nt.assert_equal(found, info)
406 self.assertEqual(found, info)
403
407
404 found = ip._ofind('a.bar', [('locals', locals())])
408 found = ip._ofind('a.bar', [('locals', locals())])
405 info = dict(found=False, isalias=False, ismagic=False,
409 info = dict(found=False, isalias=False, ismagic=False,
406 namespace=None, obj=None, parent=a)
410 namespace=None, obj=None, parent=a)
407 nt.assert_equal(found, info)
411 self.assertEqual(found, info)
408
412
409 def test_ofind_prefers_property_to_instance_level_attribute(self):
413 def test_ofind_prefers_property_to_instance_level_attribute(self):
410 class A(object):
414 class A(object):
@@ -412,10 +416,10 b' class InteractiveShellTestCase(unittest.TestCase):'
412 def foo(self):
416 def foo(self):
413 return 'bar'
417 return 'bar'
414 a = A()
418 a = A()
415 a.__dict__['foo'] = 'baz'
419 a.__dict__["foo"] = "baz"
416 nt.assert_equal(a.foo, 'bar')
420 self.assertEqual(a.foo, "bar")
417 found = ip._ofind('a.foo', [('locals', locals())])
421 found = ip._ofind("a.foo", [("locals", locals())])
418 nt.assert_is(found['obj'], A.foo)
422 self.assertIs(found["obj"], A.foo)
419
423
420 def test_custom_syntaxerror_exception(self):
424 def test_custom_syntaxerror_exception(self):
421 called = []
425 called = []
@@ -819,7 +823,7 b' class TestAstTransformError(unittest.TestCase):'
819 ip.run_cell("1 + 2")
823 ip.run_cell("1 + 2")
820
824
821 # This should have been removed.
825 # This should have been removed.
822 nt.assert_not_in(err_transformer, ip.ast_transformers)
826 self.assertNotIn(err_transformer, ip.ast_transformers)
823
827
824
828
825 class StringRejector(ast.NodeTransformer):
829 class StringRejector(ast.NodeTransformer):
@@ -889,21 +893,21 b' def test_user_variables():'
889 keys = {'dummy', 'doesnotexist'}
893 keys = {'dummy', 'doesnotexist'}
890 r = ip.user_expressions({ key:key for key in keys})
894 r = ip.user_expressions({ key:key for key in keys})
891
895
892 nt.assert_equal(keys, set(r.keys()))
896 assert keys == set(r.keys())
893 dummy = r['dummy']
897 dummy = r["dummy"]
894 nt.assert_equal({'status', 'data', 'metadata'}, set(dummy.keys()))
898 assert {"status", "data", "metadata"} == set(dummy.keys())
895 nt.assert_equal(dummy['status'], 'ok')
899 assert dummy["status"] == "ok"
896 data = dummy['data']
900 data = dummy["data"]
897 metadata = dummy['metadata']
901 metadata = dummy["metadata"]
898 nt.assert_equal(data.get('text/html'), d._repr_html_())
902 assert data.get("text/html") == d._repr_html_()
899 js, jsmd = d._repr_javascript_()
903 js, jsmd = d._repr_javascript_()
900 nt.assert_equal(data.get('application/javascript'), js)
904 assert data.get("application/javascript") == js
901 nt.assert_equal(metadata.get('application/javascript'), jsmd)
905 assert metadata.get("application/javascript") == jsmd
902
906
903 dne = r['doesnotexist']
907 dne = r["doesnotexist"]
904 nt.assert_equal(dne['status'], 'error')
908 assert dne["status"] == "error"
905 nt.assert_equal(dne['ename'], 'NameError')
909 assert dne["ename"] == "NameError"
906
910
907 # back to text only
911 # back to text only
908 ip.display_formatter.active_types = ['text/plain']
912 ip.display_formatter.active_types = ['text/plain']
909
913
@@ -917,18 +921,18 b' def test_user_expression():'
917 r = ip.user_expressions(query)
921 r = ip.user_expressions(query)
918 import pprint
922 import pprint
919 pprint.pprint(r)
923 pprint.pprint(r)
920 nt.assert_equal(set(r.keys()), set(query.keys()))
924 assert set(r.keys()) == set(query.keys())
921 a = r['a']
925 a = r["a"]
922 nt.assert_equal({'status', 'data', 'metadata'}, set(a.keys()))
926 assert {"status", "data", "metadata"} == set(a.keys())
923 nt.assert_equal(a['status'], 'ok')
927 assert a["status"] == "ok"
924 data = a['data']
928 data = a["data"]
925 metadata = a['metadata']
929 metadata = a["metadata"]
926 nt.assert_equal(data.get('text/plain'), '3')
930 assert data.get("text/plain") == "3"
927
931
928 b = r['b']
932 b = r["b"]
929 nt.assert_equal(b['status'], 'error')
933 assert b["status"] == "error"
930 nt.assert_equal(b['ename'], 'ZeroDivisionError')
934 assert b["ename"] == "ZeroDivisionError"
931
935
932 # back to text only
936 # back to text only
933 ip.display_formatter.active_types = ['text/plain']
937 ip.display_formatter.active_types = ['text/plain']
934
938
@@ -1030,8 +1034,8 b' def test_custom_exc_count():'
1030 ip.run_cell("def foo()", store_history=True)
1034 ip.run_cell("def foo()", store_history=True)
1031 # restore default excepthook
1035 # restore default excepthook
1032 ip.set_custom_exc((), None)
1036 ip.set_custom_exc((), None)
1033 nt.assert_equal(hook.call_count, 1)
1037 assert hook.call_count == 1
1034 nt.assert_equal(ip.execution_count, before + 1)
1038 assert ip.execution_count == before + 1
1035
1039
1036
1040
1037 def test_run_cell_async():
1041 def test_run_cell_async():
General Comments 0
You need to be logged in to leave comments. Login now