Show More
@@ -1,109 +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() |
|
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 | |||
|
45 | from mercurial import error as errorproxy | |||
|
46 | print("errorproxy =", f(errorproxy)) | |||
|
47 | print("errorproxy.__doc__ = %r" | |||
|
48 | % (' '.join(errorproxy.__doc__.split()[:3]) + ' ...')) | |||
|
49 | print("errorproxy.__name__ = %r" % errorproxy.__name__) | |||
|
50 | # __name__ must be accessible via __dict__ so the relative imports can be | |||
|
51 | # resolved | |||
|
52 | print("errorproxy.__dict__['__name__'] = %r" % errorproxy.__dict__['__name__']) | |||
|
53 | print("errorproxy =", f(errorproxy)) | |||
|
54 | ||||
44 | import os |
|
55 | import os | |
45 |
|
56 | |||
46 | print("os =", f(os)) |
|
57 | print("os =", f(os)) | |
47 | print("os.system =", f(os.system)) |
|
58 | print("os.system =", f(os.system)) | |
48 | print("os =", f(os)) |
|
59 | print("os =", f(os)) | |
49 |
|
60 | |||
50 | from mercurial import util |
|
61 | from mercurial import util | |
51 |
|
62 | |||
52 | print("util =", f(util)) |
|
63 | print("util =", f(util)) | |
53 | print("util.system =", f(util.system)) |
|
64 | print("util.system =", f(util.system)) | |
54 | print("util =", f(util)) |
|
65 | print("util =", f(util)) | |
55 | print("util.system =", f(util.system)) |
|
66 | print("util.system =", f(util.system)) | |
56 |
|
67 | |||
57 | from mercurial import hgweb |
|
68 | from mercurial import hgweb | |
58 | print("hgweb =", f(hgweb)) |
|
69 | print("hgweb =", f(hgweb)) | |
59 | print("hgweb_mod =", f(hgweb.hgweb_mod)) |
|
70 | print("hgweb_mod =", f(hgweb.hgweb_mod)) | |
60 | print("hgweb =", f(hgweb)) |
|
71 | print("hgweb =", f(hgweb)) | |
61 |
|
72 | |||
62 | import re as fred |
|
73 | import re as fred | |
63 | print("fred =", f(fred)) |
|
74 | print("fred =", f(fred)) | |
64 |
|
75 | |||
65 | import re as remod |
|
76 | import re as remod | |
66 | print("remod =", f(remod)) |
|
77 | print("remod =", f(remod)) | |
67 |
|
78 | |||
68 | import sys as re |
|
79 | import sys as re | |
69 | print("re =", f(re)) |
|
80 | print("re =", f(re)) | |
70 |
|
81 | |||
71 | print("fred =", f(fred)) |
|
82 | print("fred =", f(fred)) | |
72 | print("fred.sub =", f(fred.sub)) |
|
83 | print("fred.sub =", f(fred.sub)) | |
73 | print("fred =", f(fred)) |
|
84 | print("fred =", f(fred)) | |
74 |
|
85 | |||
75 | remod.escape # use remod |
|
86 | remod.escape # use remod | |
76 | print("remod =", f(remod)) |
|
87 | print("remod =", f(remod)) | |
77 |
|
88 | |||
78 | print("re =", f(re)) |
|
89 | print("re =", f(re)) | |
79 | print("re.stderr =", f(re.stderr)) |
|
90 | print("re.stderr =", f(re.stderr)) | |
80 | print("re =", f(re)) |
|
91 | print("re =", f(re)) | |
81 |
|
92 | |||
82 | # Test access to special attributes through demandmod proxy |
|
|||
83 | from mercurial import pvec as pvecproxy |
|
|||
84 | print("pvecproxy =", f(pvecproxy)) |
|
|||
85 | print("pvecproxy.__doc__ = %r" |
|
|||
86 | % (' '.join(pvecproxy.__doc__.split()[:3]) + ' ...')) |
|
|||
87 | print("pvecproxy.__name__ = %r" % pvecproxy.__name__) |
|
|||
88 | # __name__ must be accessible via __dict__ so the relative imports can be |
|
|||
89 | # resolved |
|
|||
90 | print("pvecproxy.__dict__['__name__'] = %r" % pvecproxy.__dict__['__name__']) |
|
|||
91 | print("pvecproxy =", f(pvecproxy)) |
|
|||
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 | # Unlike the import statement, __import__() function should not raise |
|
103 | # Unlike the import statement, __import__() function should not raise | |
104 | # ImportError even if fromlist has an unknown item |
|
104 | # ImportError even if fromlist has an unknown item | |
105 | # (see Python/import.c:import_module_level() and ensure_fromlist()) |
|
105 | # (see Python/import.c:import_module_level() and ensure_fromlist()) | |
106 | contextlibimp = __import__('contextlib', globals(), locals(), ['unknownattr']) |
|
106 | contextlibimp = __import__('contextlib', globals(), locals(), ['unknownattr']) | |
107 | print("__import__('contextlib', ..., ['unknownattr']) =", f(contextlibimp)) |
|
107 | print("__import__('contextlib', ..., ['unknownattr']) =", f(contextlibimp)) | |
108 | print("hasattr(contextlibimp, 'unknownattr') =", |
|
108 | print("hasattr(contextlibimp, 'unknownattr') =", | |
109 | util.safehasattr(contextlibimp, 'unknownattr')) |
|
109 | 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'> | |||
|
3 | errorproxy.__doc__ = 'Mercurial exceptions. This ...' | |||
|
4 | errorproxy.__name__ = 'mercurial.error' | |||
|
5 | errorproxy.__dict__['__name__'] = 'mercurial.error' | |||
|
6 | errorproxy = <proxied module 'error'> | |||
2 | os = <unloaded module 'os'> |
|
7 | os = <unloaded module 'os'> | |
3 | os.system = <built-in function system> |
|
8 | os.system = <built-in function system> | |
4 | os = <module 'os' from '?'> |
|
9 | os = <module 'os' from '?'> | |
5 | util = <unloaded module 'util'> |
|
10 | util = <unloaded module 'util'> | |
6 | util.system = <function system at 0x?> |
|
11 | util.system = <function system at 0x?> | |
7 | util = <module 'mercurial.util' from '?'> |
|
12 | util = <module 'mercurial.util' from '?'> | |
8 | util.system = <function system at 0x?> |
|
13 | util.system = <function system at 0x?> | |
9 | hgweb = <unloaded module 'hgweb'> |
|
14 | hgweb = <unloaded module 'hgweb'> | |
10 | hgweb_mod = <unloaded module 'hgweb_mod'> |
|
15 | hgweb_mod = <unloaded module 'hgweb_mod'> | |
11 | hgweb = <module 'mercurial.hgweb' from '?'> |
|
16 | hgweb = <module 'mercurial.hgweb' from '?'> | |
12 | fred = <unloaded module 're'> |
|
17 | fred = <unloaded module 're'> | |
13 | remod = <unloaded module 're'> |
|
18 | remod = <unloaded module 're'> | |
14 | re = <unloaded module 'sys'> |
|
19 | re = <unloaded module 'sys'> | |
15 | fred = <unloaded module 're'> |
|
20 | fred = <unloaded module 're'> | |
16 | fred.sub = <function sub at 0x?> |
|
21 | fred.sub = <function sub at 0x?> | |
17 | fred = <proxied module 're'> |
|
22 | fred = <proxied module 're'> | |
18 | remod = <module 're' from '?'> |
|
23 | remod = <module 're' from '?'> | |
19 | re = <unloaded module 'sys'> |
|
24 | re = <unloaded module 'sys'> | |
20 | re.stderr = <open file '<whatever>', mode 'w' at 0x?> |
|
25 | re.stderr = <open file '<whatever>', mode 'w' at 0x?> | |
21 | re = <proxied module 'sys'> |
|
26 | re = <proxied module 'sys'> | |
22 | pvecproxy = <unloaded module 'pvec'> |
|
|||
23 | pvecproxy.__doc__ = 'A "pvec" is ...' |
|
|||
24 | pvecproxy.__name__ = 'mercurial.pvec' |
|
|||
25 | pvecproxy.__dict__['__name__'] = 'mercurial.pvec' |
|
|||
26 | pvecproxy = <proxied module 'pvec'> |
|
|||
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