OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 import os |
| 4 import urllib |
| 5 import hashlib |
| 6 |
| 7 doctmpl = """<!doctype html> |
| 8 <title>WebVTT cue data parser test %s</title> |
| 9 <style>video { display:none }</style> |
| 10 <script src=/resources/testharness.js></script> |
| 11 <script src=/resources/testharnessreport.js></script> |
| 12 <script src=/html/syntax/parsing/template.js></script> |
| 13 <script src=/html/syntax/parsing/common.js></script> |
| 14 <script src=../common.js></script> |
| 15 <div id=log></div> |
| 16 <script> |
| 17 runTests([ |
| 18 %s |
| 19 ]); |
| 20 </script>""" |
| 21 |
| 22 testobj = "{name:'%s', input:'%s', expected:'%s'}" |
| 23 |
| 24 def appendtest(tests, input, expected): |
| 25 tests.append(testobj % (hashlib.sha1(input).hexdigest(), urllib.quote(input[
:-1]), urllib.quote(expected[:-1]))) |
| 26 |
| 27 files = os.listdir('dat/') |
| 28 for file in files: |
| 29 if os.path.isdir('dat/'+file) or file[0] == ".": |
| 30 continue |
| 31 tests = [] |
| 32 input = "" |
| 33 expected = "" |
| 34 state = "" |
| 35 f = open('dat/'+file, "r") |
| 36 while 1: |
| 37 line = f.readline() |
| 38 if not line: |
| 39 if state != "": |
| 40 appendtest(tests, input, expected) |
| 41 input = "" |
| 42 expected = "" |
| 43 state = "" |
| 44 break |
| 45 if line[0] == "#": |
| 46 state = line |
| 47 if line == "#document-fragment\n": |
| 48 expected = expected + line |
| 49 elif state == "#data\n": |
| 50 input = input + line |
| 51 elif state == "#errors\n": |
| 52 pass |
| 53 elif state == "#document-fragment\n": |
| 54 if line == "\n": |
| 55 appendtest(tests, input, expected) |
| 56 input = "" |
| 57 expected = "" |
| 58 state = "" |
| 59 else: |
| 60 expected = expected + line |
| 61 else: |
| 62 raise Exception("failed to parse file "+file+" line:"+line+" (state:
"+state+")") |
| 63 f.close() |
| 64 barename = file.replace(".dat", "") |
| 65 out = open('tests/'+barename+".html", "w") |
| 66 out.write(doctmpl % (barename, ",\n".join(tests))) |
| 67 out.close() |
OLD | NEW |