##// END OF EJS Templates
tests: port test-pathencode.py to Python 3...
Augie Fackler -
r37897:1b230e19 default
parent child Browse files
Show More
@@ -315,6 +315,7 test-obsolete-tag-cache.t
315 315 test-parents.t
316 316 test-pathconflicts-merge.t
317 317 test-pathconflicts-update.t
318 test-pathencode.py
318 319 test-pending.t
319 320 test-permissions.t
320 321 test-phases.t
@@ -16,6 +16,7 import random
16 16 import sys
17 17 import time
18 18 from mercurial import (
19 pycompat,
19 20 store,
20 21 )
21 22
@@ -24,15 +25,15 try:
24 25 except NameError:
25 26 xrange = range
26 27
27 validchars = set(map(chr, range(0, 256)))
28 validchars = set(map(pycompat.bytechr, range(0, 256)))
28 29 alphanum = range(ord('A'), ord('Z'))
29 30
30 for c in '\0/':
31 for c in (b'\0', b'/'):
31 32 validchars.remove(c)
32 33
33 winreserved = ('aux con prn nul'.split() +
34 ['com%d' % i for i in xrange(1, 10)] +
35 ['lpt%d' % i for i in xrange(1, 10)])
34 winreserved = (b'aux con prn nul'.split() +
35 [b'com%d' % i for i in xrange(1, 10)] +
36 [b'lpt%d' % i for i in xrange(1, 10)])
36 37
37 38 def casecombinations(names):
38 39 '''Build all case-diddled combinations of names.'''
@@ -44,7 +45,7 def casecombinations(names):
44 45 for c in itertools.combinations(xrange(len(r)), i):
45 46 d = r
46 47 for j in c:
47 d = ''.join((d[:j], d[j].upper(), d[j + 1:]))
48 d = b''.join((d[:j], d[j:j + 1].upper(), d[j + 1:]))
48 49 combos.add(d)
49 50 return sorted(combos)
50 51
@@ -78,19 +79,19 def buildprobtable(fp, cmd='hg manifest
78 79 # looking at filelog names from a real-world, very large repo.
79 80
80 81 probtable = (
81 ('t', 9.828), ('e', 9.042), ('s', 8.011), ('a', 6.801), ('i', 6.618),
82 ('g', 5.053), ('r', 5.030), ('o', 4.887), ('p', 4.363), ('n', 4.258),
83 ('l', 3.830), ('h', 3.693), ('_', 3.659), ('.', 3.377), ('m', 3.194),
84 ('u', 2.364), ('d', 2.296), ('c', 2.163), ('b', 1.739), ('f', 1.625),
85 ('6', 0.666), ('j', 0.610), ('y', 0.554), ('x', 0.487), ('w', 0.477),
86 ('k', 0.476), ('v', 0.473), ('3', 0.336), ('1', 0.335), ('2', 0.326),
87 ('4', 0.310), ('5', 0.305), ('9', 0.302), ('8', 0.300), ('7', 0.299),
88 ('q', 0.298), ('0', 0.250), ('z', 0.223), ('-', 0.118), ('C', 0.095),
89 ('T', 0.087), ('F', 0.085), ('B', 0.077), ('S', 0.076), ('P', 0.076),
90 ('L', 0.059), ('A', 0.058), ('N', 0.051), ('D', 0.049), ('M', 0.046),
91 ('E', 0.039), ('I', 0.035), ('R', 0.035), ('G', 0.028), ('U', 0.026),
92 ('W', 0.025), ('O', 0.017), ('V', 0.015), ('H', 0.013), ('Q', 0.011),
93 ('J', 0.007), ('K', 0.005), ('+', 0.004), ('X', 0.003), ('Y', 0.001),
82 (b't', 9.828), (b'e', 9.042), (b's', 8.011), (b'a', 6.801), (b'i', 6.618),
83 (b'g', 5.053), (b'r', 5.030), (b'o', 4.887), (b'p', 4.363), (b'n', 4.258),
84 (b'l', 3.830), (b'h', 3.693), (b'_', 3.659), (b'.', 3.377), (b'm', 3.194),
85 (b'u', 2.364), (b'd', 2.296), (b'c', 2.163), (b'b', 1.739), (b'f', 1.625),
86 (b'6', 0.666), (b'j', 0.610), (b'y', 0.554), (b'x', 0.487), (b'w', 0.477),
87 (b'k', 0.476), (b'v', 0.473), (b'3', 0.336), (b'1', 0.335), (b'2', 0.326),
88 (b'4', 0.310), (b'5', 0.305), (b'9', 0.302), (b'8', 0.300), (b'7', 0.299),
89 (b'q', 0.298), (b'0', 0.250), (b'z', 0.223), (b'-', 0.118), (b'C', 0.095),
90 (b'T', 0.087), (b'F', 0.085), (b'B', 0.077), (b'S', 0.076), (b'P', 0.076),
91 (b'L', 0.059), (b'A', 0.058), (b'N', 0.051), (b'D', 0.049), (b'M', 0.046),
92 (b'E', 0.039), (b'I', 0.035), (b'R', 0.035), (b'G', 0.028), (b'U', 0.026),
93 (b'W', 0.025), (b'O', 0.017), (b'V', 0.015), (b'H', 0.013), (b'Q', 0.011),
94 (b'J', 0.007), (b'K', 0.005), (b'+', 0.004), (b'X', 0.003), (b'Y', 0.001),
94 95 )
95 96
96 97 for c, _ in probtable:
@@ -121,12 +122,12 resttable = firsttable[:-1]
121 122
122 123 # Special suffixes.
123 124
124 internalsuffixcombos = casecombinations('.hg .i .d'.split())
125 internalsuffixcombos = casecombinations(b'.hg .i .d'.split())
125 126
126 127 # The last component of a path, before a slash or at the end of a name.
127 128
128 129 lasttable = resttable + (
129 (lambda rng: '', 95),
130 (lambda rng: b'', 95),
130 131 (lambda rng: rng.choice(internalsuffixcombos), 5),
131 132 )
132 133
@@ -142,13 +143,13 def makepart(rng, k):
142 143 l += len(p)
143 144 ps.append(p)
144 145 ps.append(pickfrom(rng, lasttable)(rng))
145 return ''.join(ps)
146 return b''.join(ps)
146 147
147 148 def makepath(rng, j, k):
148 149 '''Construct a complete pathname.'''
149 150
150 return ('data/' + '/'.join(makepart(rng, k) for _ in xrange(j)) +
151 rng.choice(['.d', '.i']))
151 return (b'data/' + b'/'.join(makepart(rng, k) for _ in xrange(j)) +
152 rng.choice([b'.d', b'.i']))
152 153
153 154 def genpath(rng, count):
154 155 '''Generate random pathnames with gradually increasing lengths.'''
General Comments 0
You need to be logged in to leave comments. Login now