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