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