##// END OF EJS Templates
Silence errors from custom attribute completer functions....
Silence errors from custom attribute completer functions. Closes gh-907

File last commit:

r4902:765ba4e4
r5155:2e01c881
Show More
test_path.py
445 lines | 14.5 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
#-----------------------------------------------------------------------------
# Copyright (C) 2008 The IPython Development Team
#
# 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
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 import os
import shutil
import sys
import tempfile
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 from io import StringIO
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
bgranger
Fixing broken tests on win32....
r2513 from IPython.testing.decorators import skip_if_not_win32, skip_win32
Thomas Kluyver
Add AssertPrints context manager to check output from tests.
r4901 from IPython.testing.tools import make_tempfile, AssertPrints
MinRK
use tempdir if no usable ipython_dir is found...
r4475 from IPython.utils import path, io
Thomas Kluyver
Various Python 3 fixes in IPython.utils
r4764 from IPython.utils import py3compat
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:
import _winreg as wreg
except ImportError:
Jorgen Stenarson
Fake _winreg in tests for non windows platforms
r1793 #Fake _winreg module on none windows platforms
Thomas Kluyver
Various Python 3 fixes in IPython.utils
r4764 import types
wr_name = "winreg" if py3compat.PY3 else "_winreg"
sys.modules[wr_name] = types.ModuleType(wr_name)
Jorgen Stenarson
Fake _winreg in tests for non windows platforms
r1793 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")
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'))
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
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 oldstuff = (env.copy(), os.name, 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():
Jorgen Stenarson
Add doc strings to all functions
r1805 """Restore things that were remebered by the setup_environment function
"""
Robert Kern
BUG: Allow %magic argument filenames with spaces to be specified with quotes under win32.
r4688 (oldenv, os.name, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
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
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 for key in env.keys():
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
Jorgen Stenarson
Some white space fixing, and comments
r1804
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
"""
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()
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
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
"""
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
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).lower())
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
bgranger
Fixing broken tests on win32....
r2513 @skip_win32
Jorgen Stenarson
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_3():
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 """Testcase $HOME is set, then use its value as home directory."""
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 env["HOME"] = HOME_TEST_DIR
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 home_dir = path.get_home_dir()
Jorgen Stenarson
Remove bare asserts by switching to use nose.tools.assert_* functions to check test conditions.
r1802 nt.assert_equal(home_dir, 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
Min RK
fix various tests on Windows...
r4105 @skip_win32
Jorgen Stenarson
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_4():
Bernardo B. Marques
remove all trailling spaces
r4872 """Testcase $HOME is not set, os=='posix'.
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 This should fail with HomeDirError"""
Bernardo B. Marques
remove all trailling spaces
r4872
Jorgen Stenarson
Some reformatting of code
r1796 os.name = 'posix'
Jorgen Stenarson
Test for presence before deleting keys from os.environ. Mark two tests...
r1812 if 'HOME' in env: del env['HOME']
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 nt.assert_raises(path.HomeDirError, path.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
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_5():
bgranger
Fixing broken tests on win32....
r2513 """Using HOMEDRIVE + HOMEPATH, os=='nt'.
HOMESHARE is missing.
"""
Jorgen Stenarson
Test for presence before deleting keys from os.environ. Mark two tests...
r1812
Jorgen Stenarson
Some reformatting of code
r1796 os.name = 'nt'
bgranger
Fixing broken tests on win32....
r2513 env.pop('HOMESHARE', None)
Jorgen Stenarson
Fixed errors in testcases specific to py2exe after Fernando's patch
r1855 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR)
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
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
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
Removing simple test cases for get_home_dir and get_ipython_dir
r1800 def test_get_home_dir_6():
bgranger
Fixing broken tests on win32....
r2513 """Using USERPROFILE, os=='nt'.
HOMESHARE, HOMEDRIVE, HOMEPATH are missing.
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 """
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Jorgen Stenarson
Some reformatting of code
r1796 os.name = 'nt'
bgranger
Fixing broken tests on win32....
r2513 env.pop('HOMESHARE', None)
env.pop('HOMEDRIVE', None)
env.pop('HOMEPATH', None)
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 env["USERPROFILE"] = abspath(HOME_TEST_DIR)
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
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
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_7():
bgranger
Fixing broken tests on win32....
r2513 """Using HOMESHARE, os=='nt'."""
os.name = 'nt'
env["HOMESHARE"] = abspath(HOME_TEST_DIR)
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
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
Min RK
fix various tests on Windows...
r4105 env['IPYTHON_DIR'] = 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."""
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 path.get_home_dir = lambda : "someplace"
MinRK
use tempdir if no usable ipython_dir is found...
r4475 path.get_xdg_dir = lambda : None
path._writable_dir = lambda path: True
Jorgen Stenarson
Some reformatting of code
r1796 os.name = "posix"
Fernando Perez
More fixes for win32 test suite.
r2449 env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
MinRK
use XDG_CONFIG_HOME if available...
r3347 env.pop('XDG_CONFIG_HOME', None)
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 ipdir = path.get_ipython_dir()
Fernando Perez
Progress towards getting the test suite in shape again....
r2392 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():
"""test_get_ipython_dir_3, use XDG if defined, and .ipython doesn't exist."""
path.get_home_dir = lambda : "someplace"
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 os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, os.path.join(XDG_TEST_DIR, "ipython"))
@with_environment
def test_get_ipython_dir_4():
"""test_get_ipython_dir_4, use XDG if both exist."""
path.get_home_dir = lambda : HOME_TEST_DIR
os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
xdg_ipdir = os.path.join(XDG_TEST_DIR, "ipython")
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, xdg_ipdir)
@with_environment
def test_get_ipython_dir_5():
"""test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist."""
MinRK
Merge branch 'tilde-expand-fix'...
r3896 path.get_home_dir = lambda : HOME_TEST_DIR
MinRK
use XDG_CONFIG_HOME if available...
r3347 os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
os.rmdir(os.path.join(XDG_TEST_DIR, 'ipython'))
ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, IP_TEST_DIR)
@with_environment
def test_get_ipython_dir_6():
"""test_get_ipython_dir_6, use 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'))
path.get_home_dir = lambda : HOME_TEST_DIR
path.get_xdg_dir = lambda : xdg
MinRK
use XDG_CONFIG_HOME if available...
r3347 os.name = "posix"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
MinRK
use tempdir if no usable ipython_dir is found...
r4475 env.pop('XDG_CONFIG_HOME', None)
xdg_ipdir = os.path.join(xdg, "ipython")
MinRK
use XDG_CONFIG_HOME if available...
r3347 ipdir = path.get_ipython_dir()
nt.assert_equal(ipdir, xdg_ipdir)
@with_environment
MinRK
Merge branch 'tilde-expand-fix'...
r3896 def test_get_ipython_dir_7():
"""test_get_ipython_dir_7, test home directory expansion on IPYTHON_DIR"""
MinRK
use tempdir if no usable ipython_dir is found...
r4475 path._writable_dir = lambda path: True
Min RK
fix various tests on Windows...
r4105 home_dir = os.path.expanduser('~')
env['IPYTHON_DIR'] = 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'))
@with_environment
MinRK
use XDG_CONFIG_HOME if available...
r3347 def test_get_xdg_dir_1():
"""test_get_xdg_dir_1, check xdg_dir"""
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"
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"
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"
env.pop('IPYTHON_DIR', None)
env.pop('IPYTHONDIR', None)
env.pop('XDG_CONFIG_HOME', None)
cfgdir=os.path.join(path.get_home_dir(), '.config')
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
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
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():
Brian Granger
Moving and renaming in preparation of subclassing InteractiveShell....
r2760 ipapp_path = path.get_ipython_module_path('IPython.frontend.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():
Brian Granger
Fixed broken test in :mod:`IPython.utils.tests.test_path`.
r2505 p = path.get_long_path_name('c:\\docume~1')
Bernardo B. Marques
remove all trailling spaces
r4872 nt.assert_equals(p,u'c:\\Documents and Settings')
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')
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 nt.assert_equals(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):
nt.assert_equals(path.unquote_filename('foo.py', win32=win32), 'foo.py')
nt.assert_equals(path.unquote_filename('foo bar.py', win32=win32), 'foo bar.py')
nt.assert_equals(path.unquote_filename('"foo.py"', win32=True), 'foo.py')
nt.assert_equals(path.unquote_filename('"foo bar.py"', win32=True), 'foo bar.py')
nt.assert_equals(path.unquote_filename("'foo.py'", win32=True), 'foo.py')
nt.assert_equals(path.unquote_filename("'foo bar.py'", win32=True), 'foo bar.py')
nt.assert_equals(path.unquote_filename('"foo.py"', win32=False), '"foo.py"')
nt.assert_equals(path.unquote_filename('"foo bar.py"', win32=False), '"foo bar.py"')
nt.assert_equals(path.unquote_filename("'foo.py'", win32=False), "'foo.py'")
nt.assert_equals(path.unquote_filename("'foo bar.py'", win32=False), "'foo bar.py'")
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'):
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_equals(path.get_py_filename('foo.py', force_win32=win32), 'foo.py')
nt.assert_equals(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'):
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_equals(path.get_py_filename('foo', force_win32=win32), 'foo')
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):
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_equals(path.get_py_filename('foo with spaces', force_win32=win32), true_fn)
nt.assert_equals(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:
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_equals(path.get_py_filename('"foo with spaces.py"', force_win32=True), true_fn)
nt.assert_equals(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)