D5797: tests: use unimported modules in test-demandimport.py
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Fri Feb 1 20:33:23 EST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG36e2dd4fb3d2: tests: use unimported modules in test-demandimport.py (authored by indygreg, committed by ).
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D5797?vs=13681&id=13688
REVISION DETAIL
https://phab.mercurial-scm.org/D5797
AFFECTED FILES
tests/test-demandimport.py
CHANGE DETAILS
diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
--- a/tests/test-demandimport.py
+++ b/tests/test-demandimport.py
@@ -182,26 +182,28 @@
assert f(re.stderr) == "<open file '<whatever>', mode 'w' at 0x?>", f(re.stderr)
assert f(re) == "<proxied module 'sys'>", f(re)
-import contextlib
+assert 'telnetlib' not in sys.modules
+import telnetlib
if ispy3:
- assert not isinstance(contextlib, _LazyModule)
- assert f(contextlib) == "<module 'contextlib' from '?'>"
+ assert not isinstance(telnetlib, _LazyModule)
+ assert f(telnetlib) == "<module 'telnetlib' from '?'>"
else:
- assert f(contextlib) == "<unloaded module 'contextlib'>", f(contextlib)
+ assert f(telnetlib) == "<unloaded module 'telnetlib'>", f(telnetlib)
try:
- from contextlib import unknownattr
+ from telnetlib import unknownattr
assert False, ('no demandmod should be created for attribute of non-package '
- 'module:\ncontextlib.unknownattr = %s' % f(unknownattr))
+ 'module:\ntelnetlib.unknownattr = %s' % f(unknownattr))
except ImportError as inst:
assert rsub(r"'", '', str(inst)).startswith('cannot import name unknownattr')
from mercurial import util
# Unlike the import statement, __import__() function should not raise
# ImportError even if fromlist has an unknown item
# (see Python/import.c:import_module_level() and ensure_fromlist())
-contextlibimp = __import__('contextlib', globals(), locals(), ['unknownattr'])
-assert f(contextlibimp) == "<module 'contextlib' from '?'>", f(contextlibimp)
-assert not util.safehasattr(contextlibimp, 'unknownattr')
+assert 'zipfile' not in sys.modules
+zipfileimp = __import__('zipfile', globals(), locals(), ['unknownattr'])
+assert f(zipfileimp) == "<module 'zipfile' from '?'>", f(zipfileimp)
+assert not util.safehasattr(zipfileimp, 'unknownattr')
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list