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