From 0c5ef0d9c35b75bf94121a45d072124c14e6aa68 2008-09-30 17:10:35 From: Jorgen Stenarson Date: 2008-09-30 17:10:35 Subject: [PATCH] Changed get_ipython_dir to return unicode otherwise the pre_config_initialization in iplib fails with UnicodeError when exotic paths are used. ipmaker.make_IPython changed to use get_ipython_dir. some more tests added to genutils.py --- diff --git a/IPython/genutils.py b/IPython/genutils.py index 2deca30..d66703b 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -995,8 +995,8 @@ def get_ipython_dir(): ipdir_def = '_ipython' home_dir = get_home_dir() ipdir = os.path.abspath(os.environ.get('IPYTHONDIR', - os.path.join(home_dir,ipdir_def))) - return ipdir + os.path.join(home_dir, ipdir_def))) + return ipdir.decode(sys.getfilesystemencoding()) def get_security_dir(): """Get the IPython security directory. diff --git a/IPython/ipmaker.py b/IPython/ipmaker.py index 6065535..d19a071 100644 --- a/IPython/ipmaker.py +++ b/IPython/ipmaker.py @@ -131,20 +131,15 @@ object? -> Details about 'object'. ?object also works, ?? prints more. IP.usage = interactive_usage - # Platform-dependent suffix and directory names. We use _ipython instead - # of .ipython under win32 b/c there's software that breaks with .named - # directories on that platform. + # Platform-dependent suffix. if os.name == 'posix': rc_suffix = '' - ipdir_def = '.ipython' else: rc_suffix = '.ini' - ipdir_def = '_ipython' # default directory for configuration - ipythondir_def = os.path.abspath(os.environ.get('IPYTHONDIR', - os.path.join(IP.home_dir,ipdir_def))) - + ipythondir_def = get_ipython_dir() + sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran # we need the directory where IPython itself is installed diff --git a/IPython/tests/test_genutils.py b/IPython/tests/test_genutils.py index cae3d9f..8e0caab 100644 --- a/IPython/tests/test_genutils.py +++ b/IPython/tests/test_genutils.py @@ -147,11 +147,58 @@ def test_get_home_dir_9(): wreg.OpenKey, wreg.QueryValueEx,) = oldstuff -def test_get_ipython_dir(): +def test_get_ipython_dir_1(): """Testcase to see if we can call get_ipython_dir without Exceptions.""" ipdir = genutils.get_ipython_dir() -def test_get_security_dir(): - """Testcase to see if we can call get_security_dir without Exceptions.""" - sdir = genutils.get_security_dir() +def test_get_ipython_dir_2(): + """Testcase to see if we can call get_ipython_dir without Exceptions.""" + oldstuff = (env['IPYTHONDIR'],) + + env['IPYTHONDIR']="someplace/.ipython" + ipdir = genutils.get_ipython_dir() + assert ipdir == os.path.abspath("someplace/.ipython") + + (env['IPYTHONDIR'],)=oldstuff + +class test_get_ipython_dir_3: + @classmethod + def setup_class(cls): + cls.oldstuff = (env['IPYTHONDIR'], os.name, genutils.get_home_dir) + del env['IPYTHONDIR'] + genutils.get_home_dir=lambda : "someplace" + + @classmethod + def teardown_class(cls): + (env['IPYTHONDIR'], os.name, genutils.get_home_dir)=cls.oldstuff + + def test_get_ipython_dir_a(self): + """Testcase to see if we can call get_ipython_dir without Exceptions.""" + + os.name="posix" + ipdir = genutils.get_ipython_dir() + assert ipdir == os.path.abspath(os.path.join("someplace", ".ipython")) + + def test_get_ipython_dir_b(self): + """Testcase to see if we can call get_ipython_dir without Exceptions.""" + + os.name="nt" + ipdir = genutils.get_ipython_dir() + assert ipdir == os.path.abspath(os.path.join("someplace", "_ipython")) + +class test_get_security_dir: + @classmethod + def setup_class(cls): + cls.oldstuff = (env['IPYTHONDIR'], os.name, genutils.get_home_dir) + del env['IPYTHONDIR'] + genutils.get_home_dir=lambda : "someplace" + + @classmethod + def teardown_class(cls): + (env['IPYTHONDIR'], os.name, genutils.get_home_dir)=cls.oldstuff + + + def test_get_security_dir(): + """Testcase to see if we can call get_security_dir without Exceptions.""" + sdir = genutils.get_security_dir() \ No newline at end of file