##// END OF EJS Templates
Added small test for function that didn't have one. Little cleanups.
Fernando Perez -
Show More
@@ -1,116 +1,114 b''
1 """ User configuration file for IPython
1 """ User configuration file for IPython
2
2
3 This is a more flexible and safe way to configure ipython than *rc files
3 This is a more flexible and safe way to configure ipython than *rc files
4 (ipythonrc, ipythonrc-pysh etc.)
4 (ipythonrc, ipythonrc-pysh etc.)
5
5
6 This file is always imported on ipython startup. You can import the
6 This file is always imported on ipython startup. You can import the
7 ipython extensions you need here (see IPython/Extensions directory).
7 ipython extensions you need here (see IPython/Extensions directory).
8
8
9 Feel free to edit this file to customize your ipython experience.
9 Feel free to edit this file to customize your ipython experience.
10
10
11 Note that as such this file does nothing, for backwards compatibility.
11 Note that as such this file does nothing, for backwards compatibility.
12 Consult e.g. file 'ipy_profile_sh.py' for an example of the things
12 Consult e.g. file 'ipy_profile_sh.py' for an example of the things
13 you can do here.
13 you can do here.
14
14
15 See http://ipython.scipy.org/moin/IpythonExtensionApi for detailed
15 See http://ipython.scipy.org/moin/IpythonExtensionApi for detailed
16 description on what you could do here.
16 description on what you could do here.
17 """
17 """
18
18
19 # Most of your config files and extensions will probably start with this import
19 # Most of your config files and extensions will probably start with this import
20
20
21 import IPython.ipapi
21 import IPython.ipapi
22 ip = IPython.ipapi.get()
22 ip = IPython.ipapi.get()
23
23
24 # You probably want to uncomment this if you did %upgrade -nolegacy
24 # You probably want to uncomment this if you did %upgrade -nolegacy
25 # import ipy_defaults
25 # import ipy_defaults
26
26
27 import os
27 import os
28
28
29 def main():
29 def main():
30
30
31 # uncomment if you want to get ipython -p sh behaviour
31 # uncomment if you want to get ipython -p sh behaviour
32 # without having to use command line switches
32 # without having to use command line switches
33 # import ipy_profile_sh
33 # import ipy_profile_sh
34
34
35 # Configure your favourite editor?
35 # Configure your favourite editor?
36 # Good idea e.g. for %edit os.path.isfile
36 # Good idea e.g. for %edit os.path.isfile
37
37
38 #import ipy_editors
38 #import ipy_editors
39
39
40 # Choose one of these:
40 # Choose one of these:
41
41
42 #ipy_editors.scite()
42 #ipy_editors.scite()
43 #ipy_editors.scite('c:/opt/scite/scite.exe')
43 #ipy_editors.scite('c:/opt/scite/scite.exe')
44 #ipy_editors.komodo()
44 #ipy_editors.komodo()
45 #ipy_editors.idle()
45 #ipy_editors.idle()
46 # ... or many others, try 'ipy_editors??' after import to see them
46 # ... or many others, try 'ipy_editors??' after import to see them
47
47
48 # Or roll your own:
48 # Or roll your own:
49 #ipy_editors.install_editor("c:/opt/jed +$line $file")
49 #ipy_editors.install_editor("c:/opt/jed +$line $file")
50
50
51
51
52 o = ip.options
52 o = ip.options
53 # An example on how to set options
53 # An example on how to set options
54 #o.autocall = 1
54 #o.autocall = 1
55 o.system_verbose = 0
55 o.system_verbose = 0
56
56
57 #import_all("os sys")
57 #import_all("os sys")
58 #execf('~/_ipython/ns.py')
58 #execf('~/_ipython/ns.py')
59
59
60
60
61 # -- prompt
61 # -- prompt
62 # A different, more compact set of prompts from the default ones, that
62 # A different, more compact set of prompts from the default ones, that
63 # always show your current location in the filesystem:
63 # always show your current location in the filesystem:
64
64
65 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
65 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
66 #o.prompt_in2 = r'.\D: '
66 #o.prompt_in2 = r'.\D: '
67 #o.prompt_out = r'[\#] '
67 #o.prompt_out = r'[\#] '
68
68
69 # Try one of these color settings if you can't read the text easily
69 # Try one of these color settings if you can't read the text easily
70 # autoexec is a list of IPython commands to execute on startup
70 # autoexec is a list of IPython commands to execute on startup
71 #o.autoexec.append('%colors LightBG')
71 #o.autoexec.append('%colors LightBG')
72 #o.autoexec.append('%colors NoColor')
72 #o.autoexec.append('%colors NoColor')
73 #o.autoexec.append('%colors Linux')
73 #o.autoexec.append('%colors Linux')
74
74
75 # for sane integer division that converts to float (1/2 == 0.5)
75 # for sane integer division that converts to float (1/2 == 0.5)
76 #o.autoexec.append('from __future__ import division')
76 #o.autoexec.append('from __future__ import division')
77
77
78 # For %tasks and %kill
78 # For %tasks and %kill
79 #import jobctrl
79 #import jobctrl
80
80
81 # For autoreloading of modules (%autoreload, %aimport)
81 # For autoreloading of modules (%autoreload, %aimport)
82 #import ipy_autoreload
82 #import ipy_autoreload
83
83
84 # For winpdb support (%wdb)
84 # For winpdb support (%wdb)
85 #import ipy_winpdb
85 #import ipy_winpdb
86
86
87 # For bzr completer, requires bzrlib (the python installation of bzr)
87 # For bzr completer, requires bzrlib (the python installation of bzr)
88 #ip.load('ipy_bzr')
88 #ip.load('ipy_bzr')
89
89
90 # Tab completer that is not quite so picky (i.e.
90 # Tab completer that is not quite so picky (i.e.
91 # "foo".<TAB> and str(2).<TAB> will work). Complete
91 # "foo".<TAB> and str(2).<TAB> will work). Complete
92 # at your own risk!
92 # at your own risk!
93 #import ipy_greedycompleter
93 #import ipy_greedycompleter
94
94
95 # If you are on Linux, you may be annoyed by
95 # If you are on Linux, you may be annoyed by
96 # "Display all N possibilities? (y or n)" on tab completion,
96 # "Display all N possibilities? (y or n)" on tab completion,
97 # as well as the paging through "more". Uncomment the following
97 # as well as the paging through "more". Uncomment the following
98 # lines to disable that behaviour
98 # lines to disable that behaviour
99 #import readline
99 #import readline
100 #readline.parse_and_bind('set completion-query-items 1000')
100 #readline.parse_and_bind('set completion-query-items 1000')
101 #readline.parse_and_bind('set page-completions no')
101 #readline.parse_and_bind('set page-completions no')
102
102
103
103
104
105
106 # some config helper functions you can use
104 # some config helper functions you can use
107 def import_all(modules):
105 def import_all(modules):
108 """ Usage: import_all("os sys") """
106 """ Usage: import_all("os sys") """
109 for m in modules.split():
107 for m in modules.split():
110 ip.ex("from %s import *" % m)
108 ip.ex("from %s import *" % m)
111
109
112 def execf(fname):
110 def execf(fname):
113 """ Execute a file in user namespace """
111 """ Execute a file in user namespace """
114 ip.ex('execfile("%s")' % os.path.expanduser(fname))
112 ip.ex('execfile("%s")' % os.path.expanduser(fname))
115
113
116 main()
114 main()
@@ -1,297 +1,306 b''
1 # encoding: utf-8
1 # encoding: utf-8
2
2
3 """Tests for genutils.py"""
3 """Tests for genutils.py"""
4
4
5 __docformat__ = "restructuredtext en"
5 __docformat__ = "restructuredtext en"
6
6
7 #-----------------------------------------------------------------------------
7 #-----------------------------------------------------------------------------
8 # Copyright (C) 2008 The IPython Development Team
8 # Copyright (C) 2008 The IPython Development Team
9 #
9 #
10 # Distributed under the terms of the BSD License. The full license is in
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
11 # the file COPYING, distributed as part of this software.
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13
13
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 # stdlib
18 # stdlib
19 import os
19 import os
20 import shutil
20 import shutil
21 import sys
21 import sys
22 import tempfile
22 import tempfile
23
23
24 from os.path import join, abspath, split
24 from os.path import join, abspath, split
25
25
26 # third-party
26 # third-party
27 import nose.tools as nt
27 import nose.tools as nt
28
28
29 from nose import with_setup
29 from nose import with_setup
30 from nose.tools import raises
30 from nose.tools import raises
31
31
32 # Our own
32 # Our own
33 import IPython
33 import IPython
34 from IPython import genutils
34 from IPython import genutils
35 from IPython.testing.decorators import skipif, skip_if_not_win32
35 from IPython.testing.decorators import skipif, skip_if_not_win32
36
36
37 # Platform-dependent imports
37 # Platform-dependent imports
38 try:
38 try:
39 import _winreg as wreg
39 import _winreg as wreg
40 except ImportError:
40 except ImportError:
41 #Fake _winreg module on none windows platforms
41 #Fake _winreg module on none windows platforms
42 import new
42 import new
43 sys.modules["_winreg"] = new.module("_winreg")
43 sys.modules["_winreg"] = new.module("_winreg")
44 import _winreg as wreg
44 import _winreg as wreg
45 #Add entries that needs to be stubbed by the testing code
45 #Add entries that needs to be stubbed by the testing code
46 (wreg.OpenKey, wreg.QueryValueEx,) = (None, None)
46 (wreg.OpenKey, wreg.QueryValueEx,) = (None, None)
47
47
48 #-----------------------------------------------------------------------------
48 #-----------------------------------------------------------------------------
49 # Globals
49 # Globals
50 #-----------------------------------------------------------------------------
50 #-----------------------------------------------------------------------------
51 env = os.environ
51 env = os.environ
52 TEST_FILE_PATH = split(abspath(__file__))[0]
52 TEST_FILE_PATH = split(abspath(__file__))[0]
53 TMP_TEST_DIR = tempfile.mkdtemp()
53 TMP_TEST_DIR = tempfile.mkdtemp()
54 HOME_TEST_DIR = join(TMP_TEST_DIR, "home_test_dir")
54 HOME_TEST_DIR = join(TMP_TEST_DIR, "home_test_dir")
55 IP_TEST_DIR = join(HOME_TEST_DIR,'_ipython')
55 IP_TEST_DIR = join(HOME_TEST_DIR,'_ipython')
56 #
56 #
57 # Setup/teardown functions/decorators
57 # Setup/teardown functions/decorators
58 #
58 #
59
59
60 def setup():
60 def setup():
61 """Setup testenvironment for the module:
61 """Setup testenvironment for the module:
62
62
63 - Adds dummy home dir tree
63 - Adds dummy home dir tree
64 """
64 """
65 # Do not mask exceptions here. In particular, catching WindowsError is a
65 # Do not mask exceptions here. In particular, catching WindowsError is a
66 # problem because that exception is only defined on Windows...
66 # problem because that exception is only defined on Windows...
67 os.makedirs(IP_TEST_DIR)
67 os.makedirs(IP_TEST_DIR)
68
68
69 def teardown():
69 def teardown():
70 """Teardown testenvironment for the module:
70 """Teardown testenvironment for the module:
71
71
72 - Remove dummy home dir tree
72 - Remove dummy home dir tree
73 """
73 """
74 # Note: we remove the parent test dir, which is the root of all test
74 # Note: we remove the parent test dir, which is the root of all test
75 # subdirs we may have created. Use shutil instead of os.removedirs, so
75 # subdirs we may have created. Use shutil instead of os.removedirs, so
76 # that non-empty directories are all recursively removed.
76 # that non-empty directories are all recursively removed.
77 shutil.rmtree(TMP_TEST_DIR)
77 shutil.rmtree(TMP_TEST_DIR)
78
78
79
79
80 def setup_environment():
80 def setup_environment():
81 """Setup testenvironment for some functions that are tested
81 """Setup testenvironment for some functions that are tested
82 in this module. In particular this functions stores attributes
82 in this module. In particular this functions stores attributes
83 and other things that we need to stub in some test functions.
83 and other things that we need to stub in some test functions.
84 This needs to be done on a function level and not module level because
84 This needs to be done on a function level and not module level because
85 each testfunction needs a pristine environment.
85 each testfunction needs a pristine environment.
86 """
86 """
87 global oldstuff, platformstuff
87 global oldstuff, platformstuff
88 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
88 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
89
89
90 if os.name == 'nt':
90 if os.name == 'nt':
91 platformstuff = (wreg.OpenKey, wreg.QueryValueEx,)
91 platformstuff = (wreg.OpenKey, wreg.QueryValueEx,)
92
92
93 if 'IPYTHONDIR' in env:
93 if 'IPYTHONDIR' in env:
94 del env['IPYTHONDIR']
94 del env['IPYTHONDIR']
95
95
96 def teardown_environment():
96 def teardown_environment():
97 """Restore things that were remebered by the setup_environment function
97 """Restore things that were remebered by the setup_environment function
98 """
98 """
99 (oldenv, os.name, genutils.get_home_dir, IPython.__file__,) = oldstuff
99 (oldenv, os.name, genutils.get_home_dir, IPython.__file__,) = oldstuff
100 for key in env.keys():
100 for key in env.keys():
101 if key not in oldenv:
101 if key not in oldenv:
102 del env[key]
102 del env[key]
103 env.update(oldenv)
103 env.update(oldenv)
104 if hasattr(sys, 'frozen'):
104 if hasattr(sys, 'frozen'):
105 del sys.frozen
105 del sys.frozen
106 if os.name == 'nt':
106 if os.name == 'nt':
107 (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
107 (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
108
108
109 # Build decorator that uses the setup_environment/setup_environment
109 # Build decorator that uses the setup_environment/setup_environment
110 with_enivronment = with_setup(setup_environment, teardown_environment)
110 with_enivronment = with_setup(setup_environment, teardown_environment)
111
111
112
112
113 #
113 #
114 # Tests for get_home_dir
114 # Tests for get_home_dir
115 #
115 #
116
116
117 @skip_if_not_win32
117 @skip_if_not_win32
118 @with_enivronment
118 @with_enivronment
119 def test_get_home_dir_1():
119 def test_get_home_dir_1():
120 """Testcase for py2exe logic, un-compressed lib
120 """Testcase for py2exe logic, un-compressed lib
121 """
121 """
122 sys.frozen = True
122 sys.frozen = True
123
123
124 #fake filename for IPython.__init__
124 #fake filename for IPython.__init__
125 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
125 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
126
126
127 home_dir = genutils.get_home_dir()
127 home_dir = genutils.get_home_dir()
128 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
128 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
129
129
130 @skip_if_not_win32
130 @skip_if_not_win32
131 @with_enivronment
131 @with_enivronment
132 def test_get_home_dir_2():
132 def test_get_home_dir_2():
133 """Testcase for py2exe logic, compressed lib
133 """Testcase for py2exe logic, compressed lib
134 """
134 """
135 sys.frozen = True
135 sys.frozen = True
136 #fake filename for IPython.__init__
136 #fake filename for IPython.__init__
137 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
137 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
138
138
139 home_dir = genutils.get_home_dir()
139 home_dir = genutils.get_home_dir()
140 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower())
140 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower())
141
141
142 @with_enivronment
142 @with_enivronment
143 def test_get_home_dir_3():
143 def test_get_home_dir_3():
144 """Testcase $HOME is set, then use its value as home directory."""
144 """Testcase $HOME is set, then use its value as home directory."""
145 env["HOME"] = HOME_TEST_DIR
145 env["HOME"] = HOME_TEST_DIR
146 home_dir = genutils.get_home_dir()
146 home_dir = genutils.get_home_dir()
147 nt.assert_equal(home_dir, env["HOME"])
147 nt.assert_equal(home_dir, env["HOME"])
148
148
149 @with_enivronment
149 @with_enivronment
150 def test_get_home_dir_4():
150 def test_get_home_dir_4():
151 """Testcase $HOME is not set, os=='poix'.
151 """Testcase $HOME is not set, os=='poix'.
152 This should fail with HomeDirError"""
152 This should fail with HomeDirError"""
153
153
154 os.name = 'posix'
154 os.name = 'posix'
155 if 'HOME' in env: del env['HOME']
155 if 'HOME' in env: del env['HOME']
156 nt.assert_raises(genutils.HomeDirError, genutils.get_home_dir)
156 nt.assert_raises(genutils.HomeDirError, genutils.get_home_dir)
157
157
158 @skip_if_not_win32
158 @skip_if_not_win32
159 @with_enivronment
159 @with_enivronment
160 def test_get_home_dir_5():
160 def test_get_home_dir_5():
161 """Testcase $HOME is not set, os=='nt'
161 """Testcase $HOME is not set, os=='nt'
162 env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
162 env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
163
163
164 os.name = 'nt'
164 os.name = 'nt'
165 if 'HOME' in env: del env['HOME']
165 if 'HOME' in env: del env['HOME']
166 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR)
166 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR)
167
167
168 home_dir = genutils.get_home_dir()
168 home_dir = genutils.get_home_dir()
169 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
169 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
170
170
171 @skip_if_not_win32
171 @skip_if_not_win32
172 @with_enivronment
172 @with_enivronment
173 def test_get_home_dir_6():
173 def test_get_home_dir_6():
174 """Testcase $HOME is not set, os=='nt'
174 """Testcase $HOME is not set, os=='nt'
175 env['HOMEDRIVE'],env['HOMEPATH'] do not point to path.
175 env['HOMEDRIVE'],env['HOMEPATH'] do not point to path.
176 env['USERPROFILE'] points to path
176 env['USERPROFILE'] points to path
177 """
177 """
178
178
179 os.name = 'nt'
179 os.name = 'nt'
180 if 'HOME' in env: del env['HOME']
180 if 'HOME' in env: del env['HOME']
181 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST"
181 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST"
182 env["USERPROFILE"] = abspath(HOME_TEST_DIR)
182 env["USERPROFILE"] = abspath(HOME_TEST_DIR)
183
183
184 home_dir = genutils.get_home_dir()
184 home_dir = genutils.get_home_dir()
185 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
185 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
186
186
187 # Should we stub wreg fully so we can run the test on all platforms?
187 # Should we stub wreg fully so we can run the test on all platforms?
188 @skip_if_not_win32
188 @skip_if_not_win32
189 @with_enivronment
189 @with_enivronment
190 def test_get_home_dir_7():
190 def test_get_home_dir_7():
191 """Testcase $HOME is not set, os=='nt'
191 """Testcase $HOME is not set, os=='nt'
192 env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing
192 env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing
193 """
193 """
194 os.name = 'nt'
194 os.name = 'nt'
195 if 'HOME' in env: del env['HOME']
195 if 'HOME' in env: del env['HOME']
196 if 'HOMEDRIVE' in env: del env['HOMEDRIVE']
196 if 'HOMEDRIVE' in env: del env['HOMEDRIVE']
197
197
198 #Stub windows registry functions
198 #Stub windows registry functions
199 def OpenKey(x, y):
199 def OpenKey(x, y):
200 class key:
200 class key:
201 def Close(self):
201 def Close(self):
202 pass
202 pass
203 return key()
203 return key()
204 def QueryValueEx(x, y):
204 def QueryValueEx(x, y):
205 return [abspath(HOME_TEST_DIR)]
205 return [abspath(HOME_TEST_DIR)]
206
206
207 wreg.OpenKey = OpenKey
207 wreg.OpenKey = OpenKey
208 wreg.QueryValueEx = QueryValueEx
208 wreg.QueryValueEx = QueryValueEx
209
209
210 home_dir = genutils.get_home_dir()
210 home_dir = genutils.get_home_dir()
211 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
211 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
212
212
213 #
213 #
214 # Tests for get_ipython_dir
214 # Tests for get_ipython_dir
215 #
215 #
216
216
217 @with_enivronment
217 @with_enivronment
218 def test_get_ipython_dir_1():
218 def test_get_ipython_dir_1():
219 """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions."""
219 """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions."""
220 env['IPYTHONDIR'] = "someplace/.ipython"
220 env['IPYTHONDIR'] = "someplace/.ipython"
221 ipdir = genutils.get_ipython_dir()
221 ipdir = genutils.get_ipython_dir()
222 nt.assert_equal(ipdir, os.path.abspath("someplace/.ipython"))
222 nt.assert_equal(ipdir, os.path.abspath("someplace/.ipython"))
223
223
224
224
225 @with_enivronment
225 @with_enivronment
226 def test_get_ipython_dir_2():
226 def test_get_ipython_dir_2():
227 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
227 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
228 genutils.get_home_dir = lambda : "someplace"
228 genutils.get_home_dir = lambda : "someplace"
229 os.name = "posix"
229 os.name = "posix"
230 ipdir = genutils.get_ipython_dir()
230 ipdir = genutils.get_ipython_dir()
231 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", ".ipython")))
231 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", ".ipython")))
232
232
233 @with_enivronment
233 @with_enivronment
234 def test_get_ipython_dir_3():
234 def test_get_ipython_dir_3():
235 """test_get_ipython_dir_3, Testcase to see if we can call get_ipython_dir without Exceptions."""
235 """test_get_ipython_dir_3, Testcase to see if we can call get_ipython_dir without Exceptions."""
236 genutils.get_home_dir = lambda : "someplace"
236 genutils.get_home_dir = lambda : "someplace"
237 os.name = "nt"
237 os.name = "nt"
238 ipdir = genutils.get_ipython_dir()
238 ipdir = genutils.get_ipython_dir()
239 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", "_ipython")))
239 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", "_ipython")))
240
240
241 #
241 #
242 # Tests for get_security_dir
242 # Tests for get_security_dir
243 #
243 #
244
244
245 @with_enivronment
245 @with_enivronment
246 def test_get_security_dir():
246 def test_get_security_dir():
247 """Testcase to see if we can call get_security_dir without Exceptions."""
247 """Testcase to see if we can call get_security_dir without Exceptions."""
248 sdir = genutils.get_security_dir()
248 sdir = genutils.get_security_dir()
249
249
250 #
250 #
251 # Tests for get_log_dir
251 # Tests for get_log_dir
252 #
252 #
253
253
254 @with_enivronment
254 @with_enivronment
255 def test_get_log_dir():
255 def test_get_log_dir():
256 """Testcase to see if we can call get_log_dir without Exceptions."""
256 """Testcase to see if we can call get_log_dir without Exceptions."""
257 sdir = genutils.get_log_dir()
257 sdir = genutils.get_log_dir()
258
258
259 #
259 #
260 # Tests for popkey
260 # Tests for popkey
261 #
261 #
262
262
263 def test_popkey_1():
263 def test_popkey_1():
264 """test_popkey_1, Basic usage test of popkey
264 """test_popkey_1, Basic usage test of popkey
265 """
265 """
266 dct = dict(a=1, b=2, c=3)
266 dct = dict(a=1, b=2, c=3)
267 nt.assert_equal(genutils.popkey(dct, "a"), 1)
267 nt.assert_equal(genutils.popkey(dct, "a"), 1)
268 nt.assert_equal(dct, dict(b=2, c=3))
268 nt.assert_equal(dct, dict(b=2, c=3))
269 nt.assert_equal(genutils.popkey(dct, "b"), 2)
269 nt.assert_equal(genutils.popkey(dct, "b"), 2)
270 nt.assert_equal(dct, dict(c=3))
270 nt.assert_equal(dct, dict(c=3))
271 nt.assert_equal(genutils.popkey(dct, "c"), 3)
271 nt.assert_equal(genutils.popkey(dct, "c"), 3)
272 nt.assert_equal(dct, dict())
272 nt.assert_equal(dct, dict())
273
273
274 def test_popkey_2():
274 def test_popkey_2():
275 """test_popkey_2, Test to see that popkey of non occuring keys
275 """test_popkey_2, Test to see that popkey of non occuring keys
276 generates a KeyError exception
276 generates a KeyError exception
277 """
277 """
278 dct = dict(a=1, b=2, c=3)
278 dct = dict(a=1, b=2, c=3)
279 nt.assert_raises(KeyError, genutils.popkey, dct, "d")
279 nt.assert_raises(KeyError, genutils.popkey, dct, "d")
280
280
281 def test_popkey_3():
281 def test_popkey_3():
282 """test_popkey_3, Tests to see that popkey calls returns the correct value
282 """test_popkey_3, Tests to see that popkey calls returns the correct value
283 and that the key/value was removed from the dict.
283 and that the key/value was removed from the dict.
284 """
284 """
285 dct = dict(a=1, b=2, c=3)
285 dct = dict(a=1, b=2, c=3)
286 nt.assert_equal(genutils.popkey(dct, "A", 13), 13)
286 nt.assert_equal(genutils.popkey(dct, "A", 13), 13)
287 nt.assert_equal(dct, dict(a=1, b=2, c=3))
287 nt.assert_equal(dct, dict(a=1, b=2, c=3))
288 nt.assert_equal(genutils.popkey(dct, "B", 14), 14)
288 nt.assert_equal(genutils.popkey(dct, "B", 14), 14)
289 nt.assert_equal(dct, dict(a=1, b=2, c=3))
289 nt.assert_equal(dct, dict(a=1, b=2, c=3))
290 nt.assert_equal(genutils.popkey(dct, "C", 15), 15)
290 nt.assert_equal(genutils.popkey(dct, "C", 15), 15)
291 nt.assert_equal(dct, dict(a=1, b=2, c=3))
291 nt.assert_equal(dct, dict(a=1, b=2, c=3))
292 nt.assert_equal(genutils.popkey(dct, "a"), 1)
292 nt.assert_equal(genutils.popkey(dct, "a"), 1)
293 nt.assert_equal(dct, dict(b=2, c=3))
293 nt.assert_equal(dct, dict(b=2, c=3))
294 nt.assert_equal(genutils.popkey(dct, "b"), 2)
294 nt.assert_equal(genutils.popkey(dct, "b"), 2)
295 nt.assert_equal(dct, dict(c=3))
295 nt.assert_equal(dct, dict(c=3))
296 nt.assert_equal(genutils.popkey(dct, "c"), 3)
296 nt.assert_equal(genutils.popkey(dct, "c"), 3)
297 nt.assert_equal(dct, dict())
297 nt.assert_equal(dct, dict())
298
299
300 def test_filefind():
301 """Various tests for filefind"""
302 f = tempfile.NamedTemporaryFile()
303 print 'fname:',f.name
304 alt_dirs = genutils.get_ipython_dir()
305 t = genutils.filefind(f.name,alt_dirs)
306 print 'found:',t
General Comments 0
You need to be logged in to leave comments. Login now