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