Kaydet (Commit) c0ddee54 authored tarafından Ezio Melotti's avatar Ezio Melotti

Merged revisions 78689,78696-78697,78708,78711 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r78689 | ezio.melotti | 2010-03-05 14:43:17 +0200 (Fri, 05 Mar 2010) | 1 line

  This fixes a missing .lower() on the encoding name, a wrong byte undecodable by UTF-8, a wrong variable name, hopefully some windows buildbot on 3.x and adds a proper skip. It might break other things though.
........
  r78696 | ezio.melotti | 2010-03-05 17:08:19 +0200 (Fri, 05 Mar 2010) | 1 line

  r78689 enabled the test on more platforms but the buildbot did not like it. Using the filesystem encoding might work better. Also see #5604.
........
  r78697 | ezio.melotti | 2010-03-05 17:17:26 +0200 (Fri, 05 Mar 2010) | 1 line

  sys.getdefaultencoding() can return None.
........
  r78708 | ezio.melotti | 2010-03-06 03:20:49 +0200 (Sat, 06 Mar 2010) | 1 line

  Cleanup and minor fixes.
........
  r78711 | ezio.melotti | 2010-03-06 03:50:25 +0200 (Sat, 06 Mar 2010) | 1 line

  The test was failing because the curdir was missing from sys.path. This should fix the problem.
........
üst 78576508
import imp import imp
import locale
import os import os
import os.path import os.path
import sys import sys
...@@ -85,13 +84,15 @@ class ImportTests(unittest.TestCase): ...@@ -85,13 +84,15 @@ class ImportTests(unittest.TestCase):
# and issue never happens for dynamic modules. # and issue never happens for dynamic modules.
# But sources modified to follow generic way for processing pathes. # But sources modified to follow generic way for processing pathes.
locale_encoding = locale.getpreferredencoding() # the return encoding could be uppercase or None
fs_encoding = sys.getfilesystemencoding()
fs_encoding = fs_encoding.lower() if fs_encoding else 'ascii'
# covers utf-8 and Windows ANSI code pages # covers utf-8 and Windows ANSI code pages
# one non-space symbol from every page # one non-space symbol from every page
# (http://en.wikipedia.org/wiki/Code_page) # (http://en.wikipedia.org/wiki/Code_page)
known_locales = { known_locales = {
'utf-8' : b'\xe4', 'utf-8' : b'\xc3\xa4',
'cp1250' : b'\x8C', 'cp1250' : b'\x8C',
'cp1251' : b'\xc0', 'cp1251' : b'\xc0',
'cp1252' : b'\xc0', 'cp1252' : b'\xc0',
...@@ -103,47 +104,49 @@ class ImportTests(unittest.TestCase): ...@@ -103,47 +104,49 @@ class ImportTests(unittest.TestCase):
'cp1258' : b'\xc0', 'cp1258' : b'\xc0',
} }
special_char = known_locales.get(locale_encoding) special_char = known_locales.get(fs_encoding)
if special_char: if not special_char:
encoded_char = special_char.decode(locale_encoding) self.skipTest("can't run this test with %s as filesystem encoding"
temp_mod_name = 'test_imp_helper_' + encoded_char % fs_encoding)
test_package_name = 'test_imp_helper_package_' + encoded_char decoded_char = special_char.decode(fs_encoding)
init_file_name = os.path.join(test_package_name, '__init__.py') temp_mod_name = 'test_imp_helper_' + decoded_char
try: test_package_name = 'test_imp_helper_package_' + decoded_char
with open(temp_mod_name + '.py', 'w') as file: init_file_name = os.path.join(test_package_name, '__init__.py')
file.write('a = 1\n') try:
file, filename, info = imp.find_module(temp_mod_name) # if the curdir is not in sys.path the test fails when run with
self.assertNotEquals(None, file) # ./python ./Lib/test/regrtest.py test_imp
self.assertTrue(filename[:-3].endswith(temp_mod_name)) sys.path.insert(0, os.curdir)
self.assertEquals('.py', info[0]) with open(temp_mod_name + '.py', 'w') as file:
self.assertEquals('U', info[1]) file.write('a = 1\n')
self.assertEquals(imp.PY_SOURCE, info[2]) file, filename, info = imp.find_module(temp_mod_name)
self.assertIsNotNone(file)
mod = imp.load_module(temp_mod_name, file, filename, info) self.assertTrue(filename[:-3].endswith(temp_mod_name))
self.assertEquals(1, mod.a) self.assertEqual(info[0], '.py')
file.close() self.assertEqual(info[1], 'U')
self.assertEqual(info[2], imp.PY_SOURCE)
mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
self.assertEquals(1, mod.a) mod = imp.load_module(temp_mod_name, file, filename, info)
self.assertEqual(mod.a, 1)
mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc') file.close()
self.assertEquals(1, mod.a)
mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
if not os.path.exists(test_package_name): self.assertEqual(mod.a, 1)
os.mkdir(test_package_name)
with open(init_file_name, 'w') as file: mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc')
file.write('b = 2\n') self.assertEqual(mod.a, 1)
package = imp.load_package(test_package_name, test_package_name)
self.assertEquals(2, package.b) if not os.path.exists(test_package_name):
finally: os.mkdir(test_package_name)
support.unlink(temp_mod_name + '.py') with open(init_file_name, 'w') as file:
support.unlink(temp_mod_name + '.pyc') file.write('b = 2\n')
support.unlink(temp_mod_name + '.pyo') package = imp.load_package(test_package_name, test_package_name)
self.assertEqual(package.b, 2)
support.unlink(init_file_name + '.py') finally:
support.unlink(init_file_name + '.pyc') del sys.path[0]
support.unlink(init_file_name + '.pyo') for ext in ('.py', '.pyc', '.pyo'):
support.rmtree(test_package_name) support.unlink(temp_mod_name + ext)
support.unlink(init_file_name + ext)
support.rmtree(test_package_name)
def test_reload(self): def test_reload(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment