[Piglit] [PATCH 17/24] no upstream: add tool to fix all.py
Dylan Baker
baker.dylan.c at gmail.com
Mon Jan 5 13:50:38 PST 2015
This patch should not be commit to the upstream, but is the code that
was used to generate the next commit. It's too large to add to a commit
message gracefully, but I think it's worth a reviewers ability to read
the script to see what was changed.
There is a small caveat. This script will try to change
add_msaa_visual_tests, but that needed to be changed in a previous
the commit that changed the function to avoid breakage. Since this isn't
going upsteam and the extra code doesn't break anything I've left it.
---
fix_all.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
create mode 100755 fix_all.py
diff --git a/fix_all.py b/fix_all.py
new file mode 100755
index 0000000..b60dc7a
--- /dev/null
+++ b/fix_all.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python3
+
+"""Parse all.py and convert PiglitGLTest string arguments to list arguments."""
+
+import re
+import argparse
+
+_PIGLITGLTEST = re.compile(
+ r'(?P<head>.*?PiglitGLTest\()[\'\"](?P<args>.*?)[\'\"](?P<tail>.*)')
+_ADDTEST = re.compile(
+ r'(?P<head>.*?add_(concurrent|plain|msaa_visual_plain)_test(s?)\(.*?, )'
+ r'[\'\"](?P<args>.*?)[\'\"](?P<tail>(,|(?<!\()\)\s+#|(?<!\()\)$).*)')
+
+
+def fix_piglitgltest(line):
+ """Convert string arguments to PiglitGLTest to list arguments."""
+ if line.lstrip().startswith('return') or line.lstrip().startswith('def'):
+ return line
+
+ m = _PIGLITGLTEST.search(line)
+ assert m
+
+ final = '{head}[{args}]{tail}\n'.format(
+ head=m.group('head'),
+ args=', '.join("'{}'".format(x) for x in m.group('args').split()),
+ tail=m.group('tail'),
+ )
+
+ return final
+
+
+def fix_addtest(line):
+ """Convert string argument to add_*_test to list."""
+ if line.lstrip().startswith('return') or line.lstrip().startswith('def'):
+ return line
+
+ m = _ADDTEST.search(line)
+ assert m
+
+
+ final = '{head}[{args}]{tail}\n'.format(
+ head=m.group('head'),
+ args=', '.join("'{}'".format(x) for x in m.group('args').split()),
+ tail=m.group('tail'),
+ )
+ return final
+
+
+def walk(file_):
+ """Generator that iterates the lines of a file and fixes when necissary."""
+ is_addtest = re.compile(
+ r'add_(plain|concurrent|msaa_visual_plain)_test(s?)\('
+ r'.*?, [\'\"]')
+
+ with open(file_, 'r') as f:
+ for line in f:
+ if 'PiglitGLTest("' in line or "PiglitGLTest('" in line:
+ yield fix_piglitgltest(line)
+ elif is_addtest.search(line):
+ # Not every instance of add_*_test will be caught.
+ yield fix_addtest(line)
+ else:
+ yield line
+
+
+def main():
+ """Main function."""
+ parser = argparse.ArgumentParser()
+ parser.add_argument('all')
+ parser.add_argument('out')
+ args = parser.parse_args()
+
+ with open(args.out, 'w') as f:
+ for line in walk(args.all):
+ f.write(line)
+
+
+if __name__ == '__main__':
+ main()
--
2.2.1
More information about the Piglit
mailing list