##// END OF EJS Templates
Add doc strings to all functions
Jorgen Stenarson -
Show More
@@ -45,12 +45,20 b' test_file_path = split(abspath(__file__))[0]'
45
45
46
46
47 def setup():
47 def setup():
48 """Setup testenvironment for the module:
49
50 - Adds dummy home dir tree
51 """
48 try:
52 try:
49 os.makedirs("home_test_dir/_ipython")
53 os.makedirs("home_test_dir/_ipython")
50 except WindowsError:
54 except WindowsError:
51 pass #Or should we complain that the test directory already exists??
55 pass #Or should we complain that the test directory already exists??
52
56
53 def teardown():
57 def teardown():
58 """Teardown testenvironment for the module:
59
60 - Remove dummy home dir tree
61 """
54 try:
62 try:
55 os.removedirs("home_test_dir/_ipython")
63 os.removedirs("home_test_dir/_ipython")
56 except WindowsError:
64 except WindowsError:
@@ -58,6 +66,12 b' def teardown():'
58
66
59
67
60 def setup_environment():
68 def setup_environment():
69 """Setup testenvironment for some functions that are tested
70 in this module. In particular this functions stores attributes
71 and other things that we need to stub in some test functions.
72 This needs to be done on a function level and not module level because
73 each testfunction needs a pristine environment.
74 """
61 global oldstuff, platformstuff
75 global oldstuff, platformstuff
62 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
76 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
63
77
@@ -68,6 +82,8 b' def setup_environment():'
68 del env['IPYTHONDIR']
82 del env['IPYTHONDIR']
69
83
70 def teardown_environment():
84 def teardown_environment():
85 """Restore things that were remebered by the setup_environment function
86 """
71 (oldenv, os.name, genutils.get_home_dir, IPython.__file__,) = oldstuff
87 (oldenv, os.name, genutils.get_home_dir, IPython.__file__,) = oldstuff
72 for key in env.keys():
88 for key in env.keys():
73 if key not in oldenv:
89 if key not in oldenv:
@@ -78,7 +94,8 b' def teardown_environment():'
78 if os.name == 'nt':
94 if os.name == 'nt':
79 (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
95 (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
80
96
81 with_enivronment = with_setup(setup_environment, teardown_environment)
97 # Build decorator that uses the setup_environment/setup_environment
98 with_enivronment = with_setup(setup_environment, setup_environment)
82
99
83
100
84 #
101 #
@@ -183,7 +200,7 b' def test_get_home_dir_7():'
183
200
184 @with_enivronment
201 @with_enivronment
185 def test_get_ipython_dir_1():
202 def test_get_ipython_dir_1():
186 """2 Testcase to see if we can call get_ipython_dir without Exceptions."""
203 """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions."""
187 env['IPYTHONDIR'] = "someplace/.ipython"
204 env['IPYTHONDIR'] = "someplace/.ipython"
188 ipdir = genutils.get_ipython_dir()
205 ipdir = genutils.get_ipython_dir()
189 nt.assert_equal(ipdir, os.path.abspath("someplace/.ipython"))
206 nt.assert_equal(ipdir, os.path.abspath("someplace/.ipython"))
@@ -191,7 +208,7 b' def test_get_ipython_dir_1():'
191
208
192 @with_enivronment
209 @with_enivronment
193 def test_get_ipython_dir_2():
210 def test_get_ipython_dir_2():
194 """3 Testcase to see if we can call get_ipython_dir without Exceptions."""
211 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
195 genutils.get_home_dir = lambda : "someplace"
212 genutils.get_home_dir = lambda : "someplace"
196 os.name = "posix"
213 os.name = "posix"
197 ipdir = genutils.get_ipython_dir()
214 ipdir = genutils.get_ipython_dir()
@@ -199,7 +216,7 b' def test_get_ipython_dir_2():'
199
216
200 @with_enivronment
217 @with_enivronment
201 def test_get_ipython_dir_3():
218 def test_get_ipython_dir_3():
202 """4 Testcase to see if we can call get_ipython_dir without Exceptions."""
219 """test_get_ipython_dir_3, Testcase to see if we can call get_ipython_dir without Exceptions."""
203 genutils.get_home_dir = lambda : "someplace"
220 genutils.get_home_dir = lambda : "someplace"
204 os.name = "nt"
221 os.name = "nt"
205 ipdir = genutils.get_ipython_dir()
222 ipdir = genutils.get_ipython_dir()
@@ -221,6 +238,8 b' def test_get_security_dir():'
221 #
238 #
222
239
223 def test_popkey_1():
240 def test_popkey_1():
241 """test_popkey_1, Basic usage test of popkey
242 """
224 dct = dict(a=1, b=2, c=3)
243 dct = dict(a=1, b=2, c=3)
225 nt.assert_equal(genutils.popkey(dct, "a"), 1)
244 nt.assert_equal(genutils.popkey(dct, "a"), 1)
226 nt.assert_equal(dct, dict(b=2, c=3))
245 nt.assert_equal(dct, dict(b=2, c=3))
@@ -230,10 +249,16 b' def test_popkey_1():'
230 nt.assert_equal(dct, dict())
249 nt.assert_equal(dct, dict())
231
250
232 def test_popkey_2():
251 def test_popkey_2():
252 """test_popkey_2, Test to see that popkey of non occuring keys
253 generates a KeyError exception
254 """
233 dct = dict(a=1, b=2, c=3)
255 dct = dict(a=1, b=2, c=3)
234 nt.assert_raises(KeyError, genutils.popkey, dct, "d")
256 nt.assert_raises(KeyError, genutils.popkey, dct, "d")
235
257
236 def test_popkey_3():
258 def test_popkey_3():
259 """test_popkey_3, Tests to see that popkey calls returns the correct value
260 and that the key/value was removed from the dict.
261 """
237 dct = dict(a=1, b=2, c=3)
262 dct = dict(a=1, b=2, c=3)
238 nt.assert_equal(genutils.popkey(dct, "A", 13), 13)
263 nt.assert_equal(genutils.popkey(dct, "A", 13), 13)
239 nt.assert_equal(dct, dict(a=1, b=2, c=3))
264 nt.assert_equal(dct, dict(a=1, b=2, c=3))
General Comments 0
You need to be logged in to leave comments. Login now