diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 1f24f28..c5f4e80 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -240,3 +240,10 @@ tclass.py: deleting object: C-third _ip.run_cell("zz = 23") _ip.magic('run -i %s' % self.fname) tt.assert_equals(_ip.user_ns['yy'], 23) + + def test_unicode(self): + """Check that files in odd encodings are accepted.""" + mydir = os.path.dirname(__file__) + na = os.path.join(mydir, 'nonascii.py') + _ip.magic('run %s' % na) + tt.assert_equals(_ip.user_ns['u'], u'Ўт№Ф') diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index 2c9df7c..50a1e4d 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -70,7 +70,7 @@ if sys.version_info[0] >= 3: def execfile(fname, glob, loc=None): loc = loc if (loc is not None) else glob - exec compile(open(fname).read(), fname, 'exec') in glob, loc + exec compile(open(fname, 'rb').read(), fname, 'exec') in glob, loc # Refactor print statements in doctests. _print_statement_re = re.compile(r"\bprint (?P.*)$", re.MULTILINE)