annotate tests/test-demandimport.py @ 53040:cdd7bf612c7b stable tip

bundle-spec: properly format boolean parameter (issue6960) This was breaking automatic clone bundle generation. This changeset fixes it and add a test to catch it in the future.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 11 Mar 2025 02:29:42 +0100
parents b2e90465daf6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
1 from mercurial import demandimport
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41521
diff changeset
2
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
3 demandimport.enable()
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
4
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
5 import os
29872
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
6 import subprocess
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
7 import sys
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
8 import types
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
9
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
10 # Don't import pycompat because it has too many side-effects.
49636
643312047e44 tests: os module is frozen in Python 3.11 (issue6786)
Anton Shestakov <av6@dwimlabs.net>
parents: 48966
diff changeset
11 ispy311 = (sys.version_info.major, sys.version_info.minor) >= (3, 11)
29872
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
12
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
13 # Only run if demandimport is allowed
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41521
diff changeset
14 if subprocess.call(
46226
0826d684a1b5 test: replace a many occurence of `python` with `$PYTHON`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45211
diff changeset
15 [os.environ['PYTHON'], '%s/hghave' % os.environ['TESTDIR'], 'demandimport']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41521
diff changeset
16 ):
29872
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
17 sys.exit(80)
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
18
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
19 # We rely on assert, which gets optimized out.
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
20 if sys.flags.optimize:
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
21 sys.exit(80)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
22
44117
c5e0a9b97b8a hgdemandimport: disable on Python 3.5
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
23 # The demand importer doesn't work on Python 3.5.
c5e0a9b97b8a hgdemandimport: disable on Python 3.5
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
24 if sys.version_info[0:2] == (3, 5):
c5e0a9b97b8a hgdemandimport: disable on Python 3.5
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
25 sys.exit(80)
c5e0a9b97b8a hgdemandimport: disable on Python 3.5
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
26
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
27 from importlib.util import _LazyModule
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
28
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
29 try:
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
30 from importlib.util import _Module as moduletype
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
31 except ImportError:
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
32 moduletype = types.ModuleType
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
33
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
34 import re
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
35
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
36 rsub = re.sub
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41521
diff changeset
37
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41521
diff changeset
38
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
39 def f(obj):
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
40 l = repr(obj)
4802
3a4310e8fe72 test-demandimport: match upper-case hexadecimal
Patrick Mezard <pmezard@gmail.com>
parents: 4631
diff changeset
41 l = rsub("0x[0-9a-fA-F]+", "0x?", l)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
42 l = rsub("from '.*'", "from '?'", l)
13083
c0290fc6b486 test-demandimport.py: PyPy support
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 12865
diff changeset
43 l = rsub("'<[a-z]*>'", "'<whatever>'", l)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
44 return l
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
45
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41521
diff changeset
46
36274
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
47 demandimport.disable()
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
48 os.environ['HGDEMANDIMPORT'] = 'disable'
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
49 # this enable call should not actually enable demandimport!
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
50 demandimport.enable()
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
51 from mercurial import node
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
52
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
53 # We use assert instead of a unittest test case because having imports inside
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
54 # functions changes behavior of the demand importer.
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
55 assert not isinstance(node, _LazyModule)
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
56
36274
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
57 # now enable it for real
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
58 del os.environ['HGDEMANDIMPORT']
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
59 demandimport.enable()
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33936
diff changeset
60
36284
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36274
diff changeset
61 # Test access to special attributes through demandmod proxy
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
62 assert 'mercurial.error' not in sys.modules
36284
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36274
diff changeset
63 from mercurial import error as errorproxy
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
64
50030
1bd33932713d branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49951 49637
diff changeset
65 assert isinstance(errorproxy, _LazyModule)
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
66 assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
67
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
68 doc = ' '.join(errorproxy.__doc__.split()[:3])
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
69 assert doc == 'Mercurial exceptions. This', doc
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
70 assert errorproxy.__name__ == 'mercurial.error', errorproxy.__name__
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
71
36284
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36274
diff changeset
72 # __name__ must be accessible via __dict__ so the relative imports can be
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36274
diff changeset
73 # resolved
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
74 name = errorproxy.__dict__['__name__']
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
75 assert name == 'mercurial.error', name
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
76
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
77 assert not isinstance(errorproxy, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
78 assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
36284
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36274
diff changeset
79
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
80 import os
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
81
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
82 assert not isinstance(os, _LazyModule)
50030
1bd33932713d branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49951 49637
diff changeset
83 if ispy311:
1bd33932713d branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49951 49637
diff changeset
84 assert f(os) == "<module 'os' (frozen)>", f(os)
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
85 else:
50030
1bd33932713d branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49951 49637
diff changeset
86 assert f(os) == "<module 'os' from '?'>", f(os)
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
87
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
88 assert f(os.system) == '<built-in function system>', f(os.system)
49636
643312047e44 tests: os module is frozen in Python 3.11 (issue6786)
Anton Shestakov <av6@dwimlabs.net>
parents: 48966
diff changeset
89 if ispy311:
643312047e44 tests: os module is frozen in Python 3.11 (issue6786)
Anton Shestakov <av6@dwimlabs.net>
parents: 48966
diff changeset
90 assert f(os) == "<module 'os' (frozen)>", f(os)
643312047e44 tests: os module is frozen in Python 3.11 (issue6786)
Anton Shestakov <av6@dwimlabs.net>
parents: 48966
diff changeset
91 else:
643312047e44 tests: os module is frozen in Python 3.11 (issue6786)
Anton Shestakov <av6@dwimlabs.net>
parents: 48966
diff changeset
92 assert f(os) == "<module 'os' from '?'>", f(os)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
93
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
94 assert 'mercurial.utils.procutil' not in sys.modules
38008
1d0610fdd63b tests: migrate demandimport.py away from deprecated `util` module symbols
Matt Harbison <matt_harbison@yahoo.com>
parents: 36284
diff changeset
95 from mercurial.utils import procutil
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
96
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
97 assert isinstance(procutil, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
98 assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
99 procutil
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
100 )
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
101
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
102 assert f(procutil.system) == '<function system at 0x?>', f(procutil.system)
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
103 assert procutil.__class__ == moduletype, procutil.__class__
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
104 assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
105 procutil
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
106 )
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
107 assert f(procutil.system) == '<function system at 0x?>', f(procutil.system)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
108
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
109 assert 'mercurial.hgweb' not in sys.modules
27535
0d0f4070f6d7 test-demandimport: ensure that relative imports are deferred
Bryan O'Sullivan <bos@serpentine.com>
parents: 23643
diff changeset
110 from mercurial import hgweb
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
111
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
112 assert isinstance(hgweb, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
113 assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
114 assert isinstance(hgweb.hgweb_mod, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
115 assert f(hgweb.hgweb_mod) == "<module 'mercurial.hgweb.hgweb_mod' from '?'>", f(
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
116 hgweb.hgweb_mod
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
117 )
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
118
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
119 assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
27535
0d0f4070f6d7 test-demandimport: ensure that relative imports are deferred
Bryan O'Sullivan <bos@serpentine.com>
parents: 23643
diff changeset
120
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
121 import re as fred
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
122
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
123 assert not isinstance(fred, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
124 assert f(fred) == "<module 're' from '?'>"
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
125
32485
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30261
diff changeset
126 import re as remod
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
127
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
128 assert not isinstance(remod, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
129 assert f(remod) == "<module 're' from '?'>"
32485
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30261
diff changeset
130
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
131 import sys as re
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
132
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
133 assert not isinstance(re, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
134 assert f(re) == "<module 'sys' (built-in)>"
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
135
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
136 assert not isinstance(fred, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
137 assert f(fred) == "<module 're' from '?'>", f(fred)
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
138
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
139 assert f(fred.sub) == '<function sub at 0x?>', f(fred.sub)
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
140
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
141 assert not isinstance(fred, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
142 assert f(fred) == "<module 're' from '?'>", f(fred)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
143
32485
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30261
diff changeset
144 remod.escape # use remod
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
145 assert f(remod) == "<module 're' from '?'>", f(remod)
32485
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30261
diff changeset
146
49951
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
147 assert not isinstance(re, _LazyModule)
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
148 assert f(re) == "<module 'sys' (built-in)>"
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
149 assert f(type(re.stderr)) == "<class '_io.TextIOWrapper'>", f(type(re.stderr))
ecde742a5a9d tests: drop py2 support from test-demandimport.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 49729
diff changeset
150 assert f(re) == "<module 'sys' (built-in)>"
21025
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
151
51695
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
152 assert 'wsgiref' not in sys.modules
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
153 import wsgiref
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
154
51695
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
155 assert isinstance(wsgiref, _LazyModule)
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
156 assert f(wsgiref) == "<module 'wsgiref' from '?'>"
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
157
30024
26a4e46af2bc demandimport: error out early on missing attribute of non package (issue5373)
Yuya Nishihara <yuya@tcha.org>
parents: 29985
diff changeset
158 try:
51695
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
159 from wsgiref import unknownattr
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
160
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
161 assert False, (
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
162 'no demandmod should be created for attribute of non-package '
51695
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
163 'module:\nwsgiref.unknownattr = %s' % f(unknownattr)
41519
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38008
diff changeset
164 )
30024
26a4e46af2bc demandimport: error out early on missing attribute of non package (issue5373)
Yuya Nishihara <yuya@tcha.org>
parents: 29985
diff changeset
165 except ImportError as inst:
41520
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
166 assert rsub(r"'", '', str(inst)).startswith(
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
167 'cannot import name unknownattr'
3e89736b98ce py3: conditionalize test-demandimport.py for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41519
diff changeset
168 )
30261
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30024
diff changeset
169
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30024
diff changeset
170 # Unlike the import statement, __import__() function should not raise
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30024
diff changeset
171 # ImportError even if fromlist has an unknown item
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30024
diff changeset
172 # (see Python/import.c:import_module_level() and ensure_fromlist())
45211
fc8299319ffe tests: fix test-demandimport.py on Python 3.9
Manuel Jacob <me@manueljacob.de>
parents: 44118
diff changeset
173 assert 'ftplib' not in sys.modules
fc8299319ffe tests: fix test-demandimport.py on Python 3.9
Manuel Jacob <me@manueljacob.de>
parents: 44118
diff changeset
174 zipfileimp = __import__('ftplib', globals(), locals(), ['unknownattr'])
fc8299319ffe tests: fix test-demandimport.py on Python 3.9
Manuel Jacob <me@manueljacob.de>
parents: 44118
diff changeset
175 assert f(zipfileimp) == "<module 'ftplib' from '?'>", f(zipfileimp)
50951
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50030
diff changeset
176 assert not hasattr(zipfileimp, 'unknownattr')
49729
7236f11db0c3 demandimport: ensure lazyloaderex sets loader attributes (issue6725)
Jason R. Coombs <jaraco@jaraco.com>
parents: 48966
diff changeset
177
7236f11db0c3 demandimport: ensure lazyloaderex sets loader attributes (issue6725)
Jason R. Coombs <jaraco@jaraco.com>
parents: 48966
diff changeset
178
7236f11db0c3 demandimport: ensure lazyloaderex sets loader attributes (issue6725)
Jason R. Coombs <jaraco@jaraco.com>
parents: 48966
diff changeset
179 # test deactivation for issue6725
51695
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
180 del sys.modules['wsgiref']
49729
7236f11db0c3 demandimport: ensure lazyloaderex sets loader attributes (issue6725)
Jason R. Coombs <jaraco@jaraco.com>
parents: 48966
diff changeset
181 with demandimport.deactivated():
51695
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
182 import wsgiref
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
183 assert wsgiref.__loader__ == wsgiref.__spec__.loader
37f693975cbc demande-import-test: use `wsgiref` instead of `telnetlib` for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50951
diff changeset
184 assert wsgiref.__loader__.get_resource_reader