##// END OF EJS Templates
revlog: subclass the new `repository.iverifyproblem` Protocol class...
revlog: subclass the new `repository.iverifyproblem` Protocol class This is the same transformation as 3a90a6fd710d did for dirstate, but the CamelCase naming was already cleaned up here. We shouldn't have to explicitly subclass, but I'm doing so to test the interplay of regular attributes and the `attrs` class. Also, PyCharm has a nifty feature that puts a jump point in the gutter to navigate back and forth between the base class and subclasses (and override functions and base class functions) when there's an explicit subclassing. Additionally, PyCharm will immediately flag signature mismatches without a 40m pytype run.

File last commit:

r53006:b2e90465 merge default
r53365:4ef6dbc2 default
Show More
test-demandimport.py
184 lines | 5.2 KiB | text/x-python | PythonLexer
/ tests / test-demandimport.py
Martin Geisler
tests: renamed Python tests to .py
r8449 from mercurial import demandimport
Augie Fackler
formatting: blacken the codebase...
r43346
Martin Geisler
tests: renamed Python tests to .py
r8449 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.
av6
tests: os module is frozen in Python 3.11 (issue6786)
r50833 ispy311 = (sys.version_info.major, sys.version_info.minor) >= (3, 11)
timeless
tests: skip demandimport if disabled...
r29868
# Only run if demandimport is allowed
Augie Fackler
formatting: blacken the codebase...
r43346 if subprocess.call(
test: replace a many occurence of `python` with `$PYTHON`...
r46843 [os.environ['PYTHON'], '%s/hghave' % os.environ['TESTDIR'], 'demandimport']
Augie Fackler
formatting: blacken the codebase...
r43346 ):
timeless
tests: skip demandimport if disabled...
r29868 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
hgdemandimport: disable on Python 3.5...
r44576 # The demand importer doesn't work on Python 3.5.
if sys.version_info[0:2] == (3, 5):
sys.exit(80)
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 from importlib.util import _LazyModule
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 try:
from importlib.util import _Module as moduletype
except ImportError:
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 moduletype = types.ModuleType
Martin Geisler
tests: renamed Python tests to .py
r8449 import re
rsub = re.sub
Augie Fackler
formatting: blacken the codebase...
r43346
Martin Geisler
tests: renamed Python tests to .py
r8449 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
Augie Fackler
formatting: blacken the codebase...
r43346
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.
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(node, _LazyModule)
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
branching: merge with stable
r50867 assert isinstance(errorproxy, _LazyModule)
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(errorproxy, _LazyModule)
assert f(errorproxy) == "<module 'mercurial.error' from '?'>", 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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(os, _LazyModule)
branching: merge with stable
r50867 if ispy311:
assert f(os) == "<module 'os' (frozen)>", f(os)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647 else:
branching: merge with stable
r50867 assert f(os) == "<module 'os' from '?'>", f(os)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
Gregory Szorc
py3: replace print() with assert in test-demandimport.py...
r41646 assert f(os.system) == '<built-in function system>', f(os.system)
av6
tests: os module is frozen in Python 3.11 (issue6786)
r50833 if ispy311:
assert f(os) == "<module 'os' (frozen)>", f(os)
else:
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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert isinstance(procutil, _LazyModule)
assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
procutil
)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert 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
)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(fred, _LazyModule)
assert f(fred) == "<module 're' from '?'>"
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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(remod, _LazyModule)
assert f(remod) == "<module 're' from '?'>"
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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(re, _LazyModule)
assert f(re) == "<module 'sys' (built-in)>"
Martin Geisler
tests: renamed Python tests to .py
r8449
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(fred, _LazyModule)
assert f(fred) == "<module 're' from '?'>", f(fred)
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 assert not isinstance(fred, _LazyModule)
assert f(fred) == "<module 're' from '?'>", 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
Matt Harbison
tests: drop py2 support from test-demandimport.py
r50767 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)>"
Mads Kiilerich
demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable...
r21025
demande-import-test: use `wsgiref` instead of `telnetlib` for testing...
r52903 assert 'wsgiref' not in sys.modules
import wsgiref
Gregory Szorc
py3: conditionalize test-demandimport.py for Python 3...
r41647
demande-import-test: use `wsgiref` instead of `telnetlib` for testing...
r52903 assert isinstance(wsgiref, _LazyModule)
assert f(wsgiref) == "<module 'wsgiref' from '?'>"
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:
demande-import-test: use `wsgiref` instead of `telnetlib` for testing...
r52903 from wsgiref 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 '
demande-import-test: use `wsgiref` instead of `telnetlib` for testing...
r52903 'module:\nwsgiref.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
# 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())
Manuel Jacob
tests: fix test-demandimport.py on Python 3.9...
r45956 assert 'ftplib' not in sys.modules
zipfileimp = __import__('ftplib', globals(), locals(), ['unknownattr'])
assert f(zipfileimp) == "<module 'ftplib' from '?'>", f(zipfileimp)
safehasattr: drop usage in favor of hasattr...
r51821 assert not hasattr(zipfileimp, 'unknownattr')
Jason R. Coombs
demandimport: ensure lazyloaderex sets loader attributes (issue6725)...
r50483
# test deactivation for issue6725
demande-import-test: use `wsgiref` instead of `telnetlib` for testing...
r52903 del sys.modules['wsgiref']
Jason R. Coombs
demandimport: ensure lazyloaderex sets loader attributes (issue6725)...
r50483 with demandimport.deactivated():
demande-import-test: use `wsgiref` instead of `telnetlib` for testing...
r52903 import wsgiref
assert wsgiref.__loader__ == wsgiref.__spec__.loader
assert wsgiref.__loader__.get_resource_reader