##// END OF EJS Templates
py3: add b'' prefixes in tests/test-linerange.py...
Pulkit Goyal -
r37601:6939b6ac default
parent child Browse files
Show More
@@ -1,232 +1,232 b''
1 1 from __future__ import absolute_import
2 2
3 3 import unittest
4 4 from mercurial import error, mdiff
5 5
6 6 # for readability, line numbers are 0-origin
7 text1 = '''
7 text1 = b'''
8 8 00 at OLD
9 9 01 at OLD
10 10 02 at OLD
11 11 02 at NEW, 03 at OLD
12 12 03 at NEW, 04 at OLD
13 13 04 at NEW, 05 at OLD
14 14 05 at NEW, 06 at OLD
15 15 07 at OLD
16 16 08 at OLD
17 17 09 at OLD
18 18 10 at OLD
19 19 11 at OLD
20 20 '''[1:] # strip initial LF
21 21
22 text2 = '''
22 text2 = b'''
23 23 00 at NEW
24 24 01 at NEW
25 25 02 at NEW, 03 at OLD
26 26 03 at NEW, 04 at OLD
27 27 04 at NEW, 05 at OLD
28 28 05 at NEW, 06 at OLD
29 29 06 at NEW
30 30 07 at NEW
31 31 08 at NEW
32 32 09 at NEW
33 33 10 at NEW
34 34 11 at NEW
35 35 '''[1:] # strip initial LF
36 36
37 37 def filteredblocks(blocks, rangeb):
38 38 """return `rangea` extracted from `blocks` coming from
39 39 `mdiff.blocksinrange` along with the mask of blocks within rangeb.
40 40 """
41 41 filtered, rangea = mdiff.blocksinrange(blocks, rangeb)
42 42 skipped = [b not in filtered for b in blocks]
43 43 return rangea, skipped
44 44
45 45 class blocksinrangetests(unittest.TestCase):
46 46
47 47 def setUp(self):
48 48 self.blocks = list(mdiff.allblocks(text1, text2))
49 49 assert self.blocks == [
50 ([0, 3, 0, 2], '!'),
51 ((3, 7, 2, 6), '='),
52 ([7, 12, 6, 12], '!'),
53 ((12, 12, 12, 12), '='),
50 ([0, 3, 0, 2], b'!'),
51 ((3, 7, 2, 6), b'='),
52 ([7, 12, 6, 12], b'!'),
53 ((12, 12, 12, 12), b'='),
54 54 ], self.blocks
55 55
56 56 def testWithinEqual(self):
57 57 """linerange within an "=" block"""
58 58 # IDX 0 1
59 59 # 012345678901
60 60 # SRC NNOOOONNNNNN (New/Old)
61 61 # ^^
62 62 linerange2 = (3, 5)
63 63 linerange1, skipped = filteredblocks(self.blocks, linerange2)
64 64 self.assertEqual(linerange1, (4, 6))
65 65 self.assertEqual(skipped, [True, False, True, True])
66 66
67 67 def testWithinEqualStrictly(self):
68 68 """linerange matching exactly an "=" block"""
69 69 # IDX 0 1
70 70 # 012345678901
71 71 # SRC NNOOOONNNNNN (New/Old)
72 72 # ^^^^
73 73 linerange2 = (2, 6)
74 74 linerange1, skipped = filteredblocks(self.blocks, linerange2)
75 75 self.assertEqual(linerange1, (3, 7))
76 76 self.assertEqual(skipped, [True, False, True, True])
77 77
78 78 def testWithinEqualLowerbound(self):
79 79 """linerange at beginning of an "=" block"""
80 80 # IDX 0 1
81 81 # 012345678901
82 82 # SRC NNOOOONNNNNN (New/Old)
83 83 # ^^
84 84 linerange2 = (2, 4)
85 85 linerange1, skipped = filteredblocks(self.blocks, linerange2)
86 86 self.assertEqual(linerange1, (3, 5))
87 87 self.assertEqual(skipped, [True, False, True, True])
88 88
89 89 def testWithinEqualLowerboundOneline(self):
90 90 """oneline-linerange at beginning of an "=" block"""
91 91 # IDX 0 1
92 92 # 012345678901
93 93 # SRC NNOOOONNNNNN (New/Old)
94 94 # ^
95 95 linerange2 = (2, 3)
96 96 linerange1, skipped = filteredblocks(self.blocks, linerange2)
97 97 self.assertEqual(linerange1, (3, 4))
98 98 self.assertEqual(skipped, [True, False, True, True])
99 99
100 100 def testWithinEqualUpperbound(self):
101 101 """linerange at end of an "=" block"""
102 102 # IDX 0 1
103 103 # 012345678901
104 104 # SRC NNOOOONNNNNN (New/Old)
105 105 # ^^^
106 106 linerange2 = (3, 6)
107 107 linerange1, skipped = filteredblocks(self.blocks, linerange2)
108 108 self.assertEqual(linerange1, (4, 7))
109 109 self.assertEqual(skipped, [True, False, True, True])
110 110
111 111 def testWithinEqualUpperboundOneLine(self):
112 112 """oneline-linerange at end of an "=" block"""
113 113 # IDX 0 1
114 114 # 012345678901
115 115 # SRC NNOOOONNNNNN (New/Old)
116 116 # ^
117 117 linerange2 = (5, 6)
118 118 linerange1, skipped = filteredblocks(self.blocks, linerange2)
119 119 self.assertEqual(linerange1, (6, 7))
120 120 self.assertEqual(skipped, [True, False, True, True])
121 121
122 122 def testWithinFirstBlockNeq(self):
123 123 """linerange within the first "!" block"""
124 124 # IDX 0 1
125 125 # 012345678901
126 126 # SRC NNOOOONNNNNN (New/Old)
127 127 # ^
128 128 # | (empty)
129 129 # ^
130 130 # ^^
131 131 for linerange2 in [
132 132 (0, 1),
133 133 (1, 1),
134 134 (1, 2),
135 135 (0, 2),
136 136 ]:
137 137 linerange1, skipped = filteredblocks(self.blocks, linerange2)
138 138 self.assertEqual(linerange1, (0, 3))
139 139 self.assertEqual(skipped, [False, True, True, True])
140 140
141 141 def testWithinLastBlockNeq(self):
142 142 """linerange within the last "!" block"""
143 143 # IDX 0 1
144 144 # 012345678901
145 145 # SRC NNOOOONNNNNN (New/Old)
146 146 # ^
147 147 # ^
148 148 # | (empty)
149 149 # ^^^^^^
150 150 # ^
151 151 for linerange2 in [
152 152 (6, 7),
153 153 (7, 8),
154 154 (7, 7),
155 155 (6, 12),
156 156 (11, 12),
157 157 ]:
158 158 linerange1, skipped = filteredblocks(self.blocks, linerange2)
159 159 self.assertEqual(linerange1, (7, 12))
160 160 self.assertEqual(skipped, [True, True, False, True])
161 161
162 162 def testAccrossTwoBlocks(self):
163 163 """linerange accross two blocks"""
164 164 # IDX 0 1
165 165 # 012345678901
166 166 # SRC NNOOOONNNNNN (New/Old)
167 167 # ^^^^
168 168 linerange2 = (1, 5)
169 169 linerange1, skipped = filteredblocks(self.blocks, linerange2)
170 170 self.assertEqual(linerange1, (0, 6))
171 171 self.assertEqual(skipped, [False, False, True, True])
172 172
173 173 def testCrossingSeveralBlocks(self):
174 174 """linerange accross three blocks"""
175 175 # IDX 0 1
176 176 # 012345678901
177 177 # SRC NNOOOONNNNNN (New/Old)
178 178 # ^^^^^^^
179 179 linerange2 = (1, 8)
180 180 linerange1, skipped = filteredblocks(self.blocks, linerange2)
181 181 self.assertEqual(linerange1, (0, 12))
182 182 self.assertEqual(skipped, [False, False, False, True])
183 183
184 184 def testStartInEqBlock(self):
185 185 """linerange starting in an "=" block"""
186 186 # IDX 0 1
187 187 # 012345678901
188 188 # SRC NNOOOONNNNNN (New/Old)
189 189 # ^^^^
190 190 # ^^^^^^^
191 191 for linerange2, expectedlinerange1 in [
192 192 ((5, 9), (6, 12)),
193 193 ((4, 11), (5, 12)),
194 194 ]:
195 195 linerange1, skipped = filteredblocks(self.blocks, linerange2)
196 196 self.assertEqual(linerange1, expectedlinerange1)
197 197 self.assertEqual(skipped, [True, False, False, True])
198 198
199 199 def testEndInEqBlock(self):
200 200 """linerange ending in an "=" block"""
201 201 # IDX 0 1
202 202 # 012345678901
203 203 # SRC NNOOOONNNNNN (New/Old)
204 204 # ^^
205 205 # ^^^^^
206 206 for linerange2, expectedlinerange1 in [
207 207 ((1, 3), (0, 4)),
208 208 ((0, 4), (0, 5)),
209 209 ]:
210 210 linerange1, skipped = filteredblocks(self.blocks, linerange2)
211 211 self.assertEqual(linerange1, expectedlinerange1)
212 212 self.assertEqual(skipped, [False, False, True, True])
213 213
214 214 def testOutOfRange(self):
215 215 """linerange exceeding file size"""
216 216 exctype = error.Abort
217 217 for linerange2 in [
218 218 (0, 34),
219 219 (15, 12),
220 220 ]:
221 221 # Could be `with self.assertRaises(error.Abort)` but python2.6
222 222 # does not have assertRaises context manager.
223 223 try:
224 224 mdiff.blocksinrange(self.blocks, linerange2)
225 225 except exctype as exc:
226 226 self.assertTrue('line range exceeds file size' in str(exc))
227 227 else:
228 228 self.fail('%s not raised' % exctype.__name__)
229 229
230 230 if __name__ == '__main__':
231 231 import silenttestrunner
232 232 silenttestrunner.main(__name__)
General Comments 0
You need to be logged in to leave comments. Login now