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