genHTMLfromTest.py (1016B)
1 import os 2 import re 3 4 # Generate an HTML file for each .test file in the current directory 5 # 6 7 TEST_LIST_FILE = '00_test_list.txt'; 8 TEMPLATE = 'template.html'; 9 10 def genHTML(template, test): 11 contents = re.sub('___TEST_NAME___', "'" + test + "'", template); 12 filename = test + '.html'; 13 print "Generating " + filename; 14 with open(test + '.html', 'w') as f: 15 f.write(contents); 16 return filename; 17 18 19 def process_test_files(template): 20 generated = []; 21 files = os.listdir(os.getcwd()); 22 for file in files: 23 found = re.search('(^[^.].*)\.test$', file); 24 if found: 25 generated.append(genHTML(template,found.group(1))); 26 return generated; 27 28 def readTemplate(): 29 contents = None; 30 with open(TEMPLATE, 'r') as f: 31 contents = f.read(); 32 return contents; 33 34 35 template = readTemplate(); 36 if (template): 37 test_list = process_test_files(template); 38 print "Generating " + TEST_LIST_FILE; 39 with open(TEST_LIST_FILE, 'w') as f: 40 for item in test_list: 41 f.write(item + '\n'); 42 else: 43 print "Couldn't find template file: " + TEMPLATE;