##// END OF EJS Templates
[core][tests][extension] Remove nose
Samuel Gaist -
Show More
@@ -1,96 +1,94 b''
1 import os.path
1 import os.path
2
2
3 import nose.tools as nt
4
5 import IPython.testing.tools as tt
3 import IPython.testing.tools as tt
6 from IPython.utils.syspathcontext import prepended_to_syspath
4 from IPython.utils.syspathcontext import prepended_to_syspath
7 from IPython.utils.tempdir import TemporaryDirectory
5 from IPython.utils.tempdir import TemporaryDirectory
8
6
9 ext1_content = """
7 ext1_content = """
10 def load_ipython_extension(ip):
8 def load_ipython_extension(ip):
11 print("Running ext1 load")
9 print("Running ext1 load")
12
10
13 def unload_ipython_extension(ip):
11 def unload_ipython_extension(ip):
14 print("Running ext1 unload")
12 print("Running ext1 unload")
15 """
13 """
16
14
17 ext2_content = """
15 ext2_content = """
18 def load_ipython_extension(ip):
16 def load_ipython_extension(ip):
19 print("Running ext2 load")
17 print("Running ext2 load")
20 """
18 """
21
19
22 ext3_content = """
20 ext3_content = """
23 def load_ipython_extension(ip):
21 def load_ipython_extension(ip):
24 ip2 = get_ipython()
22 ip2 = get_ipython()
25 print(ip is ip2)
23 print(ip is ip2)
26 """
24 """
27
25
28 def test_extension_loading():
26 def test_extension_loading():
29 em = get_ipython().extension_manager
27 em = get_ipython().extension_manager
30 with TemporaryDirectory() as td:
28 with TemporaryDirectory() as td:
31 ext1 = os.path.join(td, 'ext1.py')
29 ext1 = os.path.join(td, 'ext1.py')
32 with open(ext1, 'w') as f:
30 with open(ext1, 'w') as f:
33 f.write(ext1_content)
31 f.write(ext1_content)
34
32
35 ext2 = os.path.join(td, 'ext2.py')
33 ext2 = os.path.join(td, 'ext2.py')
36 with open(ext2, 'w') as f:
34 with open(ext2, 'w') as f:
37 f.write(ext2_content)
35 f.write(ext2_content)
38
36
39 with prepended_to_syspath(td):
37 with prepended_to_syspath(td):
40 assert 'ext1' not in em.loaded
38 assert 'ext1' not in em.loaded
41 assert 'ext2' not in em.loaded
39 assert 'ext2' not in em.loaded
42
40
43 # Load extension
41 # Load extension
44 with tt.AssertPrints("Running ext1 load"):
42 with tt.AssertPrints("Running ext1 load"):
45 assert em.load_extension('ext1') is None
43 assert em.load_extension('ext1') is None
46 assert 'ext1' in em.loaded
44 assert 'ext1' in em.loaded
47
45
48 # Should refuse to load it again
46 # Should refuse to load it again
49 with tt.AssertNotPrints("Running ext1 load"):
47 with tt.AssertNotPrints("Running ext1 load"):
50 assert em.load_extension('ext1') == 'already loaded'
48 assert em.load_extension('ext1') == 'already loaded'
51
49
52 # Reload
50 # Reload
53 with tt.AssertPrints("Running ext1 unload"):
51 with tt.AssertPrints("Running ext1 unload"):
54 with tt.AssertPrints("Running ext1 load", suppress=False):
52 with tt.AssertPrints("Running ext1 load", suppress=False):
55 em.reload_extension('ext1')
53 em.reload_extension('ext1')
56
54
57 # Unload
55 # Unload
58 with tt.AssertPrints("Running ext1 unload"):
56 with tt.AssertPrints("Running ext1 unload"):
59 assert em.unload_extension('ext1') is None
57 assert em.unload_extension('ext1') is None
60
58
61 # Can't unload again
59 # Can't unload again
62 with tt.AssertNotPrints("Running ext1 unload"):
60 with tt.AssertNotPrints("Running ext1 unload"):
63 assert em.unload_extension('ext1') == 'not loaded'
61 assert em.unload_extension('ext1') == 'not loaded'
64 assert em.unload_extension('ext2') == 'not loaded'
62 assert em.unload_extension('ext2') == 'not loaded'
65
63
66 # Load extension 2
64 # Load extension 2
67 with tt.AssertPrints("Running ext2 load"):
65 with tt.AssertPrints("Running ext2 load"):
68 assert em.load_extension('ext2') is None
66 assert em.load_extension('ext2') is None
69
67
70 # Can't unload this
68 # Can't unload this
71 assert em.unload_extension('ext2') == 'no unload function'
69 assert em.unload_extension('ext2') == 'no unload function'
72
70
73 # But can reload it
71 # But can reload it
74 with tt.AssertPrints("Running ext2 load"):
72 with tt.AssertPrints("Running ext2 load"):
75 em.reload_extension('ext2')
73 em.reload_extension('ext2')
76
74
77
75
78 def test_extension_builtins():
76 def test_extension_builtins():
79 em = get_ipython().extension_manager
77 em = get_ipython().extension_manager
80 with TemporaryDirectory() as td:
78 with TemporaryDirectory() as td:
81 ext3 = os.path.join(td, 'ext3.py')
79 ext3 = os.path.join(td, 'ext3.py')
82 with open(ext3, 'w') as f:
80 with open(ext3, 'w') as f:
83 f.write(ext3_content)
81 f.write(ext3_content)
84
82
85 assert 'ext3' not in em.loaded
83 assert 'ext3' not in em.loaded
86
84
87 with prepended_to_syspath(td):
85 with prepended_to_syspath(td):
88 # Load extension
86 # Load extension
89 with tt.AssertPrints("True"):
87 with tt.AssertPrints("True"):
90 assert em.load_extension('ext3') is None
88 assert em.load_extension('ext3') is None
91 assert 'ext3' in em.loaded
89 assert 'ext3' in em.loaded
92
90
93
91
94 def test_non_extension():
92 def test_non_extension():
95 em = get_ipython().extension_manager
93 em = get_ipython().extension_manager
96 nt.assert_equal(em.load_extension('sys'), "no load function")
94 assert em.load_extension("sys") == "no load function"
General Comments 0
You need to be logged in to leave comments. Login now