##// END OF EJS Templates
Merge pull request #5657 from minrk/default-localhost...
Merge pull request #5657 from minrk/default-localhost use 'localhost' as default for the notebook server

File last commit:

r13753:a33c3abc
r16350:b8d3118f merge
Show More
test_path.py
677 lines | 23.0 KiB | text/x-python | PythonLexer
Brian Granger
Added tests for the new get_ipython_dir and get_security_dir ...
r1617 # encoding: utf-8
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 """Tests for IPython.utils.path.py"""
Brian Granger
Added tests for the new get_ipython_dir and get_security_dir ...
r1617
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Brian Granger
Added tests for the new get_ipython_dir and get_security_dir ...
r1617 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 from __future__ import with_statement
Thomas Kluyver
Update tests for IPython.utils.path
r13407 import errno
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 import os
import shutil
import sys
import tempfile
Thomas Kluyver
Update tests for IPython.utils.path
r13407 import warnings
David Wolever
py3 doesn't have nested, py2.6 doesn't have multiple context managers
r11653 from contextlib import contextmanager
Jorgen Stenarson
added test for genutils.popkey
r1751
Jorgen Stenarson
Fixing pep-8 conformance issues
r1801 from os.path import join, abspath, split
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843
Jorgen Stenarson
Remove bare asserts by switching to use nose.tools.assert_* functions to check test conditions.
r1802 import nose.tools as nt
Brian Granger
Added tests for the new get_ipython_dir and get_security_dir ...
r1617
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 from nose import with_setup
Brian Granger
Added tests for the new get_ipython_dir and get_security_dir ...
r1617
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 import IPython
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 from IPython.testing import decorators as dec
Thomas Kluyver
Use onlyif_unicode_paths in utils tests
r12166 from IPython.testing.decorators import (skip_if_not_win32, skip_win32,
onlyif_unicode_paths,)
Thomas Kluyver
Add AssertPrints context manager to check output from tests.
r4901 from IPython.testing.tools import make_tempfile, AssertPrints
Thomas Kluyver
Remove unused imports in IPython.utils
r11127 from IPython.utils import path
Thomas Kluyver
Various Python 3 fixes in IPython.utils
r4764 from IPython.utils import py3compat
Takafumi Arakaki
Move globlist and its test under utils.path
r8014 from IPython.utils.tempdir import TemporaryDirectory
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843
# Platform-dependent imports
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 try:
Thomas Kluyver
Update imports for Python 3...
r13354 import winreg as wreg # Py 3
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 except ImportError:
Thomas Kluyver
Update imports for Python 3...
r13354 try:
import _winreg as wreg # Py 2
except ImportError:
#Fake _winreg module on none windows platforms
import types
wr_name = "winreg" if py3compat.PY3 else "_winreg"
sys.modules[wr_name] = types.ModuleType(wr_name)
try:
import winreg as wreg
except ImportError:
import _winreg as wreg
#Add entries that needs to be stubbed by the testing code
(wreg.OpenKey, wreg.QueryValueEx,) = (None, None)
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Various Python 3 fixes in IPython.utils
r4764 try:
reload
except NameError: # Python 3
from imp import reload
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 #-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
env = os.environ
TEST_FILE_PATH = split(abspath(__file__))[0]
TMP_TEST_DIR = tempfile.mkdtemp()
HOME_TEST_DIR = join(TMP_TEST_DIR, "home_test_dir")
MinRK
use XDG_CONFIG_HOME if available...
r3347 XDG_TEST_DIR = join(HOME_TEST_DIR, "xdg_test_dir")
Julian Taylor
add path.get_ipython_cache_dir to retrieve a cache directory
r10230 XDG_CACHE_DIR = join(HOME_TEST_DIR, "xdg_cache_dir")
Fernando Perez
More fixes for win32 test suite.
r2449 IP_TEST_DIR = join(HOME_TEST_DIR,'.ipython')
Jorgen Stenarson
Some white space fixing, and comments
r1804 #
# Setup/teardown functions/decorators
Jorgen Stenarson
Moved skip decorator to testing and created similar ones for OSX and linux, create delete testdirs in module setup/teardown
r1803 #
def setup():
Jorgen Stenarson
Add doc strings to all functions
r1805 """Setup testenvironment for the module:
Bernardo B. Marques
remove all trailling spaces
r4872
Jorgen Stenarson
Add doc strings to all functions
r1805 - Adds dummy home dir tree
"""
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 # Do not mask exceptions here. In particular, catching WindowsError is a
# problem because that exception is only defined on Windows...
os.makedirs(IP_TEST_DIR)
MinRK
use XDG_CONFIG_HOME if available...
r3347 os.makedirs(os.path.join(XDG_TEST_DIR, 'ipython'))
Julian Taylor
add path.get_ipython_cache_dir to retrieve a cache directory
r10230 os.makedirs(os.path.join(XDG_CACHE_DIR, 'ipython'))
Jorgen Stenarson
Moved skip decorator to testing and created similar ones for OSX and linux, create delete testdirs in module setup/teardown
r1803
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Jorgen Stenarson
Moved skip decorator to testing and created similar ones for OSX and linux, create delete testdirs in module setup/teardown
r1803 def teardown():
Jorgen Stenarson
Add doc strings to all functions
r1805 """Teardown testenvironment for the module:
Bernardo B. Marques
remove all trailling spaces
r4872
Jorgen Stenarson
Add doc strings to all functions
r1805 - Remove dummy home dir tree
"""
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 # Note: we remove the parent test dir, which is the root of all test
# subdirs we may have created. Use shutil instead of os.removedirs, so
# that non-empty directories are all recursively removed.
shutil.rmtree(TMP_TEST_DIR)
Jorgen Stenarson
Moved skip decorator to testing and created similar ones for OSX and linux, create delete testdirs in module setup/teardown
r1803
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 def setup_environment():
Bernardo B. Marques
remove all trailling spaces
r4872 """Setup testenvironment for some functions that are tested
Jorgen Stenarson
Add doc strings to all functions
r1805 in this module. In particular this functions stores attributes
and other things that we need to stub in some test functions.
Bernardo B. Marques
remove all trailling spaces
r4872 This needs to be done on a function level and not module level because
Jorgen Stenarson
Add doc strings to all functions
r1805 each testfunction needs a pristine environment.
"""
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 global oldstuff, platformstuff
MinRK
don't use XDG path on OS X...
r7086 oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd())
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Jorgen Stenarson
Some reformatting of code
r1796 if os.name == 'nt':
platformstuff = (wreg.OpenKey, wreg.QueryValueEx,)
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 def teardown_environment():
MinRK
docstring typo
r11500 """Restore things that were remembered by the setup_environment function
Jorgen Stenarson
Add doc strings to all functions
r1805 """
MinRK
don't use XDG path on OS X...
r7086 (oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 os.chdir(old_wd)
MinRK
use tempdir if no usable ipython_dir is found...
r4475 reload(path)
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Fix tests in utils
r13373 for key in list(env):
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
Jorgen Stenarson
Some reformatting of code
r1796 if os.name == 'nt':
(wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Jorgen Stenarson
Add doc strings to all functions
r1805 # Build decorator that uses the setup_environment/setup_environment
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 with_environment = with_setup(setup_environment, teardown_environment)
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Thomas Kluyver
Update tests for IPython.utils.path
r13407 @contextmanager
def patch_get_home_dir(dirpath):
orig_get_home_dir = path.get_home_dir
path.get_home_dir = lambda : dirpath
try:
yield
finally:
path.get_home_dir = orig_get_home_dir
Jorgen Stenarson
skipping windows specific tests of get_home_dir on other platforms
r1820 @skip_if_not_win32
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 @with_environment
Jorgen Stenarson
Fix for py2exe when using uncompressed lib/
r1745 def test_get_home_dir_1():
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 """Testcase for py2exe logic, un-compressed lib
"""
MinRK
update tests for frozen dists
r11502 unfrozen = path.get_home_dir()
Jorgen Stenarson
Some reformatting of code
r1796 sys.frozen = True
Bernardo B. Marques
remove all trailling spaces
r4872
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 #fake filename for IPython.__init__
Jorgen Stenarson
Fixed errors in testcases specific to py2exe after Fernando's patch
r1855 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
Bernardo B. Marques
remove all trailling spaces
r4872
bgranger
Fixing broken tests on win32....
r2513 home_dir = path.get_home_dir()
MinRK
update tests for frozen dists
r11502 nt.assert_equal(home_dir, unfrozen)
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Jorgen Stenarson
Test for presence before deleting keys from os.environ. Mark two tests...
r1812 @skip_if_not_win32
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 @with_environment
Jorgen Stenarson
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_2():
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 """Testcase for py2exe logic, compressed lib
"""
MinRK
update tests for frozen dists
r11502 unfrozen = path.get_home_dir()
Jorgen Stenarson
Fixing pep-8 conformance issues
r1801 sys.frozen = True
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 #fake filename for IPython.__init__
Jorgen Stenarson
Fixed errors in testcases specific to py2exe after Fernando's patch
r1855 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
allow IPython to run without writable home dir...
r5384 home_dir = path.get_home_dir(True)
MinRK
update tests for frozen dists
r11502 nt.assert_equal(home_dir, unfrozen)
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 @with_environment
Jorgen Stenarson
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_3():
MinRK
defer to stdlib for path.get_home_dir()...
r5383 """get_home_dir() uses $HOME if set"""
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 env["HOME"] = HOME_TEST_DIR
MinRK
allow IPython to run without writable home dir...
r5384 home_dir = path.get_home_dir(True)
MinRK
get_home_dir expands symlinks, adjust test accordingly
r6123 # get_home_dir expands symlinks
nt.assert_equal(home_dir, os.path.realpath(env["HOME"]))
Jorgen Stenarson
Fix for py2exe when using uncompressed lib/
r1745
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 @with_environment
Jorgen Stenarson
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_4():
MinRK
defer to stdlib for path.get_home_dir()...
r5383 """get_home_dir() still works if $HOME is not set"""
Bernardo B. Marques
remove all trailling spaces
r4872
Jorgen Stenarson
Test for presence before deleting keys from os.environ. Mark two tests...
r1812 if 'HOME' in env: del env['HOME']
MinRK
don't check writability in test for get_home_dir when HOME is undefined...
r7669 # this should still succeed, but we don't care what the answer is
home = path.get_home_dir(False)
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 @with_environment
Jorgen Stenarson
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_5():
MinRK
defer to stdlib for path.get_home_dir()...
r5383 """raise HomeDirError if $HOME is specified, but not a writable dir"""
env['HOME'] = abspath(HOME_TEST_DIR+'garbage')
MinRK
restore My Documents fallback for get_home_dir on Windows
r5385 # set os.name = posix, to prevent My Documents fallback on Windows
os.name = 'posix'
MinRK
allow IPython to run without writable home dir...
r5384 nt.assert_raises(path.HomeDirError, path.get_home_dir, True)
Fernando Perez
Make last-ditch attempt to find $HOME when environment is broken....
r3373
Bernardo B. Marques
remove all trailling spaces
r4872
bgranger
Fixing broken tests on win32....
r2513 # Should we stub wreg fully so we can run the test on all platforms?
@skip_if_not_win32
@with_environment
def test_get_home_dir_8():
"""Using registry hack for 'My Documents', os=='nt'
Bernardo B. Marques
remove all trailling spaces
r4872
bgranger
Fixing broken tests on win32....
r2513 HOMESHARE, HOMEDRIVE, HOMEPATH, USERPROFILE and others are missing.
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 """
Jorgen Stenarson
Some reformatting of code
r1796 os.name = 'nt'
Fernando Perez
Various fixes for test_genutils under win32, now all tests pass.
r2447 # Remove from stub environment all keys that may be set
for key in ['HOME', 'HOMESHARE', 'HOMEDRIVE', 'HOMEPATH', 'USERPROFILE']:
env.pop(key, None)
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
#Stub windows registry functions
Jorgen Stenarson
Some reformatting of code
r1796 def OpenKey(x, y):
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 class key:
def Close(self):
pass
return key()
Jorgen Stenarson
Some reformatting of code
r1796 def QueryValueEx(x, y):
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 return [abspath(HOME_TEST_DIR)]
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
Jorgen Stenarson
Some reformatting of code
r1796 wreg.OpenKey = OpenKey
wreg.QueryValueEx = QueryValueEx
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 home_dir = path.get_home_dir()
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
Jorgen Stenarson
Fix for py2exe when using uncompressed lib/
r1745
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 @with_environment
Jorgen Stenarson
Changed get_ipython_dir to return unicode otherwise the ...
r1749 def test_get_ipython_dir_1():
Jorgen Stenarson
Add doc strings to all functions
r1805 """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions."""
Min RK
fix various tests on Windows...
r4105 env_ipdir = os.path.join("someplace", ".ipython")
MinRK
use tempdir if no usable ipython_dir is found...
r4475 path._writable_dir = lambda path: True
Bradley M. Froehle
Update tests to reflect preferred IPYTHONDIR variable.
r6700 env['IPYTHONDIR'] = env_ipdir
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 ipdir = path.get_ipython_dir()
Min RK
fix various tests on Windows...
r4105 nt.assert_equal(ipdir, env_ipdir)
Jorgen Stenarson
Changed get_ipython_dir to return unicode otherwise the ...
r1749
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436 @with_environment
Jorgen Stenarson
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_ipython_dir_2():
Jorgen Stenarson
Add doc strings to all functions
r1805 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
Thomas Kluyver
Update tests for IPython.utils.path
r13407 with patch_get_home_dir('someplace'):
path.get_xdg_dir = lambda : None
path._writable_dir = lambda path: True
os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, os.path.join("someplace", ".ipython"))
Jorgen Stenarson
Changed get_ipython_dir to return unicode otherwise the ...
r1749
MinRK
use XDG_CONFIG_HOME if available...
r3347 @with_environment
def test_get_ipython_dir_3():
Thomas Kluyver
Update tests for IPython.utils.path
r13407 """test_get_ipython_dir_3, move XDG if defined, and .ipython doesn't exist."""
tmphome = TemporaryDirectory()
try:
with patch_get_home_dir(tmphome.name):
os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
with warnings.catch_warnings(record=True) as w:
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, os.path.join(tmphome.name, ".ipython"))
if sys.platform != 'darwin':
nt.assert_equal(len(w), 1)
nt.assert_in('Moving', str(w[0]))
finally:
tmphome.cleanup()
MinRK
use XDG_CONFIG_HOME if available...
r3347
@with_environment
def test_get_ipython_dir_4():
Thomas Kluyver
Update tests for IPython.utils.path
r13407 """test_get_ipython_dir_4, warn if XDG and home both exist."""
with patch_get_home_dir(HOME_TEST_DIR):
os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
try:
os.mkdir(os.path.join(XDG_TEST_DIR, 'ipython'))
except OSError as e:
if e.errno != errno.EEXIST:
raise
with warnings.catch_warnings(record=True) as w:
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, os.path.join(HOME_TEST_DIR, ".ipython"))
if sys.platform != 'darwin':
nt.assert_equal(len(w), 1)
nt.assert_in('Ignoring', str(w[0]))
MinRK
use XDG_CONFIG_HOME if available...
r3347
@with_environment
def test_get_ipython_dir_5():
"""test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist."""
Thomas Kluyver
Update tests for IPython.utils.path
r13407 with patch_get_home_dir(HOME_TEST_DIR):
os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
try:
os.rmdir(os.path.join(XDG_TEST_DIR, 'ipython'))
except OSError as e:
if e.errno != errno.ENOENT:
raise
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, IP_TEST_DIR)
MinRK
use XDG_CONFIG_HOME if available...
r3347
@with_environment
def test_get_ipython_dir_6():
Thomas Kluyver
Update tests for IPython.utils.path
r13407 """test_get_ipython_dir_6, use home over XDG if defined and neither exist."""
MinRK
use tempdir if no usable ipython_dir is found...
r4475 xdg = os.path.join(HOME_TEST_DIR, 'somexdg')
os.mkdir(xdg)
shutil.rmtree(os.path.join(HOME_TEST_DIR, '.ipython'))
Thomas Kluyver
Update tests for IPython.utils.path
r13407 with patch_get_home_dir(HOME_TEST_DIR):
orig_get_xdg_dir = path.get_xdg_dir
path.get_xdg_dir = lambda : xdg
try:
os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
with warnings.catch_warnings(record=True) as w:
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, os.path.join(HOME_TEST_DIR, '.ipython'))
nt.assert_equal(len(w), 0)
finally:
path.get_xdg_dir = orig_get_xdg_dir
MinRK
use XDG_CONFIG_HOME if available...
r3347
@with_environment
MinRK
Merge branch 'tilde-expand-fix'...
r3896 def test_get_ipython_dir_7():
Bradley M. Froehle
Update tests to reflect preferred IPYTHONDIR variable.
r6700 """test_get_ipython_dir_7, test home directory expansion on IPYTHONDIR"""
MinRK
use tempdir if no usable ipython_dir is found...
r4475 path._writable_dir = lambda path: True
Jonathan March
Fix home path expansion test in Windows....
r7673 home_dir = os.path.normpath(os.path.expanduser('~'))
Bradley M. Froehle
Update tests to reflect preferred IPYTHONDIR variable.
r6700 env['IPYTHONDIR'] = os.path.join('~', 'somewhere')
MinRK
Merge branch 'tilde-expand-fix'...
r3896 ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, os.path.join(home_dir, 'somewhere'))
Thomas Kluyver
Skip, on Windows, test for root home directory
r10868 @skip_win32
Frank Murphy
Fix IPython.utils.path when HOME=/.
r10662 @with_environment
def test_get_ipython_dir_8():
"""test_get_ipython_dir_8, test / home directory"""
old = path._writable_dir, path.get_xdg_dir
try:
path._writable_dir = lambda path: bool(path)
path.get_xdg_dir = lambda: None
Frank Murphy
Pop out any existing IPYTHONDIR or IPYTHON_DIR variables.
r10664 env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
Frank Murphy
Fix IPython.utils.path when HOME=/.
r10662 env['HOME'] = '/'
nt.assert_equal(path.get_ipython_dir(), '/.ipython')
finally:
path._writable_dir, path.get_xdg_dir = old
MinRK
Merge branch 'tilde-expand-fix'...
r3896
@with_environment
MinRK
don't use XDG path on OS X...
r7086 def test_get_xdg_dir_0():
"""test_get_xdg_dir_0, check xdg_dir"""
MinRK
use XDG_CONFIG_HOME if available...
r3347 reload(path)
MinRK
use tempdir if no usable ipython_dir is found...
r4475 path._writable_dir = lambda path: True
MinRK
use XDG_CONFIG_HOME if available...
r3347 path.get_home_dir = lambda : 'somewhere'
os.name = "posix"
MinRK
don't use XDG path on OS X...
r7086 sys.platform = "linux2"
MinRK
use XDG_CONFIG_HOME if available...
r3347 env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
use XDG_CONFIG_HOME if available...
r3347 nt.assert_equal(path.get_xdg_dir(), os.path.join('somewhere', '.config'))
@with_environment
def test_get_xdg_dir_1():
"""test_get_xdg_dir_1, check nonexistant xdg_dir"""
reload(path)
path.get_home_dir = lambda : HOME_TEST_DIR
os.name = "posix"
MinRK
don't use XDG path on OS X...
r7086 sys.platform = "linux2"
MinRK
use XDG_CONFIG_HOME if available...
r3347 env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
nt.assert_equal(path.get_xdg_dir(), None)
@with_environment
def test_get_xdg_dir_2():
"""test_get_xdg_dir_2, check xdg_dir default to ~/.config"""
reload(path)
path.get_home_dir = lambda : HOME_TEST_DIR
os.name = "posix"
MinRK
don't use XDG path on OS X...
r7086 sys.platform = "linux2"
MinRK
use XDG_CONFIG_HOME if available...
r3347 env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
cfgdir=os.path.join(path.get_home_dir(), '.config')
MinRK
don't use XDG path on OS X...
r7086 if not os.path.exists(cfgdir):
os.makedirs(cfgdir)
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
use XDG_CONFIG_HOME if available...
r3347 nt.assert_equal(path.get_xdg_dir(), cfgdir)
Fernando Perez
Added small test for function that didn't have one. Little cleanups.
r1969
MinRK
don't use XDG path on OS X...
r7086 @with_environment
def test_get_xdg_dir_3():
"""test_get_xdg_dir_3, check xdg_dir not used on OS X"""
reload(path)
path.get_home_dir = lambda : HOME_TEST_DIR
os.name = "posix"
sys.platform = "darwin"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
cfgdir=os.path.join(path.get_home_dir(), '.config')
if not os.path.exists(cfgdir):
os.makedirs(cfgdir)
nt.assert_equal(path.get_xdg_dir(), None)
Fernando Perez
Added small test for function that didn't have one. Little cleanups.
r1969 def test_filefind():
"""Various tests for filefind"""
f = tempfile.NamedTemporaryFile()
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 # print 'fname:',f.name
alt_dirs = path.get_ipython_dir()
t = path.filefind(f.name, alt_dirs)
# print 'found:',t
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357
Julian Taylor
add path.get_ipython_cache_dir to retrieve a cache directory
r10230 @with_environment
def test_get_ipython_cache_dir():
os.environ["HOME"] = HOME_TEST_DIR
if os.name == 'posix' and sys.platform != 'darwin':
# test default
os.makedirs(os.path.join(HOME_TEST_DIR, ".cache"))
os.environ.pop("XDG_CACHE_HOME", None)
ipdir = path.get_ipython_cache_dir()
nt.assert_equal(os.path.join(HOME_TEST_DIR, ".cache", "ipython"),
ipdir)
nt.assert_true(os.path.isdir(ipdir))
# test env override
os.environ["XDG_CACHE_HOME"] = XDG_CACHE_DIR
ipdir = path.get_ipython_cache_dir()
nt.assert_true(os.path.isdir(ipdir))
nt.assert_equal(ipdir, os.path.join(XDG_CACHE_DIR, "ipython"))
else:
nt.assert_equal(path.get_ipython_cache_dir(),
path.get_ipython_dir())
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357
def test_get_ipython_package_dir():
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 ipdir = path.get_ipython_package_dir()
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357 nt.assert_true(os.path.isdir(ipdir))
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 def test_get_ipython_module_path():
Fernando Perez
Fix all remaining imports that used `IPython.frontend`.
r11024 ipapp_path = path.get_ipython_module_path('IPython.terminal.ipapp')
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 nt.assert_true(os.path.isfile(ipapp_path))
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 @dec.skip_if_not_win32
def test_get_long_path_name_win32():
Jonathan Frederic
FIX test_get_long_path_name_win32 for Win7...
r12083 with TemporaryDirectory() as tmpdir:
Jonathan Frederic
Small fixes to make test work.
r12085
watercrossing
Modifies test_get_long_path_name_winr32() to fix #4629
r13753 # Make a long path. Expands the path of tmpdir prematurely as it may already have a long
# path component, so ensure we include the long form of it
watercrossing
Modifies test_get_long_path_name_winr32() to fix #4629 on ipython/ipython.
r13741 long_path = os.path.join(path.get_long_path_name(tmpdir), u'this is my long path name')
Jonathan Frederic
Small fixes to make test work.
r12085 os.makedirs(long_path)
Jonathan Frederic
FIX test_get_long_path_name_win32 for Win7...
r12083
Jonathan Frederic
Small fixes to make test work.
r12085 # Test to see if the short path evaluates correctly.
short_path = os.path.join(tmpdir, u'THISIS~1')
evaluated_path = path.get_long_path_name(short_path)
nt.assert_equal(evaluated_path.lower(), long_path.lower())
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 @dec.skip_win32
def test_get_long_path_name():
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 p = path.get_long_path_name('/usr/local')
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(p,'/usr/local')
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436
MinRK
Skip writable_dir test on Windows...
r4483 @dec.skip_win32 # can't create not-user-writable dir on win
MinRK
use tempdir if no usable ipython_dir is found...
r4475 @with_environment
def test_not_writable_ipdir():
tmpdir = tempfile.mkdtemp()
os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
env['HOME'] = tmpdir
ipdir = os.path.join(tmpdir, '.ipython')
os.mkdir(ipdir)
os.chmod(ipdir, 600)
Thomas Kluyver
Update IPython.utils.path to use stdlib warnings module.
r4902 with AssertPrints('is not a writable location', channel='stderr'):
Thomas Kluyver
Add AssertPrints context manager to check output from tests.
r4901 ipdir = path.get_ipython_dir()
MinRK
use tempdir if no usable ipython_dir is found...
r4475 env.pop('IPYTHON_DIR', None)
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688
Robert Kern
BUG: break out the filename-unquoting from get_py_filename to be used in other contexts. Fix %save, in this respect.
r4696 def test_unquote_filename():
for win32 in (True, False):
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(path.unquote_filename('foo.py', win32=win32), 'foo.py')
nt.assert_equal(path.unquote_filename('foo bar.py', win32=win32), 'foo bar.py')
nt.assert_equal(path.unquote_filename('"foo.py"', win32=True), 'foo.py')
nt.assert_equal(path.unquote_filename('"foo bar.py"', win32=True), 'foo bar.py')
nt.assert_equal(path.unquote_filename("'foo.py'", win32=True), 'foo.py')
nt.assert_equal(path.unquote_filename("'foo bar.py'", win32=True), 'foo bar.py')
nt.assert_equal(path.unquote_filename('"foo.py"', win32=False), '"foo.py"')
nt.assert_equal(path.unquote_filename('"foo bar.py"', win32=False), '"foo bar.py"')
nt.assert_equal(path.unquote_filename("'foo.py'", win32=False), "'foo.py'")
nt.assert_equal(path.unquote_filename("'foo bar.py'", win32=False), "'foo bar.py'")
Robert Kern
BUG: break out the filename-unquoting from get_py_filename to be used in other contexts. Fix %save, in this respect.
r4696
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 @with_environment
def test_get_py_filename():
os.chdir(TMP_TEST_DIR)
for win32 in (True, False):
with make_tempfile('foo.py'):
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(path.get_py_filename('foo.py', force_win32=win32), 'foo.py')
nt.assert_equal(path.get_py_filename('foo', force_win32=win32), 'foo.py')
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 with make_tempfile('foo'):
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(path.get_py_filename('foo', force_win32=win32), 'foo')
Robert Kern
BUG: break out the filename-unquoting from get_py_filename to be used in other contexts. Fix %save, in this respect.
r4696 nt.assert_raises(IOError, path.get_py_filename, 'foo.py', force_win32=win32)
nt.assert_raises(IOError, path.get_py_filename, 'foo', force_win32=win32)
nt.assert_raises(IOError, path.get_py_filename, 'foo.py', force_win32=win32)
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 true_fn = 'foo with spaces.py'
with make_tempfile(true_fn):
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(path.get_py_filename('foo with spaces', force_win32=win32), true_fn)
nt.assert_equal(path.get_py_filename('foo with spaces.py', force_win32=win32), true_fn)
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 if win32:
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(path.get_py_filename('"foo with spaces.py"', force_win32=True), true_fn)
nt.assert_equal(path.get_py_filename("'foo with spaces.py'", force_win32=True), true_fn)
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 else:
Robert Kern
BUG: break out the filename-unquoting from get_py_filename to be used in other contexts. Fix %save, in this respect.
r4696 nt.assert_raises(IOError, path.get_py_filename, '"foo with spaces.py"', force_win32=False)
nt.assert_raises(IOError, path.get_py_filename, "'foo with spaces.py'", force_win32=False)
Thomas Kluyver
Use onlyif_unicode_paths in utils tests
r12166
@onlyif_unicode_paths
Fix for #875 Unicode Encoding Error
r6152 def test_unicode_in_filename():
Thomas Kluyver
Add description of test.
r6164 """When a file doesn't exist, the exception raised should be safe to call
str() on - i.e. in Python 2 it must only have ASCII characters.
https://github.com/ipython/ipython/issues/875
"""
Fix for #875 Unicode Encoding Error
r6152 try:
# these calls should not throw unicode encode exceptions
path.get_py_filename(u'fooéè.py', force_win32=False)
except IOError as ex:
str(ex)
Takafumi Arakaki
Move globlist and its test under utils.path
r8014
Takafumi Arakaki
Windows aware tests for shellglob
r8638 class TestShellGlob(object):
Takafumi Arakaki
Move globlist and its test under utils.path
r8014
Takafumi Arakaki
Windows aware tests for shellglob
r8638 @classmethod
def setUpClass(cls):
Thomas Kluyver
Fix tests in utils
r13373 cls.filenames_start_with_a = ['a0', 'a1', 'a2']
cls.filenames_end_with_b = ['0b', '1b', '2b']
Takafumi Arakaki
Windows aware tests for shellglob
r8638 cls.filenames = cls.filenames_start_with_a + cls.filenames_end_with_b
cls.tempdir = TemporaryDirectory()
td = cls.tempdir.name
Takafumi Arakaki
Move globlist and its test under utils.path
r8014
Takafumi Arakaki
Windows aware tests for shellglob
r8638 with cls.in_tempdir():
Takafumi Arakaki
Move globlist and its test under utils.path
r8014 # Create empty files
Takafumi Arakaki
Windows aware tests for shellglob
r8638 for fname in cls.filenames:
Takafumi Arakaki
Move globlist and its test under utils.path
r8014 open(os.path.join(td, fname), 'w').close()
Takafumi Arakaki
Windows aware tests for shellglob
r8638 @classmethod
def tearDownClass(cls):
cls.tempdir.cleanup()
@classmethod
@contextmanager
def in_tempdir(cls):
Thomas Kluyver
Python 3 compatibility for os.getcwdu()
r13447 save = py3compat.getcwd()
Takafumi Arakaki
Wrap yield of @contextmanager with try-finally block
r8640 try:
os.chdir(cls.tempdir.name)
yield
finally:
os.chdir(save)
Takafumi Arakaki
Windows aware tests for shellglob
r8638
def check_match(self, patterns, matches):
with self.in_tempdir():
# glob returns unordered list. that's why sorted is required.
nt.assert_equals(sorted(path.shellglob(patterns)),
sorted(matches))
def common_cases(self):
return [
(['*'], self.filenames),
(['a*'], self.filenames_start_with_a),
(['*c'], ['*c']),
(['*', 'a*', '*b', '*c'], self.filenames
+ self.filenames_start_with_a
+ self.filenames_end_with_b
+ ['*c']),
(['a[012]'], self.filenames_start_with_a),
]
@skip_win32
def test_match_posix(self):
for (patterns, matches) in self.common_cases() + [
([r'\*'], ['*']),
([r'a\*', 'a*'], ['a*'] + self.filenames_start_with_a),
([r'a\[012]'], ['a[012]']),
]:
yield (self.check_match, patterns, matches)
@skip_if_not_win32
def test_match_windows(self):
for (patterns, matches) in self.common_cases() + [
# In windows, backslash is interpreted as path
# separator. Therefore, you can't escape glob
# using it.
([r'a\*', 'a*'], [r'a\*'] + self.filenames_start_with_a),
([r'a\[012]'], [r'a\[012]']),
]:
yield (self.check_match, patterns, matches)
Takafumi Arakaki
Unescape failed glob patterns in shellglob
r8119
def test_unescape_glob():
nt.assert_equals(path.unescape_glob(r'\*\[\!\]\?'), '*[!]?')
Takafumi Arakaki
Fix unescape_glob: support escaping "\"
r8122 nt.assert_equals(path.unescape_glob(r'\\*'), r'\*')
nt.assert_equals(path.unescape_glob(r'\\\*'), r'\*')
nt.assert_equals(path.unescape_glob(r'\\a'), r'\a')
nt.assert_equals(path.unescape_glob(r'\a'), r'\a')
David Wolever
Add link_or_copy to IPython.utils.path
r11647
class TestLinkOrCopy(object):
def setUp(self):
self.tempdir = TemporaryDirectory()
self.src = self.dst("src")
with open(self.src, "w") as f:
f.write("Hello, world!")
def tearDown(self):
self.tempdir.cleanup()
def dst(self, *args):
return os.path.join(self.tempdir.name, *args)
def assert_inode_not_equal(self, a, b):
nt.assert_not_equals(os.stat(a).st_ino, os.stat(b).st_ino,
"%r and %r do reference the same indoes" %(a, b))
def assert_inode_equal(self, a, b):
nt.assert_equals(os.stat(a).st_ino, os.stat(b).st_ino,
"%r and %r do not reference the same indoes" %(a, b))
David Wolever
Fix a couple typos
r11650 def assert_content_equal(self, a, b):
David Wolever
py3 doesn't have nested, py2.6 doesn't have multiple context managers
r11653 with open(a) as a_f:
with open(b) as b_f:
nt.assert_equals(a_f.read(), b_f.read())
David Wolever
Add link_or_copy to IPython.utils.path
r11647
@skip_win32
def test_link_successful(self):
dst = self.dst("target")
path.link_or_copy(self.src, dst)
self.assert_inode_equal(self.src, dst)
@skip_win32
def test_link_into_dir(self):
dst = self.dst("some_dir")
os.mkdir(dst)
path.link_or_copy(self.src, dst)
expected_dst = self.dst("some_dir", os.path.basename(self.src))
self.assert_inode_equal(self.src, expected_dst)
@skip_win32
def test_target_exists(self):
dst = self.dst("target")
open(dst, "w").close()
path.link_or_copy(self.src, dst)
self.assert_inode_equal(self.src, dst)
@skip_win32
def test_no_link(self):
real_link = os.link
try:
del os.link
dst = self.dst("target")
path.link_or_copy(self.src, dst)
David Wolever
Fix a couple typos
r11650 self.assert_content_equal(self.src, dst)
David Wolever
Add link_or_copy to IPython.utils.path
r11647 self.assert_inode_not_equal(self.src, dst)
finally:
os.link = real_link
@skip_if_not_win32
def test_windows(self):
dst = self.dst("target")
path.link_or_copy(self.src, dst)
David Wolever
Fix a couple typos
r11650 self.assert_content_equal(self.src, dst)