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