##// END OF EJS Templates
bdiff-torture: fix pyflakes warning reporting undefined name 'inst'...
Pulkit Goyal -
r43123:3316e59b default
parent child Browse files
Show More
@@ -1,99 +1,98 b''
1 # Randomized torture test generation for bdiff
1 # Randomized torture test generation for bdiff
2
2
3 from __future__ import absolute_import, print_function
3 from __future__ import absolute_import, print_function
4 import random
4 import random
5 import sys
5 import sys
6
6
7 from mercurial import (
7 from mercurial import (
8 mdiff,
8 mdiff,
9 )
9 )
10
10
11 def reducetest(a, b):
11 def reducetest(a, b):
12 tries = 0
12 tries = 0
13 reductions = 0
13 reductions = 0
14 print("reducing...")
14 print("reducing...")
15 while tries < 1000:
15 while tries < 1000:
16 a2 = "\n".join(l for l in a.splitlines()
16 a2 = "\n".join(l for l in a.splitlines()
17 if random.randint(0, 100) > 0) + "\n"
17 if random.randint(0, 100) > 0) + "\n"
18 b2 = "\n".join(l for l in b.splitlines()
18 b2 = "\n".join(l for l in b.splitlines()
19 if random.randint(0, 100) > 0) + "\n"
19 if random.randint(0, 100) > 0) + "\n"
20 if a2 == a and b2 == b:
20 if a2 == a and b2 == b:
21 continue
21 continue
22 if a2 == b2:
22 if a2 == b2:
23 continue
23 continue
24 tries += 1
24 tries += 1
25
25
26 try:
26 try:
27 test1(a, b)
27 test1(a, b)
28 except Exception:
28 except Exception:
29 reductions += 1
29 reductions += 1
30 tries = 0
30 tries = 0
31 a = a2
31 a = a2
32 b = b2
32 b = b2
33
33
34 print("reduced:", reductions, len(a) + len(b),
34 print("reduced:", reductions, len(a) + len(b),
35 repr(a), repr(b))
35 repr(a), repr(b))
36 try:
36 try:
37 test1(a, b)
37 test1(a, b)
38 except Exception as inst:
38 except Exception as inst:
39 print("failed:", inst)
39 print("failed:", inst)
40
40
41 sys.exit(0)
41 sys.exit(0)
42
42
43 def test1(a, b):
43 def test1(a, b):
44 d = mdiff.textdiff(a, b)
44 d = mdiff.textdiff(a, b)
45 if not d:
45 if not d:
46 raise ValueError("empty")
46 raise ValueError("empty")
47 c = mdiff.patches(a, [d])
47 c = mdiff.patches(a, [d])
48 if c != b:
48 if c != b:
49 raise ValueError("bad")
49 raise ValueError("bad")
50
50
51 def testwrap(a, b):
51 def testwrap(a, b):
52 try:
52 try:
53 test1(a, b)
53 test1(a, b)
54 return
54 return
55 except Exception as inst:
55 except Exception as inst:
56 pass
56 print("exception:", inst)
57 print("exception:", inst)
58 reducetest(a, b)
57 reducetest(a, b)
59
58
60 def test(a, b):
59 def test(a, b):
61 testwrap(a, b)
60 testwrap(a, b)
62 testwrap(b, a)
61 testwrap(b, a)
63
62
64 def rndtest(size, noise):
63 def rndtest(size, noise):
65 a = []
64 a = []
66 src = " aaaaaaaabbbbccd"
65 src = " aaaaaaaabbbbccd"
67 for x in xrange(size):
66 for x in xrange(size):
68 a.append(src[random.randint(0, len(src) - 1)])
67 a.append(src[random.randint(0, len(src) - 1)])
69
68
70 while True:
69 while True:
71 b = [c for c in a if random.randint(0, 99) > noise]
70 b = [c for c in a if random.randint(0, 99) > noise]
72 b2 = []
71 b2 = []
73 for c in b:
72 for c in b:
74 b2.append(c)
73 b2.append(c)
75 while random.randint(0, 99) < noise:
74 while random.randint(0, 99) < noise:
76 b2.append(src[random.randint(0, len(src) - 1)])
75 b2.append(src[random.randint(0, len(src) - 1)])
77 if b2 != a:
76 if b2 != a:
78 break
77 break
79
78
80 a = "\n".join(a) + "\n"
79 a = "\n".join(a) + "\n"
81 b = "\n".join(b2) + "\n"
80 b = "\n".join(b2) + "\n"
82
81
83 test(a, b)
82 test(a, b)
84
83
85 maxvol = 10000
84 maxvol = 10000
86 startsize = 2
85 startsize = 2
87 while True:
86 while True:
88 size = startsize
87 size = startsize
89 count = 0
88 count = 0
90 while size < maxvol:
89 while size < maxvol:
91 print(size)
90 print(size)
92 volume = 0
91 volume = 0
93 while volume < maxvol:
92 while volume < maxvol:
94 rndtest(size, 2)
93 rndtest(size, 2)
95 volume += size
94 volume += size
96 count += 2
95 count += 2
97 size *= 2
96 size *= 2
98 maxvol *= 4
97 maxvol *= 4
99 startsize *= 4
98 startsize *= 4
General Comments 0
You need to be logged in to leave comments. Login now