Show More
@@ -1,106 +1,109 b'' | |||||
1 | from __future__ import absolute_import, print_function |
|
1 | from __future__ import absolute_import, print_function | |
2 |
|
2 | |||
3 | from mercurial import demandimport |
|
3 | from mercurial import demandimport | |
4 | demandimport.enable() |
|
4 | demandimport.enable() | |
5 |
|
5 | |||
6 | import os |
|
6 | import os | |
7 | import subprocess |
|
7 | import subprocess | |
8 | import sys |
|
8 | import sys | |
9 |
|
9 | |||
10 | # Only run if demandimport is allowed |
|
10 | # Only run if demandimport is allowed | |
11 | if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
|
11 | if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], | |
12 | 'demandimport']): |
|
12 | 'demandimport']): | |
13 | sys.exit(80) |
|
13 | sys.exit(80) | |
14 |
|
14 | |||
15 | if os.name != 'nt': |
|
15 | if os.name != 'nt': | |
16 | try: |
|
16 | try: | |
17 | import distutils.msvc9compiler |
|
17 | import distutils.msvc9compiler | |
18 | print('distutils.msvc9compiler needs to be an immediate ' |
|
18 | print('distutils.msvc9compiler needs to be an immediate ' | |
19 | 'importerror on non-windows platforms') |
|
19 | 'importerror on non-windows platforms') | |
20 | distutils.msvc9compiler |
|
20 | distutils.msvc9compiler | |
21 | except ImportError: |
|
21 | except ImportError: | |
22 | pass |
|
22 | pass | |
23 |
|
23 | |||
24 | import re |
|
24 | import re | |
25 |
|
25 | |||
26 | rsub = re.sub |
|
26 | rsub = re.sub | |
27 | def f(obj): |
|
27 | def f(obj): | |
28 | l = repr(obj) |
|
28 | l = repr(obj) | |
29 | l = rsub("0x[0-9a-fA-F]+", "0x?", l) |
|
29 | l = rsub("0x[0-9a-fA-F]+", "0x?", l) | |
30 | l = rsub("from '.*'", "from '?'", l) |
|
30 | l = rsub("from '.*'", "from '?'", l) | |
31 | l = rsub("'<[a-z]*>'", "'<whatever>'", l) |
|
31 | l = rsub("'<[a-z]*>'", "'<whatever>'", l) | |
32 | return l |
|
32 | return l | |
33 |
|
33 | |||
|
34 | demandimport.disable() | |||
|
35 | os.environ['HGDEMANDIMPORT'] = 'disable' | |||
|
36 | # this enable call should not actually enable demandimport! | |||
|
37 | demandimport.enable() | |||
|
38 | from mercurial import node | |||
|
39 | print("node =", f(node)) | |||
|
40 | # now enable it for real | |||
|
41 | del os.environ['HGDEMANDIMPORT'] | |||
|
42 | demandimport.enable() | |||
|
43 | ||||
34 | import os |
|
44 | import os | |
35 |
|
45 | |||
36 | print("os =", f(os)) |
|
46 | print("os =", f(os)) | |
37 | print("os.system =", f(os.system)) |
|
47 | print("os.system =", f(os.system)) | |
38 | print("os =", f(os)) |
|
48 | print("os =", f(os)) | |
39 |
|
49 | |||
40 | from mercurial import util |
|
50 | from mercurial import util | |
41 |
|
51 | |||
42 | print("util =", f(util)) |
|
52 | print("util =", f(util)) | |
43 | print("util.system =", f(util.system)) |
|
53 | print("util.system =", f(util.system)) | |
44 | print("util =", f(util)) |
|
54 | print("util =", f(util)) | |
45 | print("util.system =", f(util.system)) |
|
55 | print("util.system =", f(util.system)) | |
46 |
|
56 | |||
47 | from mercurial import hgweb |
|
57 | from mercurial import hgweb | |
48 | print("hgweb =", f(hgweb)) |
|
58 | print("hgweb =", f(hgweb)) | |
49 | print("hgweb_mod =", f(hgweb.hgweb_mod)) |
|
59 | print("hgweb_mod =", f(hgweb.hgweb_mod)) | |
50 | print("hgweb =", f(hgweb)) |
|
60 | print("hgweb =", f(hgweb)) | |
51 |
|
61 | |||
52 | import re as fred |
|
62 | import re as fred | |
53 | print("fred =", f(fred)) |
|
63 | print("fred =", f(fred)) | |
54 |
|
64 | |||
55 | import re as remod |
|
65 | import re as remod | |
56 | print("remod =", f(remod)) |
|
66 | print("remod =", f(remod)) | |
57 |
|
67 | |||
58 | import sys as re |
|
68 | import sys as re | |
59 | print("re =", f(re)) |
|
69 | print("re =", f(re)) | |
60 |
|
70 | |||
61 | print("fred =", f(fred)) |
|
71 | print("fred =", f(fred)) | |
62 | print("fred.sub =", f(fred.sub)) |
|
72 | print("fred.sub =", f(fred.sub)) | |
63 | print("fred =", f(fred)) |
|
73 | print("fred =", f(fred)) | |
64 |
|
74 | |||
65 | remod.escape # use remod |
|
75 | remod.escape # use remod | |
66 | print("remod =", f(remod)) |
|
76 | print("remod =", f(remod)) | |
67 |
|
77 | |||
68 | print("re =", f(re)) |
|
78 | print("re =", f(re)) | |
69 | print("re.stderr =", f(re.stderr)) |
|
79 | print("re.stderr =", f(re.stderr)) | |
70 | print("re =", f(re)) |
|
80 | print("re =", f(re)) | |
71 |
|
81 | |||
72 | # Test access to special attributes through demandmod proxy |
|
82 | # Test access to special attributes through demandmod proxy | |
73 | from mercurial import pvec as pvecproxy |
|
83 | from mercurial import pvec as pvecproxy | |
74 | print("pvecproxy =", f(pvecproxy)) |
|
84 | print("pvecproxy =", f(pvecproxy)) | |
75 | print("pvecproxy.__doc__ = %r" |
|
85 | print("pvecproxy.__doc__ = %r" | |
76 | % (' '.join(pvecproxy.__doc__.split()[:3]) + ' ...')) |
|
86 | % (' '.join(pvecproxy.__doc__.split()[:3]) + ' ...')) | |
77 | print("pvecproxy.__name__ = %r" % pvecproxy.__name__) |
|
87 | print("pvecproxy.__name__ = %r" % pvecproxy.__name__) | |
78 | # __name__ must be accessible via __dict__ so the relative imports can be |
|
88 | # __name__ must be accessible via __dict__ so the relative imports can be | |
79 | # resolved |
|
89 | # resolved | |
80 | print("pvecproxy.__dict__['__name__'] = %r" % pvecproxy.__dict__['__name__']) |
|
90 | print("pvecproxy.__dict__['__name__'] = %r" % pvecproxy.__dict__['__name__']) | |
81 | print("pvecproxy =", f(pvecproxy)) |
|
91 | print("pvecproxy =", f(pvecproxy)) | |
82 |
|
92 | |||
83 | import contextlib |
|
93 | import contextlib | |
84 | print("contextlib =", f(contextlib)) |
|
94 | print("contextlib =", f(contextlib)) | |
85 | try: |
|
95 | try: | |
86 | from contextlib import unknownattr |
|
96 | from contextlib import unknownattr | |
87 | print('no demandmod should be created for attribute of non-package ' |
|
97 | print('no demandmod should be created for attribute of non-package ' | |
88 | 'module:\ncontextlib.unknownattr =', f(unknownattr)) |
|
98 | 'module:\ncontextlib.unknownattr =', f(unknownattr)) | |
89 | except ImportError as inst: |
|
99 | except ImportError as inst: | |
90 | print('contextlib.unknownattr = ImportError: %s' |
|
100 | print('contextlib.unknownattr = ImportError: %s' | |
91 | % rsub(r"'", '', str(inst))) |
|
101 | % rsub(r"'", '', str(inst))) | |
92 |
|
102 | |||
93 | # Unlike the import statement, __import__() function should not raise |
|
103 | # Unlike the import statement, __import__() function should not raise | |
94 | # ImportError even if fromlist has an unknown item |
|
104 | # ImportError even if fromlist has an unknown item | |
95 | # (see Python/import.c:import_module_level() and ensure_fromlist()) |
|
105 | # (see Python/import.c:import_module_level() and ensure_fromlist()) | |
96 | contextlibimp = __import__('contextlib', globals(), locals(), ['unknownattr']) |
|
106 | contextlibimp = __import__('contextlib', globals(), locals(), ['unknownattr']) | |
97 | print("__import__('contextlib', ..., ['unknownattr']) =", f(contextlibimp)) |
|
107 | print("__import__('contextlib', ..., ['unknownattr']) =", f(contextlibimp)) | |
98 | print("hasattr(contextlibimp, 'unknownattr') =", |
|
108 | print("hasattr(contextlibimp, 'unknownattr') =", | |
99 | util.safehasattr(contextlibimp, 'unknownattr')) |
|
109 | util.safehasattr(contextlibimp, 'unknownattr')) | |
100 |
|
||||
101 | demandimport.disable() |
|
|||
102 | os.environ['HGDEMANDIMPORT'] = 'disable' |
|
|||
103 | # this enable call should not actually enable demandimport! |
|
|||
104 | demandimport.enable() |
|
|||
105 | from mercurial import node |
|
|||
106 | print("node =", f(node)) |
|
@@ -1,30 +1,30 b'' | |||||
|
1 | node = <module 'mercurial.node' from '?'> | |||
1 | os = <unloaded module 'os'> |
|
2 | os = <unloaded module 'os'> | |
2 | os.system = <built-in function system> |
|
3 | os.system = <built-in function system> | |
3 | os = <module 'os' from '?'> |
|
4 | os = <module 'os' from '?'> | |
4 | util = <unloaded module 'util'> |
|
5 | util = <unloaded module 'util'> | |
5 | util.system = <function system at 0x?> |
|
6 | util.system = <function system at 0x?> | |
6 | util = <module 'mercurial.util' from '?'> |
|
7 | util = <module 'mercurial.util' from '?'> | |
7 | util.system = <function system at 0x?> |
|
8 | util.system = <function system at 0x?> | |
8 | hgweb = <unloaded module 'hgweb'> |
|
9 | hgweb = <unloaded module 'hgweb'> | |
9 | hgweb_mod = <unloaded module 'hgweb_mod'> |
|
10 | hgweb_mod = <unloaded module 'hgweb_mod'> | |
10 | hgweb = <module 'mercurial.hgweb' from '?'> |
|
11 | hgweb = <module 'mercurial.hgweb' from '?'> | |
11 | fred = <unloaded module 're'> |
|
12 | fred = <unloaded module 're'> | |
12 | remod = <unloaded module 're'> |
|
13 | remod = <unloaded module 're'> | |
13 | re = <unloaded module 'sys'> |
|
14 | re = <unloaded module 'sys'> | |
14 | fred = <unloaded module 're'> |
|
15 | fred = <unloaded module 're'> | |
15 | fred.sub = <function sub at 0x?> |
|
16 | fred.sub = <function sub at 0x?> | |
16 | fred = <proxied module 're'> |
|
17 | fred = <proxied module 're'> | |
17 | remod = <module 're' from '?'> |
|
18 | remod = <module 're' from '?'> | |
18 | re = <unloaded module 'sys'> |
|
19 | re = <unloaded module 'sys'> | |
19 | re.stderr = <open file '<whatever>', mode 'w' at 0x?> |
|
20 | re.stderr = <open file '<whatever>', mode 'w' at 0x?> | |
20 | re = <proxied module 'sys'> |
|
21 | re = <proxied module 'sys'> | |
21 | pvecproxy = <unloaded module 'pvec'> |
|
22 | pvecproxy = <unloaded module 'pvec'> | |
22 | pvecproxy.__doc__ = 'A "pvec" is ...' |
|
23 | pvecproxy.__doc__ = 'A "pvec" is ...' | |
23 | pvecproxy.__name__ = 'mercurial.pvec' |
|
24 | pvecproxy.__name__ = 'mercurial.pvec' | |
24 | pvecproxy.__dict__['__name__'] = 'mercurial.pvec' |
|
25 | pvecproxy.__dict__['__name__'] = 'mercurial.pvec' | |
25 | pvecproxy = <proxied module 'pvec'> |
|
26 | pvecproxy = <proxied module 'pvec'> | |
26 | contextlib = <unloaded module 'contextlib'> |
|
27 | contextlib = <unloaded module 'contextlib'> | |
27 | contextlib.unknownattr = ImportError: cannot import name unknownattr |
|
28 | contextlib.unknownattr = ImportError: cannot import name unknownattr | |
28 | __import__('contextlib', ..., ['unknownattr']) = <module 'contextlib' from '?'> |
|
29 | __import__('contextlib', ..., ['unknownattr']) = <module 'contextlib' from '?'> | |
29 | hasattr(contextlibimp, 'unknownattr') = False |
|
30 | hasattr(contextlibimp, 'unknownattr') = False | |
30 | node = <module 'mercurial.node' from '?'> |
|
General Comments 0
You need to be logged in to leave comments.
Login now