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