From patchwork Sat Feb 2 01:33:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D5797: tests: use unimported modules in test-demandimport.py From: phabricator X-Patchwork-Id: 38312 Message-Id: <89c4e689d87f072a749e930d0ffffedd@localhost.localdomain> To: mercurial-devel@mercurial-scm.org Date: Sat, 2 Feb 2019 01:33:23 +0000 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 To: indygreg, #hg-reviewers Cc: mercurial-devel 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) == "', mode 'w' at 0x?>", f(re.stderr) assert f(re) == "", f(re) -import contextlib +assert 'telnetlib' not in sys.modules +import telnetlib if ispy3: - assert not isinstance(contextlib, _LazyModule) - assert f(contextlib) == "" + assert not isinstance(telnetlib, _LazyModule) + assert f(telnetlib) == "" else: - assert f(contextlib) == "", f(contextlib) + assert f(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) == "", f(contextlibimp) -assert not util.safehasattr(contextlibimp, 'unknownattr') +assert 'zipfile' not in sys.modules +zipfileimp = __import__('zipfile', globals(), locals(), ['unknownattr']) +assert f(zipfileimp) == "", f(zipfileimp) +assert not util.safehasattr(zipfileimp, 'unknownattr')