blob: b70ec7caddb3ad969053f59881bec18fe4188245 [file] [log] [blame]
Brett Cannonc0499522012-05-11 14:48:41 -04001import importlib
Nick Coghlan9d3c61c2015-09-05 21:05:05 +10002import importlib.util
Guido van Rossum0ad59d42009-03-30 22:01:35 +00003import os
4import os.path
Brett Cannon8a9583e2008-09-04 05:04:25 +00005import sys
Benjamin Petersonee8712c2008-05-20 21:35:26 +00006from test import support
Brett Cannonc0499522012-05-11 14:48:41 -04007import unittest
8import warnings
Brett Cannone4f41de2013-06-16 13:13:40 -04009with warnings.catch_warnings():
Brett Cannon213b4052015-10-30 14:41:06 -070010 warnings.simplefilter('ignore', DeprecationWarning)
Brett Cannone4f41de2013-06-16 13:13:40 -040011 import imp
Neal Norwitz2294c0d2003-02-12 23:02:21 +000012
Brett Cannon130e4812013-05-03 10:54:23 -040013
14def requires_load_dynamic(meth):
15 """Decorator to skip a test if not running under CPython or lacking
16 imp.load_dynamic()."""
17 meth = support.cpython_only(meth)
18 return unittest.skipIf(not hasattr(imp, 'load_dynamic'),
19 'imp.load_dynamic() required')(meth)
20
21
Thomas Wouters89f507f2006-12-13 04:49:30 +000022class LockTests(unittest.TestCase):
Tim Peters579bed72003-04-26 14:31:24 +000023
Thomas Wouters89f507f2006-12-13 04:49:30 +000024 """Very basic test of import lock functions."""
Tim Peters579bed72003-04-26 14:31:24 +000025
Thomas Wouters89f507f2006-12-13 04:49:30 +000026 def verify_lock_state(self, expected):
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000027 self.assertEqual(imp.lock_held(), expected,
Thomas Wouters89f507f2006-12-13 04:49:30 +000028 "expected imp.lock_held() to be %r" % expected)
29 def testLock(self):
30 LOOPS = 50
Tim Peters579bed72003-04-26 14:31:24 +000031
Thomas Wouters89f507f2006-12-13 04:49:30 +000032 # The import lock may already be held, e.g. if the test suite is run
33 # via "import test.autotest".
34 lock_held_at_start = imp.lock_held()
35 self.verify_lock_state(lock_held_at_start)
Tim Peters579bed72003-04-26 14:31:24 +000036
Thomas Wouters89f507f2006-12-13 04:49:30 +000037 for i in range(LOOPS):
38 imp.acquire_lock()
39 self.verify_lock_state(True)
Tim Peters579bed72003-04-26 14:31:24 +000040
Thomas Wouters89f507f2006-12-13 04:49:30 +000041 for i in range(LOOPS):
Neal Norwitz2294c0d2003-02-12 23:02:21 +000042 imp.release_lock()
Thomas Wouters89f507f2006-12-13 04:49:30 +000043
44 # The original state should be restored now.
45 self.verify_lock_state(lock_held_at_start)
46
47 if not lock_held_at_start:
48 try:
49 imp.release_lock()
50 except RuntimeError:
51 pass
52 else:
53 self.fail("release_lock() without lock should raise "
54 "RuntimeError")
Neal Norwitz2294c0d2003-02-12 23:02:21 +000055
Guido van Rossumce3a72a2007-10-19 23:16:50 +000056class ImportTests(unittest.TestCase):
Alexander Belopolskye8f58322010-10-15 16:28:20 +000057 def setUp(self):
58 mod = importlib.import_module('test.encoded_modules')
59 self.test_strings = mod.test_strings
60 self.test_path = mod.__path__
61
62 def test_import_encoded_module(self):
63 for modname, encoding, teststr in self.test_strings:
64 mod = importlib.import_module('test.encoded_modules.'
65 'module_' + modname)
66 self.assertEqual(teststr, mod.test)
Guido van Rossumce3a72a2007-10-19 23:16:50 +000067
68 def test_find_module_encoding(self):
Alexander Belopolskye8f58322010-10-15 16:28:20 +000069 for mod, encoding, _ in self.test_strings:
Brett Cannon749afa92010-10-29 23:47:23 +000070 with imp.find_module('module_' + mod, self.test_path)[0] as fd:
71 self.assertEqual(fd.encoding, encoding)
Guido van Rossumce3a72a2007-10-19 23:16:50 +000072
Victor Stinnerfe7c5b52011-04-05 01:48:03 +020073 path = [os.path.dirname(__file__)]
Brett Cannondd9a5692012-04-20 12:59:59 -040074 with self.assertRaises(SyntaxError):
75 imp.find_module('badsyntax_pep3120', path)
Victor Stinnerfe7c5b52011-04-05 01:48:03 +020076
Guido van Rossum40d20bc2007-10-22 00:09:51 +000077 def test_issue1267(self):
Alexander Belopolskye8f58322010-10-15 16:28:20 +000078 for mod, encoding, _ in self.test_strings:
79 fp, filename, info = imp.find_module('module_' + mod,
80 self.test_path)
Brett Cannon749afa92010-10-29 23:47:23 +000081 with fp:
82 self.assertNotEqual(fp, None)
83 self.assertEqual(fp.encoding, encoding)
84 self.assertEqual(fp.tell(), 0)
85 self.assertEqual(fp.readline(), '# test %s encoding\n'
86 % encoding)
Guido van Rossum40d20bc2007-10-22 00:09:51 +000087
88 fp, filename, info = imp.find_module("tokenize")
Brett Cannon749afa92010-10-29 23:47:23 +000089 with fp:
90 self.assertNotEqual(fp, None)
91 self.assertEqual(fp.encoding, "utf-8")
92 self.assertEqual(fp.tell(), 0)
93 self.assertEqual(fp.readline(),
94 '"""Tokenization help for Python programs.\n')
Guido van Rossum40d20bc2007-10-22 00:09:51 +000095
Brett Cannon8a9583e2008-09-04 05:04:25 +000096 def test_issue3594(self):
97 temp_mod_name = 'test_imp_helper'
98 sys.path.insert(0, '.')
99 try:
100 with open(temp_mod_name + '.py', 'w') as file:
101 file.write("# coding: cp1252\nu = 'test.test_imp'\n")
102 file, filename, info = imp.find_module(temp_mod_name)
103 file.close()
Ezio Melottib3aedd42010-11-20 19:04:17 +0000104 self.assertEqual(file.encoding, 'cp1252')
Brett Cannon8a9583e2008-09-04 05:04:25 +0000105 finally:
106 del sys.path[0]
107 support.unlink(temp_mod_name + '.py')
108 support.unlink(temp_mod_name + '.pyc')
Brett Cannon8a9583e2008-09-04 05:04:25 +0000109
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000110 def test_issue5604(self):
111 # Test cannot cover imp.load_compiled function.
112 # Martin von Loewis note what shared library cannot have non-ascii
113 # character because init_xxx function cannot be compiled
114 # and issue never happens for dynamic modules.
luzpaza5293b42017-11-05 07:37:50 -0600115 # But sources modified to follow generic way for processing paths.
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000116
Ezio Melotti435b5312010-03-06 01:20:49 +0000117 # the return encoding could be uppercase or None
118 fs_encoding = sys.getfilesystemencoding()
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000119
120 # covers utf-8 and Windows ANSI code pages
121 # one non-space symbol from every page
122 # (http://en.wikipedia.org/wiki/Code_page)
123 known_locales = {
Ezio Melotti9a7d5ac2010-03-05 12:43:17 +0000124 'utf-8' : b'\xc3\xa4',
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000125 'cp1250' : b'\x8C',
126 'cp1251' : b'\xc0',
127 'cp1252' : b'\xc0',
128 'cp1253' : b'\xc1',
129 'cp1254' : b'\xc0',
130 'cp1255' : b'\xe0',
131 'cp1256' : b'\xe0',
132 'cp1257' : b'\xc0',
133 'cp1258' : b'\xc0',
134 }
135
Florent Xicluna21164ce2010-03-20 20:30:53 +0000136 if sys.platform == 'darwin':
137 self.assertEqual(fs_encoding, 'utf-8')
138 # Mac OS X uses the Normal Form D decomposition
139 # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
140 special_char = b'a\xcc\x88'
141 else:
142 special_char = known_locales.get(fs_encoding)
143
Ezio Melotti9a7d5ac2010-03-05 12:43:17 +0000144 if not special_char:
Ezio Melotti76e0d1a2010-03-05 15:08:19 +0000145 self.skipTest("can't run this test with %s as filesystem encoding"
146 % fs_encoding)
147 decoded_char = special_char.decode(fs_encoding)
Ezio Melotti9a7d5ac2010-03-05 12:43:17 +0000148 temp_mod_name = 'test_imp_helper_' + decoded_char
149 test_package_name = 'test_imp_helper_package_' + decoded_char
150 init_file_name = os.path.join(test_package_name, '__init__.py')
151 try:
Ezio Melotti41a6b042010-03-06 01:50:25 +0000152 # if the curdir is not in sys.path the test fails when run with
153 # ./python ./Lib/test/regrtest.py test_imp
154 sys.path.insert(0, os.curdir)
Ezio Melotti9a7d5ac2010-03-05 12:43:17 +0000155 with open(temp_mod_name + '.py', 'w') as file:
156 file.write('a = 1\n')
157 file, filename, info = imp.find_module(temp_mod_name)
Brett Cannon749afa92010-10-29 23:47:23 +0000158 with file:
159 self.assertIsNotNone(file)
160 self.assertTrue(filename[:-3].endswith(temp_mod_name))
161 self.assertEqual(info[0], '.py')
Serhiy Storchaka6787a382013-11-23 22:12:06 +0200162 self.assertEqual(info[1], 'r')
Brett Cannon749afa92010-10-29 23:47:23 +0000163 self.assertEqual(info[2], imp.PY_SOURCE)
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000164
Brett Cannon749afa92010-10-29 23:47:23 +0000165 mod = imp.load_module(temp_mod_name, file, filename, info)
166 self.assertEqual(mod.a, 1)
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000167
Brett Cannonc0499522012-05-11 14:48:41 -0400168 with warnings.catch_warnings():
169 warnings.simplefilter('ignore')
170 mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
Ezio Melotti435b5312010-03-06 01:20:49 +0000171 self.assertEqual(mod.a, 1)
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000172
Brett Cannonc0499522012-05-11 14:48:41 -0400173 with warnings.catch_warnings():
174 warnings.simplefilter('ignore')
Ezio Melottie5e7a7c2013-03-16 21:49:20 +0200175 if not sys.dont_write_bytecode:
176 mod = imp.load_compiled(
177 temp_mod_name,
178 imp.cache_from_source(temp_mod_name + '.py'))
Ezio Melotti435b5312010-03-06 01:20:49 +0000179 self.assertEqual(mod.a, 1)
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000180
Ezio Melotti9a7d5ac2010-03-05 12:43:17 +0000181 if not os.path.exists(test_package_name):
182 os.mkdir(test_package_name)
183 with open(init_file_name, 'w') as file:
184 file.write('b = 2\n')
Brett Cannonc0499522012-05-11 14:48:41 -0400185 with warnings.catch_warnings():
186 warnings.simplefilter('ignore')
187 package = imp.load_package(test_package_name, test_package_name)
Ezio Melotti435b5312010-03-06 01:20:49 +0000188 self.assertEqual(package.b, 2)
Ezio Melotti9a7d5ac2010-03-05 12:43:17 +0000189 finally:
Ezio Melotti41a6b042010-03-06 01:50:25 +0000190 del sys.path[0]
Brett Cannonf299abd2015-04-13 14:21:02 -0400191 for ext in ('.py', '.pyc'):
Ezio Melotti435b5312010-03-06 01:20:49 +0000192 support.unlink(temp_mod_name + ext)
193 support.unlink(init_file_name + ext)
Ezio Melotti9a7d5ac2010-03-05 12:43:17 +0000194 support.rmtree(test_package_name)
Victor Stinner047b7ae2014-10-05 17:37:41 +0200195 support.rmtree('__pycache__')
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000196
Victor Stinnerc68b6aa2011-04-23 00:41:19 +0200197 def test_issue9319(self):
Antoine Pitrou11846902011-04-25 21:39:49 +0200198 path = os.path.dirname(__file__)
Victor Stinner7fdd0fe2011-04-23 01:24:11 +0200199 self.assertRaises(SyntaxError,
Antoine Pitrou11846902011-04-25 21:39:49 +0200200 imp.find_module, "badsyntax_pep3120", [path])
Victor Stinnerc68b6aa2011-04-23 00:41:19 +0200201
Nick Coghlan91b9f132012-09-01 00:13:45 +1000202 def test_load_from_source(self):
203 # Verify that the imp module can correctly load and find .py files
204 # XXX (ncoghlan): It would be nice to use support.CleanImport
205 # here, but that breaks because the os module registers some
206 # handlers in copy_reg on import. Since CleanImport doesn't
207 # revert that registration, the module is left in a broken
208 # state after reversion. Reinitialising the module contents
209 # and just reverting os.environ to its previous state is an OK
210 # workaround
211 orig_path = os.path
212 orig_getenv = os.getenv
213 with support.EnvironmentVarGuard():
214 x = imp.find_module("os")
215 self.addCleanup(x[0].close)
216 new_os = imp.load_module("os", *x)
217 self.assertIs(os, new_os)
218 self.assertIs(orig_path, new_os.path)
219 self.assertIsNot(orig_getenv, new_os.getenv)
220
Brett Cannon130e4812013-05-03 10:54:23 -0400221 @requires_load_dynamic
Nick Coghlan91b9f132012-09-01 00:13:45 +1000222 def test_issue15828_load_extensions(self):
223 # Issue 15828 picked up that the adapter between the old imp API
224 # and importlib couldn't handle C extensions
225 example = "_heapq"
226 x = imp.find_module(example)
Brett Cannon848cdfd2012-08-31 11:31:20 -0400227 file_ = x[0]
228 if file_ is not None:
229 self.addCleanup(file_.close)
Nick Coghlan91b9f132012-09-01 00:13:45 +1000230 mod = imp.load_module(example, *x)
231 self.assertEqual(mod.__name__, example)
232
Brett Cannon130e4812013-05-03 10:54:23 -0400233 @requires_load_dynamic
Andrew Svetlov6b2cbeb2012-12-14 17:04:59 +0200234 def test_issue16421_multiple_modules_in_one_dll(self):
235 # Issue 16421: loading several modules from the same compiled file fails
236 m = '_testimportmultiple'
237 fileobj, pathname, description = imp.find_module(m)
238 fileobj.close()
239 mod0 = imp.load_dynamic(m, pathname)
Andrew Svetlovef9a43b2012-12-15 17:22:59 +0200240 mod1 = imp.load_dynamic('_testimportmultiple_foo', pathname)
241 mod2 = imp.load_dynamic('_testimportmultiple_bar', pathname)
Andrew Svetlov6b2cbeb2012-12-14 17:04:59 +0200242 self.assertEqual(mod0.__name__, m)
Andrew Svetlovef9a43b2012-12-15 17:22:59 +0200243 self.assertEqual(mod1.__name__, '_testimportmultiple_foo')
244 self.assertEqual(mod2.__name__, '_testimportmultiple_bar')
Andrew Svetlov6b2cbeb2012-12-14 17:04:59 +0200245 with self.assertRaises(ImportError):
246 imp.load_dynamic('nonexistent', pathname)
247
Brett Cannon130e4812013-05-03 10:54:23 -0400248 @requires_load_dynamic
Brett Cannonf0434e62012-04-20 15:22:50 -0400249 def test_load_dynamic_ImportError_path(self):
250 # Issue #1559549 added `name` and `path` attributes to ImportError
251 # in order to provide better detail. Issue #10854 implemented those
252 # attributes on import failures of extensions on Windows.
253 path = 'bogus file path'
254 name = 'extension'
255 with self.assertRaises(ImportError) as err:
256 imp.load_dynamic(name, path)
257 self.assertIn(path, err.exception.path)
258 self.assertEqual(name, err.exception.name)
259
Brett Cannon130e4812013-05-03 10:54:23 -0400260 @requires_load_dynamic
Brett Cannon9d0f7722013-05-03 10:37:08 -0400261 def test_load_module_extension_file_is_None(self):
262 # When loading an extension module and the file is None, open one
263 # on the behalf of imp.load_dynamic().
264 # Issue #15902
Brett Cannon8772b182013-05-04 17:54:57 -0400265 name = '_testimportmultiple'
Brett Cannon9d0f7722013-05-03 10:37:08 -0400266 found = imp.find_module(name)
Benjamin Petersonaa6f6882013-05-11 16:29:03 -0500267 if found[0] is not None:
268 found[0].close()
Brett Cannon8772b182013-05-04 17:54:57 -0400269 if found[2][2] != imp.C_EXTENSION:
Zachary Ware9fe6d862013-12-08 00:20:35 -0600270 self.skipTest("found module doesn't appear to be a C extension")
Brett Cannon9d0f7722013-05-03 10:37:08 -0400271 imp.load_module(name, None, *found[1:])
272
Nick Coghlan9d3c61c2015-09-05 21:05:05 +1000273 @requires_load_dynamic
274 def test_issue24748_load_module_skips_sys_modules_check(self):
275 name = 'test.imp_dummy'
276 try:
277 del sys.modules[name]
278 except KeyError:
279 pass
280 try:
281 module = importlib.import_module(name)
282 spec = importlib.util.find_spec('_testmultiphase')
283 module = imp.load_dynamic(name, spec.origin)
284 self.assertEqual(module.__name__, name)
285 self.assertEqual(module.__spec__.name, name)
286 self.assertEqual(module.__spec__.origin, spec.origin)
287 self.assertRaises(AttributeError, getattr, module, 'dummy_name')
288 self.assertEqual(module.int_const, 1969)
289 self.assertIs(sys.modules[name], module)
290 finally:
291 try:
292 del sys.modules[name]
293 except KeyError:
294 pass
295
Brett Cannon997487d2013-06-07 13:26:53 -0400296 @unittest.skipIf(sys.dont_write_bytecode,
297 "test meaningful only when writing bytecode")
298 def test_bug7732(self):
Antoine Pitroubb2c45e2013-08-19 23:31:18 +0200299 with support.temp_cwd():
300 source = support.TESTFN + '.py'
301 os.mkdir(source)
Brett Cannon997487d2013-06-07 13:26:53 -0400302 self.assertRaisesRegex(ImportError, '^No module',
303 imp.find_module, support.TESTFN, ["."])
Brett Cannon330cc522013-08-23 12:10:09 -0400304
Brett Cannona4975a92013-08-23 11:45:57 -0400305 def test_multiple_calls_to_get_data(self):
306 # Issue #18755: make sure multiple calls to get_data() can succeed.
307 loader = imp._LoadSourceCompatibility('imp', imp.__file__,
308 open(imp.__file__))
309 loader.get_data(imp.__file__) # File should be closed
310 loader.get_data(imp.__file__) # Will need to create a newly opened file
Brett Cannon997487d2013-06-07 13:26:53 -0400311
Serhiy Storchakaf7eae0a2017-06-28 08:30:06 +0300312 def test_load_source(self):
Victor Stinnera505ecd2017-10-13 13:47:49 -0700313 # Create a temporary module since load_source(name) modifies
314 # sys.modules[name] attributes like __loader___
315 modname = f"tmp{__name__}"
316 mod = type(sys.modules[__name__])(modname)
317 with support.swap_item(sys.modules, modname, mod):
318 with self.assertRaisesRegex(ValueError, 'embedded null'):
319 imp.load_source(modname, __file__ + "\0")
Serhiy Storchakaf7eae0a2017-06-28 08:30:06 +0300320
Oren Milman9974e1b2017-09-19 14:39:47 +0300321 @support.cpython_only
322 def test_issue31315(self):
323 # There shouldn't be an assertion failure in imp.create_dynamic(),
324 # when spec.name is not a string.
325 create_dynamic = support.get_attribute(imp, 'create_dynamic')
326 class BadSpec:
327 name = None
328 origin = 'foo'
329 with self.assertRaises(TypeError):
330 create_dynamic(BadSpec())
331
Guido van Rossum0ad59d42009-03-30 22:01:35 +0000332
Nick Coghlan6ead5522009-10-18 13:19:33 +0000333class ReloadTests(unittest.TestCase):
334
335 """Very basic tests to make sure that imp.reload() operates just like
336 reload()."""
337
338 def test_source(self):
Florent Xicluna97133722010-03-20 20:31:34 +0000339 # XXX (ncoghlan): It would be nice to use test.support.CleanImport
Nick Coghlan6ead5522009-10-18 13:19:33 +0000340 # here, but that breaks because the os module registers some
341 # handlers in copy_reg on import. Since CleanImport doesn't
342 # revert that registration, the module is left in a broken
343 # state after reversion. Reinitialising the module contents
344 # and just reverting os.environ to its previous state is an OK
345 # workaround
346 with support.EnvironmentVarGuard():
347 import os
348 imp.reload(os)
349
350 def test_extension(self):
351 with support.CleanImport('time'):
352 import time
353 imp.reload(time)
354
355 def test_builtin(self):
356 with support.CleanImport('marshal'):
357 import marshal
358 imp.reload(marshal)
Christian Heimes13a7a212008-01-07 17:13:09 +0000359
Ezio Melotti056bafe2013-08-10 19:59:36 +0300360 def test_with_deleted_parent(self):
361 # see #18681
362 from html import parser
Serhiy Storchakab2122912013-08-11 20:12:20 +0300363 html = sys.modules.pop('html')
364 def cleanup():
365 sys.modules['html'] = html
Ezio Melotti056bafe2013-08-10 19:59:36 +0300366 self.addCleanup(cleanup)
367 with self.assertRaisesRegex(ImportError, 'html'):
368 imp.reload(parser)
369
Guido van Rossum40d20bc2007-10-22 00:09:51 +0000370
Barry Warsaw28a691b2010-04-17 00:19:56 +0000371class PEP3147Tests(unittest.TestCase):
372 """Tests of PEP 3147."""
373
374 tag = imp.get_tag()
375
Brett Cannon19a2f592012-07-09 13:58:07 -0400376 @unittest.skipUnless(sys.implementation.cache_tag is not None,
377 'requires sys.implementation.cache_tag not be None')
Barry Warsaw28a691b2010-04-17 00:19:56 +0000378 def test_cache_from_source(self):
379 # Given the path to a .py file, return the path to its PEP 3147
380 # defined .pyc file (i.e. under __pycache__).
Brett Cannon410e88d2012-04-22 13:29:47 -0400381 path = os.path.join('foo', 'bar', 'baz', 'qux.py')
382 expect = os.path.join('foo', 'bar', 'baz', '__pycache__',
383 'qux.{}.pyc'.format(self.tag))
384 self.assertEqual(imp.cache_from_source(path, True), expect)
385
Brett Cannon19a2f592012-07-09 13:58:07 -0400386 @unittest.skipUnless(sys.implementation.cache_tag is not None,
387 'requires sys.implementation.cache_tag to not be '
388 'None')
Barry Warsaw28a691b2010-04-17 00:19:56 +0000389 def test_source_from_cache(self):
390 # Given the path to a PEP 3147 defined .pyc file, return the path to
391 # its source. This tests the good path.
Brett Cannon410e88d2012-04-22 13:29:47 -0400392 path = os.path.join('foo', 'bar', 'baz', '__pycache__',
393 'qux.{}.pyc'.format(self.tag))
394 expect = os.path.join('foo', 'bar', 'baz', 'qux.py')
395 self.assertEqual(imp.source_from_cache(path), expect)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000396
Barry Warsaw28a691b2010-04-17 00:19:56 +0000397
Victor Stinner1a4d12d2010-08-13 13:07:29 +0000398class NullImporterTests(unittest.TestCase):
Victor Stinner09c449c2010-08-13 22:23:24 +0000399 @unittest.skipIf(support.TESTFN_UNENCODABLE is None,
Victor Stinner1a4d12d2010-08-13 13:07:29 +0000400 "Need an undecodeable filename")
401 def test_unencodeable(self):
Victor Stinner09c449c2010-08-13 22:23:24 +0000402 name = support.TESTFN_UNENCODABLE
Victor Stinner1a4d12d2010-08-13 13:07:29 +0000403 os.mkdir(name)
404 try:
405 self.assertRaises(ImportError, imp.NullImporter, name)
406 finally:
407 os.rmdir(name)
408
409
Neal Norwitz2294c0d2003-02-12 23:02:21 +0000410if __name__ == "__main__":
Brett Cannon95ea11f2013-05-03 10:57:08 -0400411 unittest.main()