Last active
September 20, 2016 19:07
-
-
Save dhermes/4e36f11eba22845309a484369ce56d41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import re | |
| import subprocess | |
| IS_REGEX = re.compile(r'self.assertTrue\((.*) is (.*)\)') | |
| def main(): | |
| git_root = subprocess.check_output( | |
| ['git', 'rev-parse', '--show-toplevel']) | |
| git_root = git_root.strip() | |
| cli_regex = 'self.assertTrue(.* is .*)' | |
| tests_dir = os.path.join(git_root, 'unit_tests') | |
| affected_files = subprocess.check_output( | |
| ['git', 'grep', '-l', cli_regex, '--', tests_dir]) | |
| affected_files = affected_files.strip().split('\n') | |
| sys_tests_dir = os.path.join(git_root, 'system_tests') | |
| also_affected = subprocess.check_output( | |
| ['git', 'grep', '-l', cli_regex, '--', sys_tests_dir]) | |
| affected_files.extend(also_affected.strip().split('\n')) | |
| assert len(affected_files) == 60 | |
| for filename in affected_files: | |
| with open(filename, 'rb') as file_obj: | |
| lines = file_obj.readlines() | |
| new_content = [] | |
| for line in lines: | |
| match = IS_REGEX.search(line) | |
| if match is not None: | |
| to_replace = match.group(0) | |
| to_keep1 = match.group(1) | |
| to_keep2 = match.group(2) | |
| new_assert = 'self.assertIs(%s, %s)' % (to_keep1, to_keep2) | |
| line = line.replace(to_replace, new_assert) | |
| new_content.append(line) | |
| with open(filename, 'wb') as file_obj: | |
| file_obj.writelines(new_content) | |
| subprocess.call(['git', 'add', filename]) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment