summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2010-03-06 03:09:26 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2010-03-06 03:09:26 (GMT)
commitc0ddee54b066e937b151a8598be5dba7f45f2405 (patch)
tree45b9d778c9aac8da9219cdf90d28fda704f9cd13 /Lib
parent7857650833b68664f879edfc33bf8dc183bbc4a2 (diff)
downloadcpython-c0ddee54b066e937b151a8598be5dba7f45f2405.zip
cpython-c0ddee54b066e937b151a8598be5dba7f45f2405.tar.gz
cpython-c0ddee54b066e937b151a8598be5dba7f45f2405.tar.bz2
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. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_imp.py91
1 files changed, 47 insertions, 44 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 70169e0..c24d465 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -1,5 +1,4 @@
import imp
-import locale
import os
import os.path
import sys
@@ -85,13 +84,15 @@ class ImportTests(unittest.TestCase):
# and issue never happens for dynamic modules.
# 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
# one non-space symbol from every page
# (http://en.wikipedia.org/wiki/Code_page)
known_locales = {
- 'utf-8' : b'\xe4',
+ 'utf-8' : b'\xc3\xa4',
'cp1250' : b'\x8C',
'cp1251' : b'\xc0',
'cp1252' : b'\xc0',
@@ -103,47 +104,49 @@ class ImportTests(unittest.TestCase):
'cp1258' : b'\xc0',
}
- special_char = known_locales.get(locale_encoding)
- if special_char:
- encoded_char = special_char.decode(locale_encoding)
- temp_mod_name = 'test_imp_helper_' + encoded_char
- test_package_name = 'test_imp_helper_package_' + encoded_char
- init_file_name = os.path.join(test_package_name, '__init__.py')
- try:
- with open(temp_mod_name + '.py', 'w') as file:
- file.write('a = 1\n')
- file, filename, info = imp.find_module(temp_mod_name)
- self.assertNotEquals(None, file)
- self.assertTrue(filename[:-3].endswith(temp_mod_name))
- self.assertEquals('.py', info[0])
- self.assertEquals('U', info[1])
- self.assertEquals(imp.PY_SOURCE, info[2])
-
- mod = imp.load_module(temp_mod_name, file, filename, info)
- self.assertEquals(1, mod.a)
- file.close()
-
- mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
- self.assertEquals(1, mod.a)
-
- mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc')
- self.assertEquals(1, mod.a)
-
- if not os.path.exists(test_package_name):
- os.mkdir(test_package_name)
- with open(init_file_name, 'w') as file:
- file.write('b = 2\n')
- package = imp.load_package(test_package_name, test_package_name)
- self.assertEquals(2, package.b)
- finally:
- support.unlink(temp_mod_name + '.py')
- support.unlink(temp_mod_name + '.pyc')
- support.unlink(temp_mod_name + '.pyo')
-
- support.unlink(init_file_name + '.py')
- support.unlink(init_file_name + '.pyc')
- support.unlink(init_file_name + '.pyo')
- support.rmtree(test_package_name)
+ special_char = known_locales.get(fs_encoding)
+ if not special_char:
+ self.skipTest("can't run this test with %s as filesystem encoding"
+ % fs_encoding)
+ decoded_char = special_char.decode(fs_encoding)
+ temp_mod_name = 'test_imp_helper_' + decoded_char
+ test_package_name = 'test_imp_helper_package_' + decoded_char
+ init_file_name = os.path.join(test_package_name, '__init__.py')
+ try:
+ # if the curdir is not in sys.path the test fails when run with
+ # ./python ./Lib/test/regrtest.py test_imp
+ sys.path.insert(0, os.curdir)
+ with open(temp_mod_name + '.py', 'w') as file:
+ file.write('a = 1\n')
+ file, filename, info = imp.find_module(temp_mod_name)
+ self.assertIsNotNone(file)
+ self.assertTrue(filename[:-3].endswith(temp_mod_name))
+ self.assertEqual(info[0], '.py')
+ self.assertEqual(info[1], 'U')
+ self.assertEqual(info[2], imp.PY_SOURCE)
+
+ mod = imp.load_module(temp_mod_name, file, filename, info)
+ self.assertEqual(mod.a, 1)
+ file.close()
+
+ mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
+ self.assertEqual(mod.a, 1)
+
+ mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc')
+ self.assertEqual(mod.a, 1)
+
+ if not os.path.exists(test_package_name):
+ os.mkdir(test_package_name)
+ with open(init_file_name, 'w') as file:
+ file.write('b = 2\n')
+ package = imp.load_package(test_package_name, test_package_name)
+ self.assertEqual(package.b, 2)
+ finally:
+ del sys.path[0]
+ for ext in ('.py', '.pyc', '.pyo'):
+ support.unlink(temp_mod_name + ext)
+ support.unlink(init_file_name + ext)
+ support.rmtree(test_package_name)
def test_reload(self):