Show More
@@ -250,7 +250,7 b' def get_ipython_dir():' | |||||
250 | """ |
|
250 | """ | |
251 | ipdir_def = '.ipython' |
|
251 | ipdir_def = '.ipython' | |
252 | home_dir = get_home_dir() |
|
252 | home_dir = get_home_dir() | |
253 | #import pdb; pdb.set_trace() # dbg |
|
253 | # import pdb; pdb.set_trace() # dbg | |
254 | ipdir = os.environ.get( |
|
254 | ipdir = os.environ.get( | |
255 | 'IPYTHON_DIR', os.environ.get( |
|
255 | 'IPYTHON_DIR', os.environ.get( | |
256 | 'IPYTHONDIR', os.path.join(home_dir, ipdir_def) |
|
256 | 'IPYTHONDIR', os.path.join(home_dir, ipdir_def) |
@@ -26,15 +26,7 b' from nose import with_setup' | |||||
26 | import IPython |
|
26 | import IPython | |
27 | from IPython.testing import decorators as dec |
|
27 | from IPython.testing import decorators as dec | |
28 | from IPython.testing.decorators import skip_if_not_win32 |
|
28 | from IPython.testing.decorators import skip_if_not_win32 | |
29 |
from IPython.utils |
|
29 | from IPython.utils import path | |
30 | get_home_dir, |
|
|||
31 | HomeDirError, |
|
|||
32 | get_ipython_dir, |
|
|||
33 | get_ipython_package_dir, |
|
|||
34 | get_ipython_module_path, |
|
|||
35 | filefind, |
|
|||
36 | get_long_path_name |
|
|||
37 | ) |
|
|||
38 |
|
30 | |||
39 | # Platform-dependent imports |
|
31 | # Platform-dependent imports | |
40 | try: |
|
32 | try: | |
@@ -68,6 +60,7 b' def setup():' | |||||
68 | # problem because that exception is only defined on Windows... |
|
60 | # problem because that exception is only defined on Windows... | |
69 | os.makedirs(IP_TEST_DIR) |
|
61 | os.makedirs(IP_TEST_DIR) | |
70 |
|
62 | |||
|
63 | ||||
71 | def teardown(): |
|
64 | def teardown(): | |
72 | """Teardown testenvironment for the module: |
|
65 | """Teardown testenvironment for the module: | |
73 |
|
66 | |||
@@ -78,7 +71,7 b' def teardown():' | |||||
78 | # that non-empty directories are all recursively removed. |
|
71 | # that non-empty directories are all recursively removed. | |
79 | shutil.rmtree(TMP_TEST_DIR) |
|
72 | shutil.rmtree(TMP_TEST_DIR) | |
80 |
|
73 | |||
81 |
|
74 | |||
82 | def setup_environment(): |
|
75 | def setup_environment(): | |
83 | """Setup testenvironment for some functions that are tested |
|
76 | """Setup testenvironment for some functions that are tested | |
84 | in this module. In particular this functions stores attributes |
|
77 | in this module. In particular this functions stores attributes | |
@@ -87,12 +80,12 b' def setup_environment():' | |||||
87 | each testfunction needs a pristine environment. |
|
80 | each testfunction needs a pristine environment. | |
88 | """ |
|
81 | """ | |
89 | global oldstuff, platformstuff |
|
82 | global oldstuff, platformstuff | |
90 | oldstuff = (env.copy(), os.name, get_home_dir, IPython.__file__) |
|
83 | oldstuff = (env.copy(), os.name, path.get_home_dir, IPython.__file__) | |
91 |
|
84 | |||
92 | if os.name == 'nt': |
|
85 | if os.name == 'nt': | |
93 | platformstuff = (wreg.OpenKey, wreg.QueryValueEx,) |
|
86 | platformstuff = (wreg.OpenKey, wreg.QueryValueEx,) | |
94 |
|
87 | |||
95 |
|
88 | |||
96 | def teardown_environment(): |
|
89 | def teardown_environment(): | |
97 | """Restore things that were remebered by the setup_environment function |
|
90 | """Restore things that were remebered by the setup_environment function | |
98 | """ |
|
91 | """ | |
@@ -121,9 +114,10 b' def test_get_home_dir_1():' | |||||
121 | #fake filename for IPython.__init__ |
|
114 | #fake filename for IPython.__init__ | |
122 | IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py")) |
|
115 | IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py")) | |
123 |
|
116 | |||
124 | home_dir = get_home_dir() |
|
117 | path.home_dir = get_home_dir() | |
125 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) |
|
118 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
126 |
|
119 | |||
|
120 | ||||
127 | @skip_if_not_win32 |
|
121 | @skip_if_not_win32 | |
128 | @with_environment |
|
122 | @with_environment | |
129 | def test_get_home_dir_2(): |
|
123 | def test_get_home_dir_2(): | |
@@ -133,25 +127,28 b' def test_get_home_dir_2():' | |||||
133 | #fake filename for IPython.__init__ |
|
127 | #fake filename for IPython.__init__ | |
134 | IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower() |
|
128 | IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower() | |
135 |
|
129 | |||
136 | home_dir = get_home_dir() |
|
130 | home_dir = path.get_home_dir() | |
137 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower()) |
|
131 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower()) | |
138 |
|
132 | |||
|
133 | ||||
139 | @with_environment |
|
134 | @with_environment | |
140 | def test_get_home_dir_3(): |
|
135 | def test_get_home_dir_3(): | |
141 | """Testcase $HOME is set, then use its value as home directory.""" |
|
136 | """Testcase $HOME is set, then use its value as home directory.""" | |
142 | env["HOME"] = HOME_TEST_DIR |
|
137 | env["HOME"] = HOME_TEST_DIR | |
143 | home_dir = get_home_dir() |
|
138 | home_dir = path.get_home_dir() | |
144 | nt.assert_equal(home_dir, env["HOME"]) |
|
139 | nt.assert_equal(home_dir, env["HOME"]) | |
145 |
|
140 | |||
|
141 | ||||
146 | @with_environment |
|
142 | @with_environment | |
147 | def test_get_home_dir_4(): |
|
143 | def test_get_home_dir_4(): | |
148 | """Testcase $HOME is not set, os=='poix'. |
|
144 | """Testcase $HOME is not set, os=='posix'. | |
149 | This should fail with HomeDirError""" |
|
145 | This should fail with HomeDirError""" | |
150 |
|
146 | |||
151 | os.name = 'posix' |
|
147 | os.name = 'posix' | |
152 | if 'HOME' in env: del env['HOME'] |
|
148 | if 'HOME' in env: del env['HOME'] | |
153 | nt.assert_raises(HomeDirError, get_home_dir) |
|
149 | nt.assert_raises(path.HomeDirError, path.get_home_dir) | |
154 |
|
150 | |||
|
151 | ||||
155 | @skip_if_not_win32 |
|
152 | @skip_if_not_win32 | |
156 | @with_environment |
|
153 | @with_environment | |
157 | def test_get_home_dir_5(): |
|
154 | def test_get_home_dir_5(): | |
@@ -162,9 +159,10 b' def test_get_home_dir_5():' | |||||
162 | if 'HOME' in env: del env['HOME'] |
|
159 | if 'HOME' in env: del env['HOME'] | |
163 | env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR) |
|
160 | env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR) | |
164 |
|
161 | |||
165 | home_dir = get_home_dir() |
|
162 | home_dir = path.get_home_dir() | |
166 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) |
|
163 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
167 |
|
164 | |||
|
165 | ||||
168 | @skip_if_not_win32 |
|
166 | @skip_if_not_win32 | |
169 | @with_environment |
|
167 | @with_environment | |
170 | def test_get_home_dir_6(): |
|
168 | def test_get_home_dir_6(): | |
@@ -178,9 +176,10 b' def test_get_home_dir_6():' | |||||
178 | env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST" |
|
176 | env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST" | |
179 | env["USERPROFILE"] = abspath(HOME_TEST_DIR) |
|
177 | env["USERPROFILE"] = abspath(HOME_TEST_DIR) | |
180 |
|
178 | |||
181 | home_dir = get_home_dir() |
|
179 | home_dir = path.get_home_dir() | |
182 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) |
|
180 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
183 |
|
181 | |||
|
182 | ||||
184 | # Should we stub wreg fully so we can run the test on all platforms? |
|
183 | # Should we stub wreg fully so we can run the test on all platforms? | |
185 | @skip_if_not_win32 |
|
184 | @skip_if_not_win32 | |
186 | @with_environment |
|
185 | @with_environment | |
@@ -206,7 +205,7 b' def test_get_home_dir_7():' | |||||
206 | wreg.OpenKey = OpenKey |
|
205 | wreg.OpenKey = OpenKey | |
207 | wreg.QueryValueEx = QueryValueEx |
|
206 | wreg.QueryValueEx = QueryValueEx | |
208 |
|
207 | |||
209 | home_dir = get_home_dir() |
|
208 | home_dir = path.get_home_dir() | |
210 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) |
|
209 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
211 |
|
210 | |||
212 |
|
211 | |||
@@ -214,47 +213,48 b' def test_get_home_dir_7():' | |||||
214 | def test_get_ipython_dir_1(): |
|
213 | def test_get_ipython_dir_1(): | |
215 | """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions.""" |
|
214 | """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions.""" | |
216 | env['IPYTHON_DIR'] = "someplace/.ipython" |
|
215 | env['IPYTHON_DIR'] = "someplace/.ipython" | |
217 | ipdir = get_ipython_dir() |
|
216 | ipdir = path.get_ipython_dir() | |
218 | nt.assert_equal(ipdir, "someplace/.ipython") |
|
217 | nt.assert_equal(ipdir, "someplace/.ipython") | |
219 |
|
218 | |||
220 |
|
219 | |||
221 | @with_environment |
|
220 | @with_environment | |
222 | def test_get_ipython_dir_2(): |
|
221 | def test_get_ipython_dir_2(): | |
223 | """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" |
|
222 | """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" | |
224 | get_home_dir = lambda : "someplace" |
|
223 | path.get_home_dir = lambda : "someplace" | |
225 | os.name = "posix" |
|
224 | os.name = "posix" | |
226 | env.pop('IPYTHON_DIR', None) |
|
225 | env.pop('IPYTHON_DIR', None) | |
227 | env.pop('IPYTHONDIR', None) |
|
226 | env.pop('IPYTHONDIR', None) | |
228 | ipdir = get_ipython_dir() |
|
227 | ipdir = path.get_ipython_dir() | |
229 | nt.assert_equal(ipdir, os.path.join("someplace", ".ipython")) |
|
228 | nt.assert_equal(ipdir, os.path.join("someplace", ".ipython")) | |
230 |
|
229 | |||
231 |
|
230 | |||
232 | def test_filefind(): |
|
231 | def test_filefind(): | |
233 | """Various tests for filefind""" |
|
232 | """Various tests for filefind""" | |
234 | f = tempfile.NamedTemporaryFile() |
|
233 | f = tempfile.NamedTemporaryFile() | |
235 | print 'fname:',f.name |
|
234 | # print 'fname:',f.name | |
236 | alt_dirs = get_ipython_dir() |
|
235 | alt_dirs = path.get_ipython_dir() | |
237 | t = filefind(f.name, alt_dirs) |
|
236 | t = path.filefind(f.name, alt_dirs) | |
238 | print 'found:',t |
|
237 | # print 'found:',t | |
239 |
|
238 | |||
240 |
|
239 | |||
241 | def test_get_ipython_package_dir(): |
|
240 | def test_get_ipython_package_dir(): | |
242 | ipdir = get_ipython_package_dir() |
|
241 | ipdir = path.get_ipython_package_dir() | |
243 | nt.assert_true(os.path.isdir(ipdir)) |
|
242 | nt.assert_true(os.path.isdir(ipdir)) | |
244 |
|
243 | |||
|
244 | ||||
245 | def test_get_ipython_module_path(): |
|
245 | def test_get_ipython_module_path(): | |
246 | ipapp_path = get_ipython_module_path('IPython.core.ipapp') |
|
246 | ipapp_path = path.get_ipython_module_path('IPython.core.ipapp') | |
247 | nt.assert_true(os.path.isfile(ipapp_path)) |
|
247 | nt.assert_true(os.path.isfile(ipapp_path)) | |
248 |
|
248 | |||
|
249 | ||||
249 | @dec.skip_if_not_win32 |
|
250 | @dec.skip_if_not_win32 | |
250 | def test_get_long_path_name_win32(): |
|
251 | def test_get_long_path_name_win32(): | |
251 | p = get_long_path_name('c:\\docume~1') |
|
252 | p = path.get_long_path_name('c:\\docume~1') | |
252 | nt.assert_equals(p,u'c:\\Documents and Settings') |
|
253 | nt.assert_equals(p,u'c:\\Documents and Settings') | |
253 |
|
254 | |||
254 |
|
255 | |||
255 | @dec.skip_win32 |
|
256 | @dec.skip_win32 | |
256 | def test_get_long_path_name(): |
|
257 | def test_get_long_path_name(): | |
257 | p = get_long_path_name('/usr/local') |
|
258 | p = path.get_long_path_name('/usr/local') | |
258 | nt.assert_equals(p,'/usr/local') |
|
259 | nt.assert_equals(p,'/usr/local') | |
259 |
|
260 | |||
260 |
|
General Comments 0
You need to be logged in to leave comments.
Login now