##// END OF EJS Templates
cat: don't prefetch files unless the output requires it...
cat: don't prefetch files unless the output requires it It's a waste to cache lfs blobs when cat'ing the raw data at best, but a hassle debugging when the blob is missing. I'm not sure if there are other commands that have '{data}' for output, and if there's a general way to prefetch on that keyword. It's interesting that the verbose output seems to leak into the JSON output, but that seems like an existing bug.

File last commit:

r41570:28ed6d30 default
r42678:561cd02c default
Show More
test-demandimport.py
226 lines | 6.5 KiB | text/x-python | PythonLexer
/ tests / test-demandimport.py
Augie Fackler
tests: ensure demandimport test uses absolute_import
r33919 from __future__ import absolute_import, print_function
Pulkit Goyal
py3: make test-demandimport use print_function...
r28948
Martin Geisler
tests: renamed Python tests to .py
r8449 from mercurial import demandimport
demandimport.enable()
Augie Fackler
demandimport: blacklist distutils.msvc9compiler (issue4475)...
r23643 import os
timeless
tests: skip demandimport if disabled...
r29868 import subprocess
import sys
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 import types
# Don't import pycompat because it has too many side-effects.
ispy3 = sys.version_info[0] >= 3
timeless
tests: skip demandimport if disabled...
r29868
# Only run if demandimport is allowed
if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'],
'demandimport']):
sys.exit(80)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 # We rely on assert, which gets optimized out.
if sys.flags.optimize:
sys.exit(80)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 if ispy3:
from importlib.util import _LazyModule
try:
from importlib.util import _Module as moduletype
except ImportError:
moduletype = types.ModuleType
else:
moduletype = types.ModuleType
Augie Fackler
demandimport: blacklist distutils.msvc9compiler (issue4475)...
r23643 if os.name != 'nt':
try:
import distutils.msvc9compiler
Pulkit Goyal
py3: make test-demandimport use print_function...
r28948 print('distutils.msvc9compiler needs to be an immediate '
'importerror on non-windows platforms')
Augie Fackler
demandimport: blacklist distutils.msvc9compiler (issue4475)...
r23643 distutils.msvc9compiler
except ImportError:
pass
Martin Geisler
tests: renamed Python tests to .py
r8449 import re
rsub = re.sub
def f(obj):
l = repr(obj)
l = rsub("0x[0-9a-fA-F]+", "0x?", l)
l = rsub("from '.*'", "from '?'", l)
Dan Villiom Podlaski Christiansen
test-demandimport.py: PyPy support...
r13083 l = rsub("'<[a-z]*>'", "'<whatever>'", l)
Martin Geisler
tests: renamed Python tests to .py
r8449 return l
Martin von Zweigbergk
tests: actually check that HGDEMANDIMPORT=disable disables demandimport...
r36255 demandimport.disable()
os.environ['HGDEMANDIMPORT'] = 'disable'
# this enable call should not actually enable demandimport!
demandimport.enable()
from mercurial import node
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646
# We use assert instead of a unittest test case because having imports inside
# functions changes behavior of the demand importer.
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 if ispy3:
assert not isinstance(node, _LazyModule)
else:
assert f(node) == "<module 'mercurial.node' from '?'>", f(node)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646
Martin von Zweigbergk
tests: actually check that HGDEMANDIMPORT=disable disables demandimport...
r36255 # now enable it for real
del os.environ['HGDEMANDIMPORT']
demandimport.enable()
Martin von Zweigbergk
tests: avoid referring to pvec in demandimport test...
r36265 # Test access to special attributes through demandmod proxy
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 assert 'mercurial.error' not in sys.modules
Martin von Zweigbergk
tests: avoid referring to pvec in demandimport test...
r36265 from mercurial import error as errorproxy
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
if ispy3:
# unsure why this isn't lazy.
assert not isinstance(f, _LazyModule)
assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
else:
assert f(errorproxy) == "<unloaded module 'error'>", f(errorproxy)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 doc = ' '.join(errorproxy.__doc__.split()[:3])
assert doc == 'Mercurial exceptions. This', doc
assert errorproxy.__name__ == 'mercurial.error', errorproxy.__name__
Martin von Zweigbergk
tests: avoid referring to pvec in demandimport test...
r36265 # __name__ must be accessible via __dict__ so the relative imports can be
# resolved
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 name = errorproxy.__dict__['__name__']
assert name == 'mercurial.error', name
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 if ispy3:
assert not isinstance(errorproxy, _LazyModule)
assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
else:
assert f(errorproxy) == "<proxied module 'error'>", f(errorproxy)
Martin von Zweigbergk
tests: avoid referring to pvec in demandimport test...
r36265
Martin Geisler
tests: renamed Python tests to .py
r8449 import os
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 if ispy3:
assert not isinstance(os, _LazyModule)
assert f(os) == "<module 'os' from '?'>", f(os)
else:
assert f(os) == "<unloaded module 'os'>", f(os)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 assert f(os.system) == '<built-in function system>', f(os.system)
assert f(os) == "<module 'os' from '?'>", f(os)
Martin Geisler
tests: renamed Python tests to .py
r8449
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 assert 'mercurial.utils.procutil' not in sys.modules
Matt Harbison
tests: migrate demandimport.py away from deprecated `util` module symbols
r37983 from mercurial.utils import procutil
Martin Geisler
tests: renamed Python tests to .py
r8449
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 if ispy3:
assert isinstance(procutil, _LazyModule)
assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
procutil
)
else:
assert f(procutil) == "<unloaded module 'procutil'>", f(procutil)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 assert f(procutil.system) == '<function system at 0x?>', f(procutil.system)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 assert procutil.__class__ == moduletype, procutil.__class__
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
procutil
)
assert f(procutil.system) == '<function system at 0x?>', f(procutil.system)
Martin Geisler
tests: renamed Python tests to .py
r8449
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 assert 'mercurial.hgweb' not in sys.modules
Bryan O'Sullivan
test-demandimport: ensure that relative imports are deferred...
r27535 from mercurial import hgweb
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
if ispy3:
assert not isinstance(hgweb, _LazyModule)
assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
assert isinstance(hgweb.hgweb_mod, _LazyModule)
assert (
f(hgweb.hgweb_mod) == "<module 'mercurial.hgweb.hgweb_mod' from '?'>"
), f(hgweb.hgweb_mod)
else:
assert f(hgweb) == "<unloaded module 'hgweb'>", f(hgweb)
assert f(hgweb.hgweb_mod) == "<unloaded module 'hgweb_mod'>", f(
hgweb.hgweb_mod
)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
Bryan O'Sullivan
test-demandimport: ensure that relative imports are deferred...
r27535
Martin Geisler
tests: renamed Python tests to .py
r8449 import re as fred
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
if ispy3:
assert not isinstance(fred, _LazyModule)
assert f(fred) == "<module 're' from '?'>"
else:
assert f(fred) == "<unloaded module 're'>", f(fred)
Martin Geisler
tests: renamed Python tests to .py
r8449
Yuya Nishihara
demandimport: look for 'mod' suffix as alternative name for module reference...
r32447 import re as remod
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
if ispy3:
assert not isinstance(remod, _LazyModule)
assert f(remod) == "<module 're' from '?'>"
else:
assert f(remod) == "<unloaded module 're'>", f(remod)
Yuya Nishihara
demandimport: look for 'mod' suffix as alternative name for module reference...
r32447
Martin Geisler
tests: renamed Python tests to .py
r8449 import sys as re
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
if ispy3:
assert not isinstance(re, _LazyModule)
assert f(re) == "<module 'sys' (built-in)>"
else:
assert f(re) == "<unloaded module 'sys'>", f(re)
Martin Geisler
tests: renamed Python tests to .py
r8449
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 if ispy3:
assert not isinstance(fred, _LazyModule)
assert f(fred) == "<module 're' from '?'>", f(fred)
else:
assert f(fred) == "<unloaded module 're'>", f(fred)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 assert f(fred.sub) == '<function sub at 0x?>', f(fred.sub)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
if ispy3:
assert not isinstance(fred, _LazyModule)
assert f(fred) == "<module 're' from '?'>", f(fred)
else:
assert f(fred) == "<proxied module 're'>", f(fred)
Martin Geisler
tests: renamed Python tests to .py
r8449
Yuya Nishihara
demandimport: look for 'mod' suffix as alternative name for module reference...
r32447 remod.escape # use remod
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 assert f(remod) == "<module 're' from '?'>", f(remod)
Yuya Nishihara
demandimport: look for 'mod' suffix as alternative name for module reference...
r32447
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 if ispy3:
assert not isinstance(re, _LazyModule)
assert f(re) == "<module 'sys' (built-in)>"
assert f(type(re.stderr)) == "<class '_io.TextIOWrapper'>", f(
type(re.stderr)
)
assert f(re) == "<module 'sys' (built-in)>"
else:
assert f(re) == "<unloaded module 'sys'>", f(re)
assert f(re.stderr) == "<open file '<whatever>', mode 'w' at 0x?>", f(
re.stderr
)
assert f(re) == "<proxied module 'sys'>", f(re)
Mads Kiilerich
demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable...
r21025
Gregory Szorc
tests: use unimported modules in test-demandimport.py...
r41648 assert 'telnetlib' not in sys.modules
import telnetlib
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
if ispy3:
Gregory Szorc
tests: use unimported modules in test-demandimport.py...
r41648 assert not isinstance(telnetlib, _LazyModule)
assert f(telnetlib) == "<module 'telnetlib' from '?'>"
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 else:
Gregory Szorc
tests: use unimported modules in test-demandimport.py...
r41648 assert f(telnetlib) == "<unloaded module 'telnetlib'>", f(telnetlib)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
Yuya Nishihara
demandimport: error out early on missing attribute of non package (issue5373)...
r30022 try:
Gregory Szorc
tests: use unimported modules in test-demandimport.py...
r41648 from telnetlib import unknownattr
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646
assert False, (
'no demandmod should be created for attribute of non-package '
Gregory Szorc
tests: use unimported modules in test-demandimport.py...
r41648 'module:\ntelnetlib.unknownattr = %s' % f(unknownattr)
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 )
Yuya Nishihara
demandimport: error out early on missing attribute of non package (issue5373)...
r30022 except ImportError as inst:
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 assert rsub(r"'", '', str(inst)).startswith(
'cannot import name unknownattr'
)
Yuya Nishihara
demandimport: do not raise ImportError for unknown item in fromlist...
r30647
Matt Harbison
tests: migrate demandimport.py away from deprecated `util` module symbols
r37983 from mercurial import util
Yuya Nishihara
demandimport: do not raise ImportError for unknown item in fromlist...
r30647 # 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())
Gregory Szorc
tests: use unimported modules in test-demandimport.py...
r41648 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')