make-polyfill-tests.py (1186B)
1 #!/usr/bin/python 2 3 import os, re, os.path, glob 4 5 head = re.compile( r"^(\s*</head>)", re.MULTILINE ) 6 runtest = re.compile( r"runTest\(\s*(\S.*?)\s*\)", re.DOTALL ) 7 8 scripts = ''' 9 <!-- Polyfill files (NOTE: These are added by auto-generation script) --> 10 <script src=/encrypted-media/polyfill/chrome-polyfill.js></script> 11 <script src=/encrypted-media/polyfill/firefox-polyfill.js></script> 12 <script src=/encrypted-media/polyfill/edge-keystatuses.js></script> 13 <script src=/encrypted-media/polyfill/clearkey-polyfill.js></script>''' 14 15 def process_file( infile, outfile ) : 16 with open( outfile, "w" ) as output : 17 with open( infile, "r" ) as input : 18 output.write( runtest.sub( r"runTest( \1, 'polyfill: ' )", head.sub( scripts + r"\1", input.read() ) ) ) 19 20 if __name__ == '__main__' : 21 if (not os.getcwd().endswith('polyfill')) : 22 print("Please run from polyfill directory") 23 exit( 1 ) 24 25 for infile in glob.glob( "../*.html" ) : 26 process_file( infile, os.path.basename( infile ) ) 27 28 for infile in glob.glob( "../resources/*.html" ) : 29 process_file( infile, os.path.join( "resources", os.path.basename( infile ) ) )