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