##// END OF EJS Templates
Remove bare asserts by switching to use nose.tools.assert_* functions to check test conditions.
Jorgen Stenarson -
Show More
@@ -22,6 +22,7 b' from nose.tools import raises'
22
22
23 from os.path import join, abspath, split
23 from os.path import join, abspath, split
24 import os, sys, IPython
24 import os, sys, IPython
25 import nose.tools as nt
25
26
26 env = os.environ
27 env = os.environ
27
28
@@ -72,7 +73,7 b' def test_get_home_dir_1():'
72 IPython.__file__ = abspath(join(test_file_path, "home_test_dir/Lib/IPython/__init__.py"))
73 IPython.__file__ = abspath(join(test_file_path, "home_test_dir/Lib/IPython/__init__.py"))
73
74
74 home_dir = genutils.get_home_dir()
75 home_dir = genutils.get_home_dir()
75 assert home_dir == abspath(join(test_file_path, "home_test_dir"))
76 nt.assert_equal(home_dir, abspath(join(test_file_path, "home_test_dir")))
76
77
77 @with_enivronment
78 @with_enivronment
78 def test_get_home_dir_2():
79 def test_get_home_dir_2():
@@ -83,14 +84,14 b' def test_get_home_dir_2():'
83 IPython.__file__ = abspath(join(test_file_path, "home_test_dir/Library.zip/IPython/__init__.py"))
84 IPython.__file__ = abspath(join(test_file_path, "home_test_dir/Library.zip/IPython/__init__.py"))
84
85
85 home_dir = genutils.get_home_dir()
86 home_dir = genutils.get_home_dir()
86 assert home_dir == abspath(join(test_file_path, "home_test_dir")).lower()
87 nt.assert_equal(home_dir, abspath(join(test_file_path, "home_test_dir")).lower())
87
88
88 @with_enivronment
89 @with_enivronment
89 def test_get_home_dir_3():
90 def test_get_home_dir_3():
90 """Testcase $HOME is set, then use its value as home directory."""
91 """Testcase $HOME is set, then use its value as home directory."""
91 env["HOME"] = join(test_file_path, "home_test_dir")
92 env["HOME"] = join(test_file_path, "home_test_dir")
92 home_dir = genutils.get_home_dir()
93 home_dir = genutils.get_home_dir()
93 assert home_dir == env["HOME"]
94 nt.assert_equal(home_dir, env["HOME"])
94
95
95 @with_enivronment
96 @with_enivronment
96 def test_get_home_dir_4():
97 def test_get_home_dir_4():
@@ -99,11 +100,7 b' def test_get_home_dir_4():'
99
100
100 os.name = 'posix'
101 os.name = 'posix'
101 del os.environ["HOME"]
102 del os.environ["HOME"]
102 try:
103 nt.assert_raises(genutils.HomeDirError, genutils.get_home_dir)
103 genutils.get_home_dir()
104 assert False
105 except genutils.HomeDirError:
106 pass
107
104
108 @with_enivronment
105 @with_enivronment
109 def test_get_home_dir_5():
106 def test_get_home_dir_5():
@@ -115,7 +112,7 b' def test_get_home_dir_5():'
115 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(test_file_path), "home_test_dir"
112 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(test_file_path), "home_test_dir"
116
113
117 home_dir = genutils.get_home_dir()
114 home_dir = genutils.get_home_dir()
118 assert home_dir == abspath(join(test_file_path, "home_test_dir"))
115 nt.assert_equal(home_dir, abspath(join(test_file_path, "home_test_dir")))
119
116
120 @with_enivronment
117 @with_enivronment
121 def test_get_home_dir_6():
118 def test_get_home_dir_6():
@@ -130,7 +127,7 b' def test_get_home_dir_6():'
130 env["USERPROFILE"] = abspath(join(test_file_path, "home_test_dir"))
127 env["USERPROFILE"] = abspath(join(test_file_path, "home_test_dir"))
131
128
132 home_dir = genutils.get_home_dir()
129 home_dir = genutils.get_home_dir()
133 assert home_dir == abspath(join(test_file_path, "home_test_dir"))
130 nt.assert_equal(home_dir, abspath(join(test_file_path, "home_test_dir")))
134
131
135 # Should we stub wreg fully so we can run the test on all platforms?
132 # Should we stub wreg fully so we can run the test on all platforms?
136 #@skip_if_not_win32
133 #@skip_if_not_win32
@@ -155,7 +152,7 b' def test_get_home_dir_7():'
155 wreg.QueryValueEx = QueryValueEx
152 wreg.QueryValueEx = QueryValueEx
156
153
157 home_dir = genutils.get_home_dir()
154 home_dir = genutils.get_home_dir()
158 assert home_dir == abspath(join(test_file_path, "home_test_dir"))
155 nt.assert_equal(home_dir, abspath(join(test_file_path, "home_test_dir")))
159
156
160
157
161 #
158 #
@@ -167,7 +164,7 b' def test_get_ipython_dir_1():'
167 """2 Testcase to see if we can call get_ipython_dir without Exceptions."""
164 """2 Testcase to see if we can call get_ipython_dir without Exceptions."""
168 env['IPYTHONDIR'] = "someplace/.ipython"
165 env['IPYTHONDIR'] = "someplace/.ipython"
169 ipdir = genutils.get_ipython_dir()
166 ipdir = genutils.get_ipython_dir()
170 assert ipdir == os.path.abspath("someplace/.ipython")
167 nt.assert_equal(ipdir, os.path.abspath("someplace/.ipython"))
171
168
172
169
173 @with_enivronment
170 @with_enivronment
@@ -176,7 +173,7 b' def test_get_ipython_dir_2():'
176 genutils.get_home_dir = lambda : "someplace"
173 genutils.get_home_dir = lambda : "someplace"
177 os.name = "posix"
174 os.name = "posix"
178 ipdir = genutils.get_ipython_dir()
175 ipdir = genutils.get_ipython_dir()
179 assert ipdir == os.path.abspath(os.path.join("someplace", ".ipython"))
176 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", ".ipython")))
180
177
181 @with_enivronment
178 @with_enivronment
182 def test_get_ipython_dir_3():
179 def test_get_ipython_dir_3():
@@ -184,7 +181,7 b' def test_get_ipython_dir_3():'
184 genutils.get_home_dir = lambda : "someplace"
181 genutils.get_home_dir = lambda : "someplace"
185 os.name = "nt"
182 os.name = "nt"
186 ipdir = genutils.get_ipython_dir()
183 ipdir = genutils.get_ipython_dir()
187 assert ipdir == os.path.abspath(os.path.join("someplace", "_ipython"))
184 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", "_ipython")))
188
185
189
186
190 #
187 #
@@ -203,29 +200,28 b' def test_get_security_dir():'
203
200
204 def test_popkey_1():
201 def test_popkey_1():
205 dct = dict(a=1, b=2, c=3)
202 dct = dict(a=1, b=2, c=3)
206 assert genutils.popkey(dct, "a") == 1
203 nt.assert_equal(genutils.popkey(dct, "a"), 1)
207 assert dct == dict(b=2, c=3)
204 nt.assert_equal(dct, dict(b=2, c=3))
208 assert genutils.popkey(dct, "b") == 2
205 nt.assert_equal(genutils.popkey(dct, "b"), 2)
209 assert dct == dict(c=3)
206 nt.assert_equal(dct, dict(c=3))
210 assert genutils.popkey(dct, "c") == 3
207 nt.assert_equal(genutils.popkey(dct, "c"), 3)
211 assert dct == dict()
208 nt.assert_equal(dct, dict())
212
209
213 @raises(KeyError)
214 def test_popkey_2():
210 def test_popkey_2():
215 dct = dict(a=1, b=2, c=3)
211 dct = dict(a=1, b=2, c=3)
216 genutils.popkey(dct, "d")
212 nt.assert_raises(KeyError, genutils.popkey, dct, "d")
217
213
218 def test_popkey_3():
214 def test_popkey_3():
219 dct = dict(a=1, b=2, c=3)
215 dct = dict(a=1, b=2, c=3)
220 assert genutils.popkey(dct, "A", 13) == 13
216 nt.assert_equal(genutils.popkey(dct, "A", 13), 13)
221 assert dct == dict(a=1, b=2, c=3)
217 nt.assert_equal(dct, dict(a=1, b=2, c=3))
222 assert genutils.popkey(dct, "B", 14) == 14
218 nt.assert_equal(genutils.popkey(dct, "B", 14), 14)
223 assert dct == dict(a=1, b=2, c=3)
219 nt.assert_equal(dct, dict(a=1, b=2, c=3))
224 assert genutils.popkey(dct, "C", 15) == 15
220 nt.assert_equal(genutils.popkey(dct, "C", 15), 15)
225 assert dct == dict(a=1, b=2, c=3)
221 nt.assert_equal(dct, dict(a=1, b=2, c=3))
226 assert genutils.popkey(dct, "a") == 1
222 nt.assert_equal(genutils.popkey(dct, "a"), 1)
227 assert dct == dict(b=2, c=3)
223 nt.assert_equal(dct, dict(b=2, c=3))
228 assert genutils.popkey(dct, "b") == 2
224 nt.assert_equal(genutils.popkey(dct, "b"), 2)
229 assert dct == dict(c=3)
225 nt.assert_equal(dct, dict(c=3))
230 assert genutils.popkey(dct, "c") == 3
226 nt.assert_equal(genutils.popkey(dct, "c"), 3)
231 assert dct == dict()
227 nt.assert_equal(dct, dict())
General Comments 0
You need to be logged in to leave comments. Login now