(file_name, id_to_count, available_ids)
| 68 | |
| 69 | |
| 70 | def fix_ids_in_source_file(file_name, id_to_count, available_ids): |
| 71 | source = read_file(file_name) |
| 72 | |
| 73 | k = 0 |
| 74 | destination = [] |
| 75 | for m in re.finditer(SOURCE_FILE_PATTERN, source): |
| 76 | destination.extend(source[k:m.start()]) |
| 77 | |
| 78 | underscore_pos = m.group(0).index("_") |
| 79 | error_id = m.group(0)[0:underscore_pos] |
| 80 | |
| 81 | # incorrect id or id has a duplicate somewhere |
| 82 | if not in_comment(source, m.start()) and (len(error_id) != 4 or error_id[0] == "0" or id_to_count[error_id] > 1): |
| 83 | assert error_id in id_to_count |
| 84 | new_id = get_next_id(available_ids) |
| 85 | assert new_id not in id_to_count |
| 86 | id_to_count[error_id] -= 1 |
| 87 | else: |
| 88 | new_id = error_id |
| 89 | |
| 90 | destination.extend(new_id + "_error") |
| 91 | k = m.end() |
| 92 | |
| 93 | destination.extend(source[k:]) |
| 94 | |
| 95 | destination = ''.join(destination) |
| 96 | if source != destination: |
| 97 | write_file(file_name, destination) |
| 98 | print(f"Fixed file: {file_name}") |
| 99 | |
| 100 | |
| 101 | def fix_ids_in_source_files(file_names, id_to_count): |
no test coverage detected