| 55 | |
| 56 | |
| 57 | def check_file(path, old_division): |
| 58 | futures = set() |
| 59 | count = 0 |
| 60 | for line in open(path, encoding='utf-8') if six.PY3 else open(path): |
| 61 | count += 1 |
| 62 | m = FUTURES_PATTERN.match(line) |
| 63 | if not m: |
| 64 | m = FUTURES_PATTERN_3.match(line) |
| 65 | if m: |
| 66 | futures.add(m.group(1)) |
| 67 | else: |
| 68 | m = FUTURES_PATTERN_2.match(line) |
| 69 | if m: |
| 70 | for entry in m.groups(): |
| 71 | futures.add(entry) |
| 72 | if not count: |
| 73 | return # Skip empty files |
| 74 | if old_division: |
| 75 | # This file checks correct behavior without importing division |
| 76 | # from __future__, so make sure it's doing that. |
| 77 | expected = set(['absolute_import', 'print_function']) |
| 78 | if futures != expected: |
| 79 | raise AssertionError(('Incorrect futures for old_division file:\n' |
| 80 | ' expected = %s\n got = %s') % |
| 81 | (' '.join(expected), ' '.join(futures))) |
| 82 | else: |
| 83 | missing = REQUIRED_FUTURES - futures |
| 84 | if missing: |
| 85 | raise AssertionError('Missing futures: %s' % ' '.join(missing)) |
| 86 | |
| 87 | |
| 88 | def main(): |