From 528125c0fe8fabc703d0a9970b834cd0c32a895a 2011-03-24 23:42:04 From: Thomas Kluyver Date: 2011-03-24 23:42:04 Subject: [PATCH] Tweak code with suggestions from yesterday. --- diff --git a/IPython/config/loader.py b/IPython/config/loader.py index cd56705..e8132ef 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -285,7 +285,8 @@ class PyFileConfigLoader(FileConfigLoader): return self.config namespace = dict(load_subconfig=load_subconfig, get_config=get_config) - conf_filename = self.full_filename.encode(sys.getfilesystemencoding()) + fs_encoding = sys.getfilesystemencoding() or 'ascii' + conf_filename = self.full_filename.encode(fs_encoding) execfile(conf_filename, namespace) def _convert_to_config(self): diff --git a/IPython/core/application.py b/IPython/core/application.py index 46c00d4..6acf566 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -362,6 +362,10 @@ class Application(object): This tries to load the config file from disk. If successful, the ``CONFIG_FILE`` config variable is set to the resolved config file location. If not successful, an empty config is used. + + By default, errors in loading config are handled, and a warning + printed on screen. For testing, the suppress_errors option is set + to False, so errors will make tests fail. """ self.log.debug("Attempting to load config file: %s" % self.config_file_name) diff --git a/IPython/core/tests/test_compilerop.py b/IPython/core/tests/test_compilerop.py index 1e214d2..2fac2fc 100644 --- a/IPython/core/tests/test_compilerop.py +++ b/IPython/core/tests/test_compilerop.py @@ -16,6 +16,7 @@ from __future__ import print_function # Stdlib imports import linecache +import sys # Third-party imports import nose.tools as nt @@ -47,10 +48,12 @@ def test_compiler(): cp('x=1', 'single') nt.assert_true(len(linecache.cache) > ncache) -def test_compiler_unicode(): - import sys +def setUp(): + # Check we're in a proper Python 2 environment (some imports, such + # as GTK, can change the default encoding, which can hide bugs.) nt.assert_equal(sys.getdefaultencoding(), "ascii") - + +def test_compiler_unicode(): cp = compilerop.CachingCompiler() ncache = len(linecache.cache) cp(u"t = 'žćčšđ'", "single") diff --git a/IPython/core/tests/test_history.py b/IPython/core/tests/test_history.py index db82828..a2d3353 100644 --- a/IPython/core/tests/test_history.py +++ b/IPython/core/tests/test_history.py @@ -17,8 +17,10 @@ import nose.tools as nt from IPython.utils.tempdir import TemporaryDirectory from IPython.core.history import HistoryManager, extract_hist_ranges -def test_history(): +def setUp(): nt.assert_equal(sys.getdefaultencoding(), "ascii") + +def test_history(): ip = get_ipython() with TemporaryDirectory() as tmpdir: #tmpdir = '/software/temp' diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index f2ff47a..fce2111 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -168,6 +168,10 @@ def make_exclude(): if not have['wx']: exclusions.append(ipjoin('lib', 'inputhookwx')) + + # We do this unconditionally, so that the test suite doesn't import + # gtk, changing the default encoding and masking some unicode bugs. + exclusions.append(ipjoin('lib', 'inputhookgtk')) # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://bugs.launchpad.net/bugs/366982