Mercurial > piecrust2
comparison tests/conftest.py @ 665:5dc13c816045
tests: Fix logic for making time-based tests not fail randomly.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 03 Mar 2016 08:19:28 -0800 |
parents | 1eda551ee681 |
children | 81d9c3a3a0b5 |
comparison
equal
deleted
inserted
replaced
664:8da29a497f61 | 665:5dc13c816045 |
---|---|
460 left = (left[:i] + test_time_iso8601 + | 460 left = (left[:i] + test_time_iso8601 + |
461 left[i + len(test_time_iso8601_pattern):]) | 461 left[i + len(test_time_iso8601_pattern):]) |
462 else: | 462 else: |
463 break | 463 break |
464 | 464 |
465 skip_for = -1 | |
465 for i in range(min(len(left), len(right))): | 466 for i in range(min(len(left), len(right))): |
467 if skip_for > 0: | |
468 skip_for -= 1 | |
469 continue | |
470 | |
466 if i in left_time_indices: | 471 if i in left_time_indices: |
467 # This is where the time starts. Let's compare that the time | 472 # This is where the time starts. Let's compare that the time |
468 # values are within a few seconds of each other (usually 0 or 1). | 473 # values are within a few seconds of each other (usually 0 or 1). |
469 right_time_str = right[i:i + len(test_time_iso8601)] | 474 right_time_str = right[i:i + len(test_time_iso8601)] |
470 right_time = time.strptime(right_time_str, '%Y-%m-%dT%H:%M:%SZ') | 475 right_time = time.strptime(right_time_str, '%Y-%m-%dT%H:%M:%SZ') |
471 left_time = time.gmtime(ctx.time) | 476 left_time = time.gmtime(ctx.time) |
472 difference = time.mktime(left_time) - time.mktime(right_time) | 477 difference = time.mktime(left_time) - time.mktime(right_time) |
473 print("Got time difference: %d" % difference) | 478 print("Got time difference: %d" % difference) |
474 if abs(difference) <= 2: | 479 if abs(difference) <= 2: |
475 print("(good enough, moving to end of timestamp)") | 480 print("(good enough, moving to end of timestamp)") |
476 i += len(test_time_iso8601) | 481 skip_for = len(test_time_iso8601) - 1 |
477 | 482 |
478 if left[i] != right[i]: | 483 if left[i] != right[i]: |
479 start = max(0, i - 15) | 484 start = max(0, i - 15) |
480 l_end = min(len(left), i + 15) | 485 l_end = min(len(left), i + 15) |
481 r_end = min(len(right), i + 15) | 486 r_end = min(len(right), i + 15) |
500 "Left:", left, '', | 505 "Left:", left, '', |
501 "Right:", right, '', | 506 "Right:", right, '', |
502 "Difference:", | 507 "Difference:", |
503 l_str, (' ' * l_offset + '^'), | 508 l_str, (' ' * l_offset + '^'), |
504 r_str, (' ' * r_offset + '^')] | 509 r_str, (' ' * r_offset + '^')] |
510 | |
505 if len(left) > len(right): | 511 if len(left) > len(right): |
506 return ["Left is longer.", | 512 return ["Left is longer.", |
507 "Left '%s': " % ctx.path, left, | 513 "Left '%s': " % ctx.path, left, |
508 "Right '%s': " % ctx.path, right, | 514 "Right '%s': " % ctx.path, right, |
509 "Extra items: %r" % left[len(right):]] | 515 "Extra items: %r" % left[len(right):]] |
516 | |
510 if len(right) > len(left): | 517 if len(right) > len(left): |
511 return ["Right is longer.", | 518 return ["Right is longer.", |
512 "Left '%s': " % ctx.path, left, | 519 "Left '%s': " % ctx.path, left, |
513 "Right '%s': " % ctx.path, right, | 520 "Right '%s': " % ctx.path, right, |
514 "Extra items: %r" % right[len(left):]] | 521 "Extra items: %r" % right[len(left):]] |