Show More
@@ -227,13 +227,13 b' def get_home_dir(require_writable=False):' | |||||
227 | def get_xdg_dir(): |
|
227 | def get_xdg_dir(): | |
228 | """Return the XDG_CONFIG_HOME, if it is defined and exists, else None. |
|
228 | """Return the XDG_CONFIG_HOME, if it is defined and exists, else None. | |
229 |
|
229 | |||
230 |
This is only for posix (Linux,Unix, |
|
230 | This is only for non-OS X posix (Linux,Unix,etc.) systems. | |
231 | """ |
|
231 | """ | |
232 |
|
232 | |||
233 | env = os.environ |
|
233 | env = os.environ | |
234 |
|
234 | |||
235 | if os.name == 'posix': |
|
235 | if os.name == 'posix' and sys.platform != 'darwin': | |
236 |
# Linux, Unix, AIX, |
|
236 | # Linux, Unix, AIX, etc. | |
237 | # use ~/.config if empty OR not set |
|
237 | # use ~/.config if empty OR not set | |
238 | xdg = env.get("XDG_CONFIG_HOME", None) or os.path.join(get_home_dir(), '.config') |
|
238 | xdg = env.get("XDG_CONFIG_HOME", None) or os.path.join(get_home_dir(), '.config') | |
239 | if xdg and _writable_dir(xdg): |
|
239 | if xdg and _writable_dir(xdg): |
@@ -93,7 +93,7 b' def setup_environment():' | |||||
93 | each testfunction needs a pristine environment. |
|
93 | each testfunction needs a pristine environment. | |
94 | """ |
|
94 | """ | |
95 | global oldstuff, platformstuff |
|
95 | global oldstuff, platformstuff | |
96 | oldstuff = (env.copy(), os.name, path.get_home_dir, IPython.__file__, os.getcwd()) |
|
96 | oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd()) | |
97 |
|
97 | |||
98 | if os.name == 'nt': |
|
98 | if os.name == 'nt': | |
99 | platformstuff = (wreg.OpenKey, wreg.QueryValueEx,) |
|
99 | platformstuff = (wreg.OpenKey, wreg.QueryValueEx,) | |
@@ -102,7 +102,7 b' def setup_environment():' | |||||
102 | def teardown_environment(): |
|
102 | def teardown_environment(): | |
103 | """Restore things that were remebered by the setup_environment function |
|
103 | """Restore things that were remebered by the setup_environment function | |
104 | """ |
|
104 | """ | |
105 | (oldenv, os.name, path.get_home_dir, IPython.__file__, old_wd) = oldstuff |
|
105 | (oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff | |
106 | os.chdir(old_wd) |
|
106 | os.chdir(old_wd) | |
107 | reload(path) |
|
107 | reload(path) | |
108 |
|
108 | |||
@@ -234,7 +234,11 b' def test_get_ipython_dir_3():' | |||||
234 | env.pop('IPYTHONDIR', None) |
|
234 | env.pop('IPYTHONDIR', None) | |
235 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR |
|
235 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR | |
236 | ipdir = path.get_ipython_dir() |
|
236 | ipdir = path.get_ipython_dir() | |
237 | nt.assert_equal(ipdir, os.path.join(XDG_TEST_DIR, "ipython")) |
|
237 | if sys.platform == "darwin": | |
|
238 | expected = os.path.join("someplace", ".ipython") | |||
|
239 | else: | |||
|
240 | expected = os.path.join(XDG_TEST_DIR, "ipython") | |||
|
241 | nt.assert_equal(ipdir, expected) | |||
238 |
|
242 | |||
239 | @with_environment |
|
243 | @with_environment | |
240 | def test_get_ipython_dir_4(): |
|
244 | def test_get_ipython_dir_4(): | |
@@ -244,9 +248,12 b' def test_get_ipython_dir_4():' | |||||
244 | env.pop('IPYTHON_DIR', None) |
|
248 | env.pop('IPYTHON_DIR', None) | |
245 | env.pop('IPYTHONDIR', None) |
|
249 | env.pop('IPYTHONDIR', None) | |
246 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR |
|
250 | env['XDG_CONFIG_HOME'] = XDG_TEST_DIR | |
247 | xdg_ipdir = os.path.join(XDG_TEST_DIR, "ipython") |
|
|||
248 | ipdir = path.get_ipython_dir() |
|
251 | ipdir = path.get_ipython_dir() | |
249 | nt.assert_equal(ipdir, xdg_ipdir) |
|
252 | if sys.platform == "darwin": | |
|
253 | expected = os.path.join(HOME_TEST_DIR, ".ipython") | |||
|
254 | else: | |||
|
255 | expected = os.path.join(XDG_TEST_DIR, "ipython") | |||
|
256 | nt.assert_equal(ipdir, expected) | |||
250 |
|
257 | |||
251 | @with_environment |
|
258 | @with_environment | |
252 | def test_get_ipython_dir_5(): |
|
259 | def test_get_ipython_dir_5(): | |
@@ -287,12 +294,13 b' def test_get_ipython_dir_7():' | |||||
287 |
|
294 | |||
288 |
|
295 | |||
289 | @with_environment |
|
296 | @with_environment | |
290 |
def test_get_xdg_dir_ |
|
297 | def test_get_xdg_dir_0(): | |
291 |
"""test_get_xdg_dir_ |
|
298 | """test_get_xdg_dir_0, check xdg_dir""" | |
292 | reload(path) |
|
299 | reload(path) | |
293 | path._writable_dir = lambda path: True |
|
300 | path._writable_dir = lambda path: True | |
294 | path.get_home_dir = lambda : 'somewhere' |
|
301 | path.get_home_dir = lambda : 'somewhere' | |
295 | os.name = "posix" |
|
302 | os.name = "posix" | |
|
303 | sys.platform = "linux2" | |||
296 | env.pop('IPYTHON_DIR', None) |
|
304 | env.pop('IPYTHON_DIR', None) | |
297 | env.pop('IPYTHONDIR', None) |
|
305 | env.pop('IPYTHONDIR', None) | |
298 | env.pop('XDG_CONFIG_HOME', None) |
|
306 | env.pop('XDG_CONFIG_HOME', None) | |
@@ -306,6 +314,7 b' def test_get_xdg_dir_1():' | |||||
306 | reload(path) |
|
314 | reload(path) | |
307 | path.get_home_dir = lambda : HOME_TEST_DIR |
|
315 | path.get_home_dir = lambda : HOME_TEST_DIR | |
308 | os.name = "posix" |
|
316 | os.name = "posix" | |
|
317 | sys.platform = "linux2" | |||
309 | env.pop('IPYTHON_DIR', None) |
|
318 | env.pop('IPYTHON_DIR', None) | |
310 | env.pop('IPYTHONDIR', None) |
|
319 | env.pop('IPYTHONDIR', None) | |
311 | env.pop('XDG_CONFIG_HOME', None) |
|
320 | env.pop('XDG_CONFIG_HOME', None) | |
@@ -317,14 +326,32 b' def test_get_xdg_dir_2():' | |||||
317 | reload(path) |
|
326 | reload(path) | |
318 | path.get_home_dir = lambda : HOME_TEST_DIR |
|
327 | path.get_home_dir = lambda : HOME_TEST_DIR | |
319 | os.name = "posix" |
|
328 | os.name = "posix" | |
|
329 | sys.platform = "linux2" | |||
320 | env.pop('IPYTHON_DIR', None) |
|
330 | env.pop('IPYTHON_DIR', None) | |
321 | env.pop('IPYTHONDIR', None) |
|
331 | env.pop('IPYTHONDIR', None) | |
322 | env.pop('XDG_CONFIG_HOME', None) |
|
332 | env.pop('XDG_CONFIG_HOME', None) | |
323 | cfgdir=os.path.join(path.get_home_dir(), '.config') |
|
333 | cfgdir=os.path.join(path.get_home_dir(), '.config') | |
324 |
os. |
|
334 | if not os.path.exists(cfgdir): | |
|
335 | os.makedirs(cfgdir) | |||
325 |
|
336 | |||
326 | nt.assert_equal(path.get_xdg_dir(), cfgdir) |
|
337 | nt.assert_equal(path.get_xdg_dir(), cfgdir) | |
327 |
|
338 | |||
|
339 | @with_environment | |||
|
340 | def test_get_xdg_dir_3(): | |||
|
341 | """test_get_xdg_dir_3, check xdg_dir not used on OS X""" | |||
|
342 | reload(path) | |||
|
343 | path.get_home_dir = lambda : HOME_TEST_DIR | |||
|
344 | os.name = "posix" | |||
|
345 | sys.platform = "darwin" | |||
|
346 | env.pop('IPYTHON_DIR', None) | |||
|
347 | env.pop('IPYTHONDIR', None) | |||
|
348 | env.pop('XDG_CONFIG_HOME', None) | |||
|
349 | cfgdir=os.path.join(path.get_home_dir(), '.config') | |||
|
350 | if not os.path.exists(cfgdir): | |||
|
351 | os.makedirs(cfgdir) | |||
|
352 | ||||
|
353 | nt.assert_equal(path.get_xdg_dir(), None) | |||
|
354 | ||||
328 | def test_filefind(): |
|
355 | def test_filefind(): | |
329 | """Various tests for filefind""" |
|
356 | """Various tests for filefind""" | |
330 | f = tempfile.NamedTemporaryFile() |
|
357 | f = tempfile.NamedTemporaryFile() |
General Comments 0
You need to be logged in to leave comments.
Login now