Mercurial > piecrust2
comparison tests/conftest.py @ 399:a0724af26c12
tests: More accurate marker position for diff'ing strings.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 18 May 2015 19:29:16 -0700 |
parents | af17c143b9ab |
children | e7b865f8f335 |
comparison
equal
deleted
inserted
replaced
398:af17c143b9ab | 399:a0724af26c12 |
---|---|
325 if left == right: | 325 if left == right: |
326 return None | 326 return None |
327 for i in range(min(len(left), len(right))): | 327 for i in range(min(len(left), len(right))): |
328 if left[i] != right[i]: | 328 if left[i] != right[i]: |
329 start = max(0, i - 15) | 329 start = max(0, i - 15) |
330 marker_offset = min(15, (i - start)) + 3 | 330 l_end = min(len(left), i + 15) |
331 | 331 r_end = min(len(right), i + 15) |
332 lend = min(len(left), i + 15) | 332 |
333 rend = min(len(right), i + 15) | 333 l_str = '' |
334 l_offset = 0 | |
335 for j in range(start, l_end): | |
336 c = repr(left[j]).strip("'") | |
337 l_str += c | |
338 if j < i: | |
339 l_offset += len(c) | |
340 | |
341 r_str = '' | |
342 r_offset = 0 | |
343 for j in range(start, r_end): | |
344 c = repr(right[j]).strip("'") | |
345 r_str += c | |
346 if j < i: | |
347 r_offset += len(c) | |
334 | 348 |
335 return ["Items '%s' differ at index %d:" % (path, i), '', | 349 return ["Items '%s' differ at index %d:" % (path, i), '', |
336 "Left:", left, '', | 350 "Left:", left, '', |
337 "Right:", right, '', | 351 "Right:", right, '', |
338 "Difference:", | 352 "Difference:", |
339 repr(left[start:lend]), | 353 l_str, (' ' * l_offset + '^'), |
340 (' ' * marker_offset + '^'), | 354 r_str, (' ' * r_offset + '^')] |
341 repr(right[start:rend]), | |
342 (' ' * marker_offset + '^')] | |
343 if len(left) > len(right): | 355 if len(left) > len(right): |
344 return ["Left is longer.", | 356 return ["Left is longer.", |
345 "Left '%s': " % path, left, | 357 "Left '%s': " % path, left, |
346 "Right '%s': " % path, right, | 358 "Right '%s': " % path, right, |
347 "Extra items: %r" % left[len(right):]] | 359 "Extra items: %r" % left[len(right):]] |