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.
This commit is contained in:
parent
5a53fdeee8
commit
9a7d5ac9f6
|
@ -85,13 +85,14 @@ 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 can be uppercase
|
||||||
|
locale_encoding = locale.getpreferredencoding().lower()
|
||||||
|
|
||||||
# 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',
|
||||||
|
@ -104,46 +105,48 @@ class ImportTests(unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
special_char = known_locales.get(locale_encoding)
|
special_char = known_locales.get(locale_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 preferred encoding"
|
||||||
temp_mod_name = 'test_imp_helper_' + encoded_char
|
% locale_encoding)
|
||||||
test_package_name = 'test_imp_helper_package_' + encoded_char
|
decoded_char = special_char.decode(locale_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)
|
with open(temp_mod_name + '.py', 'w') as file:
|
||||||
self.assertNotEquals(None, file)
|
file.write('a = 1\n')
|
||||||
self.assertTrue(filename[:-3].endswith(temp_mod_name))
|
file, filename, info = imp.find_module(temp_mod_name)
|
||||||
self.assertEquals('.py', info[0])
|
self.assertNotEquals(None, file)
|
||||||
self.assertEquals('U', info[1])
|
self.assertTrue(filename[:-3].endswith(temp_mod_name))
|
||||||
self.assertEquals(imp.PY_SOURCE, info[2])
|
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)
|
mod = imp.load_module(temp_mod_name, file, filename, info)
|
||||||
self.assertEquals(1, mod.a)
|
self.assertEquals(1, mod.a)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
|
mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
|
||||||
self.assertEquals(1, mod.a)
|
self.assertEquals(1, mod.a)
|
||||||
|
|
||||||
mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc')
|
mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc')
|
||||||
self.assertEquals(1, mod.a)
|
self.assertEquals(1, mod.a)
|
||||||
|
|
||||||
if not os.path.exists(test_package_name):
|
if not os.path.exists(test_package_name):
|
||||||
os.mkdir(test_package_name)
|
os.mkdir(test_package_name)
|
||||||
with open(init_file_name, 'w') as file:
|
with open(init_file_name, 'w') as file:
|
||||||
file.write('b = 2\n')
|
file.write('b = 2\n')
|
||||||
package = imp.load_package(test_package_name, test_package_name)
|
package = imp.load_package(test_package_name, test_package_name)
|
||||||
self.assertEquals(2, package.b)
|
self.assertEquals(2, package.b)
|
||||||
finally:
|
finally:
|
||||||
support.unlink(temp_mod_name + '.py')
|
support.unlink(temp_mod_name + '.py')
|
||||||
support.unlink(temp_mod_name + '.pyc')
|
support.unlink(temp_mod_name + '.pyc')
|
||||||
support.unlink(temp_mod_name + '.pyo')
|
support.unlink(temp_mod_name + '.pyo')
|
||||||
|
|
||||||
support.unlink(init_file_name + '.py')
|
support.unlink(init_file_name + '.py')
|
||||||
support.unlink(init_file_name + '.pyc')
|
support.unlink(init_file_name + '.pyc')
|
||||||
support.unlink(init_file_name + '.pyo')
|
support.unlink(init_file_name + '.pyo')
|
||||||
support.rmtree(test_package_name)
|
support.rmtree(test_package_name)
|
||||||
|
|
||||||
|
|
||||||
class ReloadTests(unittest.TestCase):
|
class ReloadTests(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue