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