| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
import argparse |
| 4 |
import json |
| 5 |
import subprocess |
| 6 |
import sys |
| 7 |
import os |
| 8 |
|
| 9 |
parser = argparse.ArgumentParser('convert flat apertium-regtest directory to one with subfolders') |
| 10 |
args = parser.parse_args() |
| 11 |
|
| 12 |
if not os.path.isdir('test'): |
| 13 |
print('test/ not found.') |
| 14 |
print('Please run this script from the top level of an Apertium directory.') |
| 15 |
sys.exit(1) |
| 16 |
|
| 17 |
os.mkdir('test/output') |
| 18 |
os.mkdir('test/gold') |
| 19 |
os.mkdir('test/expected') |
| 20 |
|
| 21 |
replace = { |
| 22 |
'-output.txt': 'test/output/', |
| 23 |
'-gold.txt': 'test/gold/', |
| 24 |
'-expected.txt': 'test/expected/' |
| 25 |
} |
| 26 |
|
| 27 |
for fname in os.listdir('test'): |
| 28 |
for old, new in replace.items(): |
| 29 |
if fname.endswith(old): |
| 30 |
os.rename('test/'+fname, new+fname[:-len(old)]+'.txt') |
| 31 |
|
| 32 |
tests = {} |
| 33 |
if os.path.isfile('test/tests.json'): |
| 34 |
with open('test/tests.json') as fin: |
| 35 |
tests = json.loads(fin.read()) |
| 36 |
tests['settings'] = {'structure': 'nested'} |
| 37 |
with open('test/tests.json', 'w') as js: |
| 38 |
js.write(json.dumps(tests, indent=4) + '\n') |
| 39 |
|
| 40 |
txt = '' |
| 41 |
end = '\n' |
| 42 |
if os.path.isfile('.gitignore'): |
| 43 |
with open('.gitignore') as fin: |
| 44 |
txt = fin.read() |
| 45 |
if '\r\n' in txt: |
| 46 |
end = '\r\n' |
| 47 |
if not txt.endswith(end): |
| 48 |
txt += end |
| 49 |
txt += '/test/output' + end |
| 50 |
with open('.gitignore', 'w') as fout: |
| 51 |
fout.write(txt) |
| 52 |
|
| 53 |
subprocess.run(['git', 'add', '.gitignore', 'test/tests.json']) |
| 54 |
subprocess.run(['git', 'add', 'test']) |