| Index: autotest.py |
| =================================================================== |
| --- a/autotest.py |
| +++ b/autotest.py |
| @@ -13,30 +13,34 @@ |
| def run_tests(): |
| - testDir = os.path.join(os.path.dirname(__file__), 'autotest') |
| + test_dir = os.path.join(os.path.dirname(__file__), 'autotest') |
| succeed = True |
| - for file in os.listdir(testDir): |
| - if not re.search(r'^test_.*\.js$', file): |
| + for filename in os.listdir(test_dir): |
| + if not re.search(r'^test_.*\.js$', filename): |
| continue |
| - file = os.path.join(testDir, file) |
| - handle = open(file, 'r') |
| + filename = os.path.join(test_dir, filename) |
| name = None |
| - arguments = None |
| - for line in handle: |
| - match = re.search(r'^//\s*([A-Za-z]+):\s*(.*?)\s*$', line) |
| - if match and match.group(1).lower() == 'name': |
| - name = match.group(2) |
| - elif match and match.group(1).lower() == 'arguments': |
| - arguments = match.group(2).split(' ') |
| - handle.close() |
| + args = None |
| - if arguments == None: |
| + with open(filename, 'r') as file: |
| + for line in file: |
| + match = re.search(r'^//\s*([A-Za-z]+):\s*(.*?)\s*$', line) |
| + if match: |
| + key = match.group(1).lower() |
| + if key == 'name': |
| + name = match.group(2) |
| + elif key == 'args': |
| + args = match.group(2).split() |
| + |
| + if args is None: |
| continue |
| - output = abp_rewrite.rewrite_js(arguments, file) |
| - expected = open(file + '.expected', 'rU').read() |
| + output = abp_rewrite.rewrite_js(args, filename) |
| + with open(filename + '.expected', 'rU') as file: |
| + expected = file.read() |
| + |
| if output == expected: |
| print(name + ' passed') |
| else: |
| @@ -44,8 +48,8 @@ |
| print(name + ' failed! Log:') |
| for line in difflib.unified_diff(expected.splitlines(), |
| output.splitlines(), |
| - fromfile=file + '.expected', |
| - tofile=file + '.output'): |
| + fromfile=filename + '.expected', |
| + tofile=filename + '.output'): |
| print(line) |
| print() |