##// END OF EJS Templates
tests: use unimported modules in test-demandimport.py...
Gregory Szorc -
r41648:30248d6b default
parent child Browse files
Show More
@@ -194,20 +194,21 b' else:'
194 194 )
195 195 assert f(re) == "<proxied module 'sys'>", f(re)
196 196
197 import contextlib
197 assert 'telnetlib' not in sys.modules
198 import telnetlib
198 199
199 200 if ispy3:
200 assert not isinstance(contextlib, _LazyModule)
201 assert f(contextlib) == "<module 'contextlib' from '?'>"
201 assert not isinstance(telnetlib, _LazyModule)
202 assert f(telnetlib) == "<module 'telnetlib' from '?'>"
202 203 else:
203 assert f(contextlib) == "<unloaded module 'contextlib'>", f(contextlib)
204 assert f(telnetlib) == "<unloaded module 'telnetlib'>", f(telnetlib)
204 205
205 206 try:
206 from contextlib import unknownattr
207 from telnetlib import unknownattr
207 208
208 209 assert False, (
209 210 'no demandmod should be created for attribute of non-package '
210 'module:\ncontextlib.unknownattr = %s' % f(unknownattr)
211 'module:\ntelnetlib.unknownattr = %s' % f(unknownattr)
211 212 )
212 213 except ImportError as inst:
213 214 assert rsub(r"'", '', str(inst)).startswith(
@@ -219,6 +220,7 b' from mercurial import util'
219 220 # Unlike the import statement, __import__() function should not raise
220 221 # ImportError even if fromlist has an unknown item
221 222 # (see Python/import.c:import_module_level() and ensure_fromlist())
222 contextlibimp = __import__('contextlib', globals(), locals(), ['unknownattr'])
223 assert f(contextlibimp) == "<module 'contextlib' from '?'>", f(contextlibimp)
224 assert not util.safehasattr(contextlibimp, 'unknownattr')
223 assert 'zipfile' not in sys.modules
224 zipfileimp = __import__('zipfile', globals(), locals(), ['unknownattr'])
225 assert f(zipfileimp) == "<module 'zipfile' from '?'>", f(zipfileimp)
226 assert not util.safehasattr(zipfileimp, 'unknownattr')
General Comments 0
You need to be logged in to leave comments. Login now