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