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