Show More
@@ -14,10 +14,12 b'' | |||||
14 |
|
14 | |||
15 | from __future__ import with_statement |
|
15 | from __future__ import with_statement | |
16 |
|
16 | |||
|
17 | import errno | |||
17 | import os |
|
18 | import os | |
18 | import shutil |
|
19 | import shutil | |
19 | import sys |
|
20 | import sys | |
20 | import tempfile |
|
21 | import tempfile | |
|
22 | import warnings | |||
21 | from contextlib import contextmanager |
|
23 | from contextlib import contextmanager | |
22 |
|
24 | |||
23 | from os.path import join, abspath, split |
|
25 | from os.path import join, abspath, split | |
@@ -128,6 +130,15 b' def teardown_environment():' | |||||
128 | # Build decorator that uses the setup_environment/setup_environment |
|
130 | # Build decorator that uses the setup_environment/setup_environment | |
129 | with_environment = with_setup(setup_environment, teardown_environment) |
|
131 | with_environment = with_setup(setup_environment, teardown_environment) | |
130 |
|
132 | |||
|
133 | @contextmanager | |||
|
134 | def patch_get_home_dir(dirpath): | |||
|
135 | orig_get_home_dir = path.get_home_dir | |||
|
136 | path.get_home_dir = lambda : dirpath | |||
|
137 | try: | |||
|
138 | yield | |||
|
139 | finally: | |||
|
140 | path.get_home_dir = orig_get_home_dir | |||
|
141 | ||||
131 | @skip_if_not_win32 |
|
142 | @skip_if_not_win32 | |
132 | @with_environment |
|
143 | @with_environment | |
133 | def test_get_home_dir_1(): |
|
144 | def test_get_home_dir_1(): | |
@@ -225,74 +236,96 b' def test_get_ipython_dir_1():' | |||||
225 | @with_environment |
|
236 | @with_environment | |
226 | def test_get_ipython_dir_2(): |
|
237 | def test_get_ipython_dir_2(): | |
227 | """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" |
|
238 | """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" | |
228 |
|
|
239 | with patch_get_home_dir('someplace'): | |
229 | path.get_xdg_dir = lambda : None |
|
240 | path.get_xdg_dir = lambda : None | |
230 | path._writable_dir = lambda path: True |
|
241 | path._writable_dir = lambda path: True | |
231 | os.name = "posix" |
|
242 | os.name = "posix" | |
232 | env.pop('IPYTHON_DIR', None) |
|
243 | env.pop('IPYTHON_DIR', None) | |
233 | env.pop('IPYTHONDIR', None) |
|
244 | env.pop('IPYTHONDIR', None) | |
234 | env.pop('XDG_CONFIG_HOME', None) |
|
245 | env.pop('XDG_CONFIG_HOME', None) | |
235 | ipdir = path.get_ipython_dir() |
|
246 | ipdir = path.get_ipython_dir() | |
236 | nt.assert_equal(ipdir, os.path.join("someplace", ".ipython")) |
|
247 | nt.assert_equal(ipdir, os.path.join("someplace", ".ipython")) | |
237 |
|
248 | |||
238 | @with_environment |
|
249 | @with_environment | |
239 | def test_get_ipython_dir_3(): |
|
250 | def test_get_ipython_dir_3(): | |
240 |
"""test_get_ipython_dir_3, |
|
251 | """test_get_ipython_dir_3, move XDG if defined, and .ipython doesn't exist.""" | |
241 | path.get_home_dir = lambda : "someplace" |
|
252 | tmphome = TemporaryDirectory() | |
242 | path._writable_dir = lambda path: True |
|
253 | try: | |
243 | os.name = "posix" |
|
254 | with patch_get_home_dir(tmphome.name): | |
244 | env.pop('IPYTHON_DIR', None) |
|
255 | os.name = "posix" | |
245 | env.pop('IPYTHONDIR', None) |
|
256 | env.pop('IPYTHON_DIR', None) | |
246 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR |
|
257 | env.pop('IPYTHONDIR', None) | |
247 | ipdir = path.get_ipython_dir() |
|
258 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR | |
248 | if sys.platform == "darwin": |
|
259 | ||
249 | expected = os.path.join("someplace", ".ipython") |
|
260 | with warnings.catch_warnings(record=True) as w: | |
250 | else: |
|
261 | ipdir = path.get_ipython_dir() | |
251 | expected = os.path.join(XDG_TEST_DIR, "ipython") |
|
262 | ||
252 | nt.assert_equal(ipdir, expected) |
|
263 | nt.assert_equal(ipdir, os.path.join(tmphome.name, ".ipython")) | |
|
264 | if sys.platform != 'darwin': | |||
|
265 | nt.assert_equal(len(w), 1) | |||
|
266 | nt.assert_in('Moving', str(w[0])) | |||
|
267 | finally: | |||
|
268 | tmphome.cleanup() | |||
253 |
|
269 | |||
254 | @with_environment |
|
270 | @with_environment | |
255 | def test_get_ipython_dir_4(): |
|
271 | def test_get_ipython_dir_4(): | |
256 |
"""test_get_ipython_dir_4, |
|
272 | """test_get_ipython_dir_4, warn if XDG and home both exist.""" | |
257 |
|
|
273 | with patch_get_home_dir(HOME_TEST_DIR): | |
258 | os.name = "posix" |
|
274 | os.name = "posix" | |
259 | env.pop('IPYTHON_DIR', None) |
|
275 | env.pop('IPYTHON_DIR', None) | |
260 | env.pop('IPYTHONDIR', None) |
|
276 | env.pop('IPYTHONDIR', None) | |
261 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR |
|
277 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR | |
262 | ipdir = path.get_ipython_dir() |
|
278 | try: | |
263 | if sys.platform == "darwin": |
|
279 | os.mkdir(os.path.join(XDG_TEST_DIR, 'ipython')) | |
264 | expected = os.path.join(HOME_TEST_DIR, ".ipython") |
|
280 | except OSError as e: | |
265 | else: |
|
281 | if e.errno != errno.EEXIST: | |
266 | expected = os.path.join(XDG_TEST_DIR, "ipython") |
|
282 | raise | |
267 | nt.assert_equal(ipdir, expected) |
|
283 | ||
|
284 | with warnings.catch_warnings(record=True) as w: | |||
|
285 | ipdir = path.get_ipython_dir() | |||
|
286 | ||||
|
287 | nt.assert_equal(ipdir, os.path.join(HOME_TEST_DIR, ".ipython")) | |||
|
288 | if sys.platform != 'darwin': | |||
|
289 | nt.assert_equal(len(w), 1) | |||
|
290 | nt.assert_in('Ignoring', str(w[0])) | |||
268 |
|
291 | |||
269 | @with_environment |
|
292 | @with_environment | |
270 | def test_get_ipython_dir_5(): |
|
293 | def test_get_ipython_dir_5(): | |
271 | """test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist.""" |
|
294 | """test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist.""" | |
272 |
|
|
295 | with patch_get_home_dir(HOME_TEST_DIR): | |
273 | os.name = "posix" |
|
296 | os.name = "posix" | |
274 | env.pop('IPYTHON_DIR', None) |
|
297 | env.pop('IPYTHON_DIR', None) | |
275 | env.pop('IPYTHONDIR', None) |
|
298 | env.pop('IPYTHONDIR', None) | |
276 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR |
|
299 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR | |
277 | os.rmdir(os.path.join(XDG_TEST_DIR, 'ipython')) |
|
300 | try: | |
278 | ipdir = path.get_ipython_dir() |
|
301 | os.rmdir(os.path.join(XDG_TEST_DIR, 'ipython')) | |
279 | nt.assert_equal(ipdir, IP_TEST_DIR) |
|
302 | except OSError as e: | |
|
303 | if e.errno != errno.ENOENT: | |||
|
304 | raise | |||
|
305 | ipdir = path.get_ipython_dir() | |||
|
306 | nt.assert_equal(ipdir, IP_TEST_DIR) | |||
280 |
|
307 | |||
281 | @with_environment |
|
308 | @with_environment | |
282 | def test_get_ipython_dir_6(): |
|
309 | def test_get_ipython_dir_6(): | |
283 | """test_get_ipython_dir_6, use XDG if defined and neither exist.""" |
|
310 | """test_get_ipython_dir_6, use home over XDG if defined and neither exist.""" | |
284 | xdg = os.path.join(HOME_TEST_DIR, 'somexdg') |
|
311 | xdg = os.path.join(HOME_TEST_DIR, 'somexdg') | |
285 | os.mkdir(xdg) |
|
312 | os.mkdir(xdg) | |
286 | shutil.rmtree(os.path.join(HOME_TEST_DIR, '.ipython')) |
|
313 | shutil.rmtree(os.path.join(HOME_TEST_DIR, '.ipython')) | |
287 |
|
|
314 | with patch_get_home_dir(HOME_TEST_DIR): | |
288 | path.get_xdg_dir = lambda : xdg |
|
315 | orig_get_xdg_dir = path.get_xdg_dir | |
289 | os.name = "posix" |
|
316 | path.get_xdg_dir = lambda : xdg | |
290 | env.pop('IPYTHON_DIR', None) |
|
317 | try: | |
291 | env.pop('IPYTHONDIR', None) |
|
318 | os.name = "posix" | |
292 |
env.pop(' |
|
319 | env.pop('IPYTHON_DIR', None) | |
293 | xdg_ipdir = os.path.join(xdg, "ipython") |
|
320 | env.pop('IPYTHONDIR', None) | |
294 | ipdir = path.get_ipython_dir() |
|
321 | env.pop('XDG_CONFIG_HOME', None) | |
295 | nt.assert_equal(ipdir, xdg_ipdir) |
|
322 | with warnings.catch_warnings(record=True) as w: | |
|
323 | ipdir = path.get_ipython_dir() | |||
|
324 | ||||
|
325 | nt.assert_equal(ipdir, os.path.join(HOME_TEST_DIR, '.ipython')) | |||
|
326 | nt.assert_equal(len(w), 0) | |||
|
327 | finally: | |||
|
328 | path.get_xdg_dir = orig_get_xdg_dir | |||
296 |
|
329 | |||
297 | @with_environment |
|
330 | @with_environment | |
298 | def test_get_ipython_dir_7(): |
|
331 | def test_get_ipython_dir_7(): |
General Comments 0
You need to be logged in to leave comments.
Login now