##// END OF EJS Templates
Work to address the review comments on Fernando's branch....
Work to address the review comments on Fernando's branch. * Added comment about Magic(object) (r1224) * Moved InteractiveTB.set_mode from IPythonApp -> InteractiveShell (r1229) * Moved pylabtools.py to IPython/lib (r1229) * Cleaned up comments and copyrights in testing (r1233) * Added comment about ip.shell._ofind (r1237) * Removed "Bye." from quitter (r1240). * Refactored and removed :mod:`IPython.utils.genutils` and :mod:`IPython.utils.platutils`. These modules have been replaced by topical focused modules in :mod:`IPython.utils`. * Refactored tests in :mod:`IPython.utils.tests`. * Moved :func:`IPython.testing.tools.temp_pyfile` to :mod:`IPython.utils.io`. * Moved :func:`IPython.testing.tools.cmd2argv` to :func:`IPython.testing.tools.pycmd2argv` and documented the fact that this only works with Python based command line programs. * Created a new :func:`IPython.utils.path.get_ipython_module_path` to use in finding paths to IPython modules.

File last commit:

r2498:3eae1372
r2498:3eae1372
Show More
test_path.py
260 lines | 7.7 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
#-----------------------------------------------------------------------------
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 import os
import shutil
import sys
import tempfile
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
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 from IPython.testing.decorators import skip_if_not_win32
from IPython.utils.path import (
get_home_dir,
HomeDirError,
get_ipython_dir,
get_ipython_package_dir,
get_ipython_module_path,
filefind,
get_long_path_name
)
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
import new
Jorgen Stenarson
Some reformatting of code
r1796 sys.modules["_winreg"] = new.module("_winreg")
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)
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")
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:
- 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)
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:
- 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
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
def setup_environment():
Jorgen Stenarson
Add doc strings to all functions
r1805 """Setup testenvironment for some functions that are tested
in this module. In particular this functions stores attributes
and other things that we need to stub in some test functions.
This needs to be done on a function level and not module level because
each testfunction needs a pristine environment.
"""
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 global oldstuff, platformstuff
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 oldstuff = (env.copy(), os.name, get_home_dir, IPython.__file__)
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
Fernando Perez
More fixes for win32 test suite.
r2449
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
"""
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 (oldenv, os.name, get_home_dir, IPython.__file__,) = oldstuff
Fernando Perez
More fixes for win32 test suite.
r2449
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
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"))
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 home_dir = 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
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()
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 home_dir = 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
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():
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
Work to address the review comments on Fernando's branch....
r2498 home_dir = 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
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():
Jorgen Stenarson
Test for presence before deleting keys from os.environ. Mark two tests...
r1812 """Testcase $HOME is not set, os=='poix'.
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 This should fail with HomeDirError"""
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
Work to address the review comments on Fernando's branch....
r2498 nt.assert_raises(HomeDirError, get_home_dir)
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
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():
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 """Testcase $HOME is not set, os=='nt'
env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
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'
Jorgen Stenarson
Test for presence before deleting keys from os.environ. Mark two tests...
r1812 if 'HOME' in env: del env['HOME']
Jorgen Stenarson
Fixed errors in testcases specific to py2exe after Fernando's patch
r1855 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR)
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 home_dir = 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
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():
Jorgen Stenarson
Added tests test_get_home_dir_3-test_get_home_dir_9...
r1746 """Testcase $HOME is not set, os=='nt'
env['HOMEDRIVE'],env['HOMEPATH'] do not point to path.
env['USERPROFILE'] points to path
"""
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750
Jorgen Stenarson
Some reformatting of code
r1796 os.name = 'nt'
Jorgen Stenarson
Test for presence before deleting keys from os.environ. Mark two tests...
r1812 if 'HOME' in env: del env['HOME']
Fernando Perez
Fixes for Jorgen's branch in tests to genutils....
r1843 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST"
env["USERPROFILE"] = abspath(HOME_TEST_DIR)
Jorgen Stenarson
Fix for py2exe when using uncompressed lib/
r1745
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 home_dir = 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
Jorgen Stenarson
Changed tests to use decorator to setup, teardown environment
r1750 # Should we stub wreg fully so we can run the test on all platforms?
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():
Fernando Perez
Various fixes for test_genutils under win32, now all tests pass.
r2447 """Testcase $HOME is not set, os=='nt'
env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] and others 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
Work to address the review comments on Fernando's branch....
r2498 home_dir = 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."""
Fernando Perez
Various fixes for test_genutils under win32, now all tests pass.
r2447 env['IPYTHON_DIR'] = "someplace/.ipython"
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 ipdir = get_ipython_dir()
Fernando Perez
Progress towards getting the test suite in shape again....
r2392 nt.assert_equal(ipdir, "someplace/.ipython")
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
Work to address the review comments on Fernando's branch....
r2498 get_home_dir = lambda : "someplace"
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)
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 ipdir = 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
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()
print 'fname:',f.name
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 alt_dirs = get_ipython_dir()
t = filefind(f.name, alt_dirs)
Fernando Perez
Added small test for function that didn't have one. Little cleanups.
r1969 print 'found:',t
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357
def test_get_ipython_package_dir():
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 ipdir = 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
Work to address the review comments on Fernando's branch....
r2498 def test_get_ipython_module_path():
ipapp_path = get_ipython_module_path('IPython.core.ipapp')
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
Work to address the review comments on Fernando's branch....
r2498 @dec.skip_if_not_win32
def test_get_long_path_name_win32():
p = get_long_path_name('c:\\docume~1')
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
Work to address the review comments on Fernando's branch....
r2498
@dec.skip_win32
def test_get_long_path_name():
p = get_long_path_name('/usr/local')
nt.assert_equals(p,'/usr/local')
Fernando Perez
Added new Tee class, that works much like Unix's 'tee' command....
r2436