Show More
@@ -1,225 +1,225 b'' | |||
|
1 | 1 | # Test that certain objects conform to well-defined interfaces. |
|
2 | 2 | |
|
3 | 3 | from __future__ import absolute_import, print_function |
|
4 | 4 | |
|
5 | 5 | from mercurial import encoding |
|
6 | 6 | encoding.environ[b'HGREALINTERFACES'] = b'1' |
|
7 | 7 | |
|
8 | 8 | import os |
|
9 | 9 | import subprocess |
|
10 | 10 | import sys |
|
11 | 11 | |
|
12 | 12 | # Only run if tests are run in a repo |
|
13 | 13 | if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
|
14 | 14 | 'test-repo']): |
|
15 | 15 | sys.exit(80) |
|
16 | 16 | |
|
17 | 17 | from mercurial.thirdparty.zope import ( |
|
18 | 18 | interface as zi, |
|
19 | 19 | ) |
|
20 | 20 | from mercurial.thirdparty.zope.interface import ( |
|
21 | 21 | verify as ziverify, |
|
22 | 22 | ) |
|
23 | 23 | from mercurial import ( |
|
24 | 24 | bundlerepo, |
|
25 | 25 | filelog, |
|
26 | 26 | httppeer, |
|
27 | 27 | localrepo, |
|
28 | 28 | manifest, |
|
29 | 29 | pycompat, |
|
30 | 30 | repository, |
|
31 | 31 | revlog, |
|
32 | 32 | sshpeer, |
|
33 | 33 | statichttprepo, |
|
34 | 34 | ui as uimod, |
|
35 | 35 | unionrepo, |
|
36 | 36 | vfs as vfsmod, |
|
37 | 37 | wireprotoserver, |
|
38 | 38 | wireprototypes, |
|
39 | 39 | wireprotov1peer, |
|
40 | 40 | wireprotov2server, |
|
41 | 41 | ) |
|
42 | 42 | |
|
43 | 43 | rootdir = pycompat.fsencode( |
|
44 | 44 | os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) |
|
45 | 45 | |
|
46 | 46 | def checkzobject(o, allowextra=False): |
|
47 | 47 | """Verify an object with a zope interface.""" |
|
48 | 48 | ifaces = zi.providedBy(o) |
|
49 | 49 | if not ifaces: |
|
50 | 50 | print('%r does not provide any zope interfaces' % o) |
|
51 | 51 | return |
|
52 | 52 | |
|
53 | 53 | # Run zope.interface's built-in verification routine. This verifies that |
|
54 | 54 | # everything that is supposed to be present is present. |
|
55 | 55 | for iface in ifaces: |
|
56 | 56 | ziverify.verifyObject(iface, o) |
|
57 | 57 | |
|
58 | 58 | if allowextra: |
|
59 | 59 | return |
|
60 | 60 | |
|
61 | 61 | # Now verify that the object provides no extra public attributes that |
|
62 | 62 | # aren't declared as part of interfaces. |
|
63 | 63 | allowed = set() |
|
64 | 64 | for iface in ifaces: |
|
65 | 65 | allowed |= set(iface.names(all=True)) |
|
66 | 66 | |
|
67 | 67 | public = {a for a in dir(o) if not a.startswith('_')} |
|
68 | 68 | |
|
69 | 69 | for attr in sorted(public - allowed): |
|
70 | 70 | print('public attribute not declared in interfaces: %s.%s' % ( |
|
71 | 71 | o.__class__.__name__, attr)) |
|
72 | 72 | |
|
73 | 73 | # Facilitates testing localpeer. |
|
74 | 74 | class dummyrepo(object): |
|
75 | 75 | def __init__(self): |
|
76 | 76 | self.ui = uimod.ui() |
|
77 | 77 | def filtered(self, name): |
|
78 | 78 | pass |
|
79 | 79 | def _restrictcapabilities(self, caps): |
|
80 | 80 | pass |
|
81 | 81 | |
|
82 | 82 | class dummyopener(object): |
|
83 | 83 | handlers = [] |
|
84 | 84 | |
|
85 | 85 | # Facilitates testing sshpeer without requiring a server. |
|
86 | 86 | class badpeer(httppeer.httppeer): |
|
87 | 87 | def __init__(self): |
|
88 | 88 | super(badpeer, self).__init__(None, None, None, dummyopener(), None, |
|
89 | 89 | None) |
|
90 | 90 | self.badattribute = True |
|
91 | 91 | |
|
92 | 92 | def badmethod(self): |
|
93 | 93 | pass |
|
94 | 94 | |
|
95 | 95 | class dummypipe(object): |
|
96 | 96 | def close(self): |
|
97 | 97 | pass |
|
98 | 98 | |
|
99 | 99 | def main(): |
|
100 | 100 | ui = uimod.ui() |
|
101 | 101 | # Needed so we can open a local repo with obsstore without a warning. |
|
102 | ui.setconfig('experimental', 'evolution.createmarkers', True) | |
|
102 | ui.setconfig(b'experimental', b'evolution.createmarkers', True) | |
|
103 | 103 | |
|
104 | 104 | checkzobject(badpeer()) |
|
105 | 105 | |
|
106 | 106 | ziverify.verifyClass(repository.ipeerbase, httppeer.httppeer) |
|
107 | 107 | checkzobject(httppeer.httppeer(None, None, None, dummyopener(), None, None)) |
|
108 | 108 | |
|
109 | 109 | ziverify.verifyClass(repository.ipeerconnection, |
|
110 | 110 | httppeer.httpv2peer) |
|
111 | 111 | ziverify.verifyClass(repository.ipeercapabilities, |
|
112 | 112 | httppeer.httpv2peer) |
|
113 | 113 | checkzobject(httppeer.httpv2peer(None, b'', b'', None, None, None)) |
|
114 | 114 | |
|
115 | 115 | ziverify.verifyClass(repository.ipeerbase, |
|
116 | 116 | localrepo.localpeer) |
|
117 | 117 | checkzobject(localrepo.localpeer(dummyrepo())) |
|
118 | 118 | |
|
119 | 119 | ziverify.verifyClass(repository.ipeercommandexecutor, |
|
120 | 120 | localrepo.localcommandexecutor) |
|
121 | 121 | checkzobject(localrepo.localcommandexecutor(None)) |
|
122 | 122 | |
|
123 | 123 | ziverify.verifyClass(repository.ipeercommandexecutor, |
|
124 | 124 | wireprotov1peer.peerexecutor) |
|
125 | 125 | checkzobject(wireprotov1peer.peerexecutor(None)) |
|
126 | 126 | |
|
127 | 127 | ziverify.verifyClass(repository.ipeerbase, sshpeer.sshv1peer) |
|
128 | 128 | checkzobject(sshpeer.sshv1peer(ui, b'ssh://localhost/foo', b'', dummypipe(), |
|
129 | 129 | dummypipe(), None, None)) |
|
130 | 130 | |
|
131 | 131 | ziverify.verifyClass(repository.ipeerbase, sshpeer.sshv2peer) |
|
132 | 132 | checkzobject(sshpeer.sshv2peer(ui, b'ssh://localhost/foo', b'', dummypipe(), |
|
133 | 133 | dummypipe(), None, None)) |
|
134 | 134 | |
|
135 | 135 | ziverify.verifyClass(repository.ipeerbase, bundlerepo.bundlepeer) |
|
136 | 136 | checkzobject(bundlerepo.bundlepeer(dummyrepo())) |
|
137 | 137 | |
|
138 | 138 | ziverify.verifyClass(repository.ipeerbase, statichttprepo.statichttppeer) |
|
139 | 139 | checkzobject(statichttprepo.statichttppeer(dummyrepo())) |
|
140 | 140 | |
|
141 | 141 | ziverify.verifyClass(repository.ipeerbase, unionrepo.unionpeer) |
|
142 | 142 | checkzobject(unionrepo.unionpeer(dummyrepo())) |
|
143 | 143 | |
|
144 | 144 | ziverify.verifyClass(repository.ilocalrepositorymain, |
|
145 | 145 | localrepo.localrepository) |
|
146 | 146 | ziverify.verifyClass(repository.ilocalrepositoryfilestorage, |
|
147 | 147 | localrepo.revlogfilestorage) |
|
148 | 148 | repo = localrepo.makelocalrepository(ui, rootdir) |
|
149 | 149 | checkzobject(repo) |
|
150 | 150 | |
|
151 | 151 | ziverify.verifyClass(wireprototypes.baseprotocolhandler, |
|
152 | 152 | wireprotoserver.sshv1protocolhandler) |
|
153 | 153 | ziverify.verifyClass(wireprototypes.baseprotocolhandler, |
|
154 | 154 | wireprotoserver.sshv2protocolhandler) |
|
155 | 155 | ziverify.verifyClass(wireprototypes.baseprotocolhandler, |
|
156 | 156 | wireprotoserver.httpv1protocolhandler) |
|
157 | 157 | ziverify.verifyClass(wireprototypes.baseprotocolhandler, |
|
158 | 158 | wireprotov2server.httpv2protocolhandler) |
|
159 | 159 | |
|
160 | 160 | sshv1 = wireprotoserver.sshv1protocolhandler(None, None, None) |
|
161 | 161 | checkzobject(sshv1) |
|
162 | 162 | sshv2 = wireprotoserver.sshv2protocolhandler(None, None, None) |
|
163 | 163 | checkzobject(sshv2) |
|
164 | 164 | |
|
165 | 165 | httpv1 = wireprotoserver.httpv1protocolhandler(None, None, None) |
|
166 | 166 | checkzobject(httpv1) |
|
167 | 167 | httpv2 = wireprotov2server.httpv2protocolhandler(None, None) |
|
168 | 168 | checkzobject(httpv2) |
|
169 | 169 | |
|
170 | 170 | ziverify.verifyClass(repository.ifilestorage, filelog.filelog) |
|
171 | 171 | ziverify.verifyClass(repository.imanifestdict, manifest.manifestdict) |
|
172 | 172 | ziverify.verifyClass(repository.imanifestrevisionstored, |
|
173 | 173 | manifest.manifestctx) |
|
174 | 174 | ziverify.verifyClass(repository.imanifestrevisionwritable, |
|
175 | 175 | manifest.memmanifestctx) |
|
176 | 176 | ziverify.verifyClass(repository.imanifestrevisionstored, |
|
177 | 177 | manifest.treemanifestctx) |
|
178 | 178 | ziverify.verifyClass(repository.imanifestrevisionwritable, |
|
179 | 179 | manifest.memtreemanifestctx) |
|
180 | 180 | ziverify.verifyClass(repository.imanifestlog, manifest.manifestlog) |
|
181 | 181 | ziverify.verifyClass(repository.imanifeststorage, manifest.manifestrevlog) |
|
182 | 182 | |
|
183 | 183 | vfs = vfsmod.vfs(b'.') |
|
184 | 184 | fl = filelog.filelog(vfs, b'dummy.i') |
|
185 | 185 | checkzobject(fl, allowextra=True) |
|
186 | 186 | |
|
187 | 187 | # Conforms to imanifestlog. |
|
188 | 188 | ml = manifest.manifestlog(vfs, repo, manifest.manifestrevlog(repo.svfs)) |
|
189 | 189 | checkzobject(ml) |
|
190 | 190 | checkzobject(repo.manifestlog) |
|
191 | 191 | |
|
192 | 192 | # Conforms to imanifestrevision. |
|
193 | 193 | mctx = ml[repo[0].manifestnode()] |
|
194 | 194 | checkzobject(mctx) |
|
195 | 195 | |
|
196 | 196 | # Conforms to imanifestrevisionwritable. |
|
197 | 197 | checkzobject(mctx.new()) |
|
198 | 198 | checkzobject(mctx.copy()) |
|
199 | 199 | |
|
200 | 200 | # Conforms to imanifestdict. |
|
201 | 201 | checkzobject(mctx.read()) |
|
202 | 202 | |
|
203 | 203 | mrl = manifest.manifestrevlog(vfs) |
|
204 | 204 | checkzobject(mrl) |
|
205 | 205 | |
|
206 | 206 | ziverify.verifyClass(repository.irevisiondelta, |
|
207 | 207 | revlog.revlogrevisiondelta) |
|
208 | 208 | |
|
209 | 209 | rd = revlog.revlogrevisiondelta( |
|
210 | 210 | node=b'', |
|
211 | 211 | p1node=b'', |
|
212 | 212 | p2node=b'', |
|
213 | 213 | basenode=b'', |
|
214 | 214 | linknode=b'', |
|
215 | 215 | flags=b'', |
|
216 | 216 | baserevisionsize=None, |
|
217 | 217 | revision=b'', |
|
218 | 218 | delta=None) |
|
219 | 219 | checkzobject(rd) |
|
220 | 220 | |
|
221 | 221 | ziverify.verifyClass(repository.iverifyproblem, |
|
222 | 222 | revlog.revlogproblem) |
|
223 | 223 | checkzobject(revlog.revlogproblem()) |
|
224 | 224 | |
|
225 | 225 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now