Mercurial > piecrust2
comparison tests/conftest.py @ 582:d8d9e0424a72
tests: Fix (hopefully) time-sensitive tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 30 Dec 2015 20:41:16 -0800 |
parents | a65f04ddbea2 |
children | 1eda551ee681 |
comparison
equal
deleted
inserted
replaced
581:911a054f4fbd | 582:d8d9e0424a72 |
---|---|
447 if left == right: | 447 if left == right: |
448 return None | 448 return None |
449 | 449 |
450 test_time_iso8601 = time.strftime('%Y-%m-%dT%H:%M:%SZ', | 450 test_time_iso8601 = time.strftime('%Y-%m-%dT%H:%M:%SZ', |
451 time.gmtime(ctx.time)) | 451 time.gmtime(ctx.time)) |
452 replacements = { | 452 test_time_iso8601_pattern = '%test_time_iso8601%' |
453 '%test_time_iso8601%': test_time_iso8601} | 453 |
454 for token, repl in replacements.items(): | 454 left_time_indices = [] |
455 left = left.replace(token, repl) | 455 i = -1 |
456 right = right.replace(token, repl) | 456 while True: |
457 i = left.find(test_time_iso8601_pattern, i + 1) | |
458 if i >= 0: | |
459 left_time_indices.append(i) | |
460 left = (left[:i] + test_time_iso8601 + | |
461 left[i + len(test_time_iso8601_pattern):]) | |
462 else: | |
463 break | |
457 | 464 |
458 for i in range(min(len(left), len(right))): | 465 for i in range(min(len(left), len(right))): |
466 if i in left_time_indices: | |
467 # 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). | |
469 right_time_str = right[i:i + len(test_time_iso8601)] | |
470 right_time = time.strptime(right_time_str, '%Y-%m-%dT%H:%M:%SZ') | |
471 left_time = time.gmtime(ctx.time) | |
472 difference = time.mktime(left_time) - time.mktime(right_time) | |
473 print("Got time difference: %d" % difference) | |
474 if abs(difference) <= 2: | |
475 print("(good enough, moving to end of timestamp)") | |
476 i += len(test_time_iso8601) | |
477 | |
459 if left[i] != right[i]: | 478 if left[i] != right[i]: |
460 start = max(0, i - 15) | 479 start = max(0, i - 15) |
461 l_end = min(len(left), i + 15) | 480 l_end = min(len(left), i + 15) |
462 r_end = min(len(right), i + 15) | 481 r_end = min(len(right), i + 15) |
463 | 482 |