##// END OF EJS Templates
tests: make test-pathencode use print_function
Pulkit Goyal -
r28918:72f68326 default
parent child Browse files
Show More
@@ -1,202 +1,201
1 1 #require test-repo
2 2
3 3 $ cd "$TESTDIR"/..
4 4
5 5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 6 doc/check-seclevel.py not using absolute_import
7 7 doc/gendoc.py not using absolute_import
8 8 doc/hgmanpage.py not using absolute_import
9 9 hgext/color.py not using absolute_import
10 10 hgext/eol.py not using absolute_import
11 11 hgext/extdiff.py not using absolute_import
12 12 hgext/factotum.py not using absolute_import
13 13 hgext/fetch.py not using absolute_import
14 14 hgext/fsmonitor/pywatchman/__init__.py not using absolute_import
15 15 hgext/fsmonitor/pywatchman/__init__.py requires print_function
16 16 hgext/fsmonitor/pywatchman/capabilities.py not using absolute_import
17 17 hgext/fsmonitor/pywatchman/pybser.py not using absolute_import
18 18 hgext/gpg.py not using absolute_import
19 19 hgext/graphlog.py not using absolute_import
20 20 hgext/hgcia.py not using absolute_import
21 21 hgext/hgk.py not using absolute_import
22 22 hgext/highlight/__init__.py not using absolute_import
23 23 hgext/highlight/highlight.py not using absolute_import
24 24 hgext/histedit.py not using absolute_import
25 25 hgext/largefiles/__init__.py not using absolute_import
26 26 hgext/largefiles/basestore.py not using absolute_import
27 27 hgext/largefiles/lfcommands.py not using absolute_import
28 28 hgext/largefiles/lfutil.py not using absolute_import
29 29 hgext/largefiles/localstore.py not using absolute_import
30 30 hgext/largefiles/overrides.py not using absolute_import
31 31 hgext/largefiles/proto.py not using absolute_import
32 32 hgext/largefiles/remotestore.py not using absolute_import
33 33 hgext/largefiles/reposetup.py not using absolute_import
34 34 hgext/largefiles/uisetup.py not using absolute_import
35 35 hgext/largefiles/wirestore.py not using absolute_import
36 36 hgext/mq.py not using absolute_import
37 37 hgext/rebase.py not using absolute_import
38 38 hgext/share.py not using absolute_import
39 39 hgext/win32text.py not using absolute_import
40 40 i18n/check-translation.py not using absolute_import
41 41 i18n/polib.py not using absolute_import
42 42 setup.py not using absolute_import
43 43 tests/heredoctest.py requires print_function
44 44 tests/killdaemons.py not using absolute_import
45 45 tests/md5sum.py not using absolute_import
46 46 tests/mockblackbox.py not using absolute_import
47 47 tests/printenv.py not using absolute_import
48 48 tests/readlink.py not using absolute_import
49 49 tests/readlink.py requires print_function
50 50 tests/revlog-formatv0.py not using absolute_import
51 51 tests/run-tests.py not using absolute_import
52 52 tests/sitecustomize.py not using absolute_import
53 53 tests/svn-safe-append.py not using absolute_import
54 54 tests/svnxml.py not using absolute_import
55 55 tests/test-atomictempfile.py not using absolute_import
56 56 tests/test-demandimport.py not using absolute_import
57 57 tests/test-demandimport.py requires print_function
58 58 tests/test-doctest.py not using absolute_import
59 59 tests/test-hgwebdir-paths.py not using absolute_import
60 60 tests/test-lrucachedict.py not using absolute_import
61 61 tests/test-lrucachedict.py requires print_function
62 62 tests/test-manifest.py not using absolute_import
63 63 tests/test-pathencode.py not using absolute_import
64 tests/test-pathencode.py requires print_function
65 64 tests/test-simplemerge.py not using absolute_import
66 65 tests/test-trusted.py requires print_function
67 66
68 67 #if py3exe
69 68 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py
70 69 contrib/check-code.py: invalid syntax: (unicode error) 'unicodeescape' codec can't decode bytes in position *-*: malformed \N character escape (<unknown>, line *) (glob)
71 70 doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
72 71 hgext/automv.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
73 72 hgext/blackbox.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
74 73 hgext/bugzilla.py: error importing module: <ImportError> No module named 'urlparse' (line *) (glob)
75 74 hgext/censor.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
76 75 hgext/chgserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
77 76 hgext/children.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
78 77 hgext/churn.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
79 78 hgext/clonebundles.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
80 79 hgext/color.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
81 80 hgext/convert/bzr.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
82 81 hgext/convert/common.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
83 82 hgext/convert/convcmd.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
84 83 hgext/convert/cvs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
85 84 hgext/convert/cvsps.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
86 85 hgext/convert/darcs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
87 86 hgext/convert/filemap.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
88 87 hgext/convert/git.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
89 88 hgext/convert/gnuarch.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
90 89 hgext/convert/hg.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
91 90 hgext/convert/monotone.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
92 91 hgext/convert/p*.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
93 92 hgext/convert/subversion.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
94 93 hgext/convert/transport.py: error importing module: <ImportError> No module named 'svn.client' (line *) (glob)
95 94 hgext/eol.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
96 95 hgext/extdiff.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
97 96 hgext/factotum.py: error importing: <ImportError> No module named 'httplib' (error at url.py:*) (glob)
98 97 hgext/fetch.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
99 98 hgext/fsmonitor/watchmanclient.py: error importing module: <SystemError> Parent module 'hgext.fsmonitor' not loaded, cannot perform relative import (line *) (glob)
100 99 hgext/gpg.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
101 100 hgext/graphlog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
102 101 hgext/hgcia.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
103 102 hgext/hgk.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
104 103 hgext/histedit.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
105 104 hgext/keyword.py: error importing: <ImportError> No module named 'BaseHTTPServer' (error at common.py:*) (glob)
106 105 hgext/largefiles/basestore.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
107 106 hgext/largefiles/lfcommands.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
108 107 hgext/largefiles/lfutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
109 108 hgext/largefiles/localstore.py: error importing module: <ImportError> No module named 'lfutil' (line *) (glob)
110 109 hgext/largefiles/overrides.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
111 110 hgext/largefiles/proto.py: error importing: <ImportError> No module named 'httplib' (error at httppeer.py:*) (glob)
112 111 hgext/largefiles/remotestore.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at wireproto.py:*) (glob)
113 112 hgext/largefiles/reposetup.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
114 113 hgext/largefiles/uisetup.py: error importing module: <SyntaxError> invalid syntax (archival.py, line *) (line *) (glob)
115 114 hgext/largefiles/wirestore.py: error importing module: <ImportError> No module named 'lfutil' (line *) (glob)
116 115 hgext/mq.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
117 116 hgext/notify.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
118 117 hgext/pager.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
119 118 hgext/patchbomb.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
120 119 hgext/purge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
121 120 hgext/rebase.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
122 121 hgext/record.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
123 122 hgext/relink.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
124 123 hgext/schemes.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
125 124 hgext/share.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
126 125 hgext/shelve.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
127 126 hgext/strip.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
128 127 hgext/transplant.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
129 128 mercurial/archival.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
130 129 mercurial/branchmap.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
131 130 mercurial/bundle*.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
132 131 mercurial/bundlerepo.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
133 132 mercurial/changegroup.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
134 133 mercurial/changelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
135 134 mercurial/cmdutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
136 135 mercurial/commands.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
137 136 mercurial/commandserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
138 137 mercurial/context.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
139 138 mercurial/copies.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
140 139 mercurial/crecord.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
141 140 mercurial/dirstate.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
142 141 mercurial/discovery.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
143 142 mercurial/dispatch.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
144 143 mercurial/exchange.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
145 144 mercurial/extensions.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
146 145 mercurial/filelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
147 146 mercurial/filemerge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
148 147 mercurial/fileset.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
149 148 mercurial/formatter.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
150 149 mercurial/graphmod.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
151 150 mercurial/help.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
152 151 mercurial/hg.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
153 152 mercurial/hgweb/common.py: error importing module: <ImportError> No module named 'BaseHTTPServer' (line *) (glob)
154 153 mercurial/hgweb/hgweb_mod.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
155 154 mercurial/hgweb/hgwebdir_mod.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
156 155 mercurial/hgweb/protocol.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
157 156 mercurial/hgweb/request.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
158 157 mercurial/hgweb/server.py: error importing module: <ImportError> No module named 'BaseHTTPServer' (line *) (glob)
159 158 mercurial/hgweb/webcommands.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
160 159 mercurial/hgweb/webutil.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
161 160 mercurial/hgweb/wsgicgi.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
162 161 mercurial/hook.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
163 162 mercurial/httpclient/_readers.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
164 163 mercurial/httpconnection.py: error importing: <ImportError> No module named 'httplib' (error at __init__.py:*) (glob)
165 164 mercurial/httppeer.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
166 165 mercurial/keepalive.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
167 166 mercurial/localrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
168 167 mercurial/mail.py: error importing module: <AttributeError> module 'email' has no attribute 'Header' (line *) (glob)
169 168 mercurial/manifest.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
170 169 mercurial/merge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
171 170 mercurial/namespaces.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
172 171 mercurial/patch.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
173 172 mercurial/pure/mpatch.py: error importing module: <ImportError> cannot import name 'pycompat' (line *) (glob)
174 173 mercurial/pure/parsers.py: error importing module: <ImportError> No module named 'mercurial.pure.node' (line *) (glob)
175 174 mercurial/repair.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
176 175 mercurial/revlog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
177 176 mercurial/revset.py: error importing module: <AttributeError> 'dict' object has no attribute 'iteritems' (line *) (glob)
178 177 mercurial/scmutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
179 178 mercurial/scmwindows.py: error importing module: <ImportError> No module named '_winreg' (line *) (glob)
180 179 mercurial/simplemerge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
181 180 mercurial/sshpeer.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at wireproto.py:*) (glob)
182 181 mercurial/sshserver.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
183 182 mercurial/statichttprepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
184 183 mercurial/store.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
185 184 mercurial/streamclone.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
186 185 mercurial/subrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
187 186 mercurial/templatefilters.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
188 187 mercurial/templatekw.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
189 188 mercurial/templater.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
190 189 mercurial/ui.py: error importing: <ImportError> No module named 'cPickle' (error at formatter.py:*) (glob)
191 190 mercurial/unionrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
192 191 mercurial/url.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
193 192 mercurial/verify.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
194 193 mercurial/win*.py: error importing module: <ImportError> No module named 'msvcrt' (line *) (glob)
195 194 mercurial/windows.py: error importing module: <ImportError> No module named '_winreg' (line *) (glob)
196 195 mercurial/wireproto.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
197 196 tests/readlink.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
198 197 tests/test-demandimport.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
199 198 tests/test-lrucachedict.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
200 199 tests/test-trusted.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
201 200
202 201 #endif
@@ -1,194 +1,196
1 1 # This is a randomized test that generates different pathnames every
2 2 # time it is invoked, and tests the encoding of those pathnames.
3 3 #
4 4 # It uses a simple probabilistic model to generate valid pathnames
5 5 # that have proven likely to expose bugs and divergent behavior in
6 6 # different encoding implementations.
7 7
8 from __future__ import print_function
9
8 10 from mercurial import store
9 11 import binascii, itertools, math, os, random, sys, time
10 12 import collections
11 13
12 14 validchars = set(map(chr, range(0, 256)))
13 15 alphanum = range(ord('A'), ord('Z'))
14 16
15 17 for c in '\0/':
16 18 validchars.remove(c)
17 19
18 20 winreserved = ('aux con prn nul'.split() +
19 21 ['com%d' % i for i in xrange(1, 10)] +
20 22 ['lpt%d' % i for i in xrange(1, 10)])
21 23
22 24 def casecombinations(names):
23 25 '''Build all case-diddled combinations of names.'''
24 26
25 27 combos = set()
26 28
27 29 for r in names:
28 30 for i in xrange(len(r) + 1):
29 31 for c in itertools.combinations(xrange(len(r)), i):
30 32 d = r
31 33 for j in c:
32 34 d = ''.join((d[:j], d[j].upper(), d[j + 1:]))
33 35 combos.add(d)
34 36 return sorted(combos)
35 37
36 38 def buildprobtable(fp, cmd='hg manifest tip'):
37 39 '''Construct and print a table of probabilities for path name
38 40 components. The numbers are percentages.'''
39 41
40 42 counts = collections.defaultdict(lambda: 0)
41 43 for line in os.popen(cmd).read().splitlines():
42 44 if line[-2:] in ('.i', '.d'):
43 45 line = line[:-2]
44 46 if line.startswith('data/'):
45 47 line = line[5:]
46 48 for c in line:
47 49 counts[c] += 1
48 50 for c in '\r/\n':
49 51 counts.pop(c, None)
50 52 t = sum(counts.itervalues()) / 100.0
51 53 fp.write('probtable = (')
52 54 for i, (k, v) in enumerate(sorted(counts.iteritems(), key=lambda x: x[1],
53 55 reverse=True)):
54 56 if (i % 5) == 0:
55 57 fp.write('\n ')
56 58 vt = v / t
57 59 if vt < 0.0005:
58 60 break
59 61 fp.write('(%r, %.03f), ' % (k, vt))
60 62 fp.write('\n )\n')
61 63
62 64 # A table of character frequencies (as percentages), gleaned by
63 65 # looking at filelog names from a real-world, very large repo.
64 66
65 67 probtable = (
66 68 ('t', 9.828), ('e', 9.042), ('s', 8.011), ('a', 6.801), ('i', 6.618),
67 69 ('g', 5.053), ('r', 5.030), ('o', 4.887), ('p', 4.363), ('n', 4.258),
68 70 ('l', 3.830), ('h', 3.693), ('_', 3.659), ('.', 3.377), ('m', 3.194),
69 71 ('u', 2.364), ('d', 2.296), ('c', 2.163), ('b', 1.739), ('f', 1.625),
70 72 ('6', 0.666), ('j', 0.610), ('y', 0.554), ('x', 0.487), ('w', 0.477),
71 73 ('k', 0.476), ('v', 0.473), ('3', 0.336), ('1', 0.335), ('2', 0.326),
72 74 ('4', 0.310), ('5', 0.305), ('9', 0.302), ('8', 0.300), ('7', 0.299),
73 75 ('q', 0.298), ('0', 0.250), ('z', 0.223), ('-', 0.118), ('C', 0.095),
74 76 ('T', 0.087), ('F', 0.085), ('B', 0.077), ('S', 0.076), ('P', 0.076),
75 77 ('L', 0.059), ('A', 0.058), ('N', 0.051), ('D', 0.049), ('M', 0.046),
76 78 ('E', 0.039), ('I', 0.035), ('R', 0.035), ('G', 0.028), ('U', 0.026),
77 79 ('W', 0.025), ('O', 0.017), ('V', 0.015), ('H', 0.013), ('Q', 0.011),
78 80 ('J', 0.007), ('K', 0.005), ('+', 0.004), ('X', 0.003), ('Y', 0.001),
79 81 )
80 82
81 83 for c, _ in probtable:
82 84 validchars.remove(c)
83 85 validchars = list(validchars)
84 86
85 87 def pickfrom(rng, table):
86 88 c = 0
87 89 r = rng.random() * sum(i[1] for i in table)
88 90 for i, p in table:
89 91 c += p
90 92 if c >= r:
91 93 return i
92 94
93 95 reservedcombos = casecombinations(winreserved)
94 96
95 97 # The first component of a name following a slash.
96 98
97 99 firsttable = (
98 100 (lambda rng: pickfrom(rng, probtable), 90),
99 101 (lambda rng: rng.choice(validchars), 5),
100 102 (lambda rng: rng.choice(reservedcombos), 5),
101 103 )
102 104
103 105 # Components of a name following the first.
104 106
105 107 resttable = firsttable[:-1]
106 108
107 109 # Special suffixes.
108 110
109 111 internalsuffixcombos = casecombinations('.hg .i .d'.split())
110 112
111 113 # The last component of a path, before a slash or at the end of a name.
112 114
113 115 lasttable = resttable + (
114 116 (lambda rng: '', 95),
115 117 (lambda rng: rng.choice(internalsuffixcombos), 5),
116 118 )
117 119
118 120 def makepart(rng, k):
119 121 '''Construct a part of a pathname, without slashes.'''
120 122
121 123 p = pickfrom(rng, firsttable)(rng)
122 124 l = len(p)
123 125 ps = [p]
124 126 maxl = rng.randint(1, k)
125 127 while l < maxl:
126 128 p = pickfrom(rng, resttable)(rng)
127 129 l += len(p)
128 130 ps.append(p)
129 131 ps.append(pickfrom(rng, lasttable)(rng))
130 132 return ''.join(ps)
131 133
132 134 def makepath(rng, j, k):
133 135 '''Construct a complete pathname.'''
134 136
135 137 return ('data/' + '/'.join(makepart(rng, k) for _ in xrange(j)) +
136 138 rng.choice(['.d', '.i']))
137 139
138 140 def genpath(rng, count):
139 141 '''Generate random pathnames with gradually increasing lengths.'''
140 142
141 143 mink, maxk = 1, 4096
142 144 def steps():
143 145 for i in xrange(count):
144 146 yield mink + int(round(math.sqrt((maxk - mink) * float(i) / count)))
145 147 for k in steps():
146 148 x = rng.randint(1, k)
147 149 y = rng.randint(1, k)
148 150 yield makepath(rng, x, y)
149 151
150 152 def runtests(rng, seed, count):
151 153 nerrs = 0
152 154 for p in genpath(rng, count):
153 155 h = store._pathencode(p) # uses C implementation, if available
154 156 r = store._hybridencode(p, True) # reference implementation in Python
155 157 if h != r:
156 158 if nerrs == 0:
157 print >> sys.stderr, 'seed:', hex(seed)[:-1]
158 print >> sys.stderr, "\np: '%s'" % p.encode("string_escape")
159 print >> sys.stderr, "h: '%s'" % h.encode("string_escape")
160 print >> sys.stderr, "r: '%s'" % r.encode("string_escape")
159 print('seed:', hex(seed)[:-1], file=sys.stderr)
160 print("\np: '%s'" % p.encode("string_escape"), file=sys.stderr)
161 print("h: '%s'" % h.encode("string_escape"), file=sys.stderr)
162 print("r: '%s'" % r.encode("string_escape"), file=sys.stderr)
161 163 nerrs += 1
162 164 return nerrs
163 165
164 166 def main():
165 167 import getopt
166 168
167 169 # Empirically observed to take about a second to run
168 170 count = 100
169 171 seed = None
170 172 opts, args = getopt.getopt(sys.argv[1:], 'c:s:',
171 173 ['build', 'count=', 'seed='])
172 174 for o, a in opts:
173 175 if o in ('-c', '--count'):
174 176 count = int(a)
175 177 elif o in ('-s', '--seed'):
176 178 seed = long(a, base=0) # accepts base 10 or 16 strings
177 179 elif o == '--build':
178 180 buildprobtable(sys.stdout,
179 181 'find .hg/store/data -type f && '
180 182 'cat .hg/store/fncache 2>/dev/null')
181 183 sys.exit(0)
182 184
183 185 if seed is None:
184 186 try:
185 187 seed = long(binascii.hexlify(os.urandom(16)), 16)
186 188 except AttributeError:
187 189 seed = long(time.time() * 1000)
188 190
189 191 rng = random.Random(seed)
190 192 if runtests(rng, seed, count):
191 193 sys.exit(1)
192 194
193 195 if __name__ == '__main__':
194 196 main()
General Comments 0
You need to be logged in to leave comments. Login now