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