#!/usr/bin/env pythonw2.5

from __future__ import with_statement

import fnmatch
import os
import re
import glob

TESTS = "/Users/simon/projects/morph/core/web/selenium/tests/*.*"

ASSERT_LOCATION = re.compile(r'<td>assertLocation</td>\s*<td>\*?(.*)(?<!\*)</td>')

def main():
    for test_path in glob.glob(TESTS):
        with open(test_path) as test_file:
            test_data = test_file.read()
            new_test_data = ASSERT_LOCATION.sub(fixer, test_data)
            
        with open(test_path, 'w') as test_file:
            test_file.write(new_test_data)
                
def fixer(match):
    return '<td>assertLocation</td>\n                    <td>*' +  match.group(1) + '*</td>'

if __name__ == '__main__':
    main()