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