forked from instructure/straitjacket
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_tests.py
30 lines (26 loc) · 1.57 KB
/
convert_tests.py
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
import ConfigParser
def _get_pattern(my_config, section, pattern_name):
pattern = my_config.get(section, pattern_name)
if pattern.startswith('\A'): pattern = pattern[2:]
if pattern.endswith('\Z'): pattern = pattern[:-2]
return pattern
for language in ['d', 'fortran', 'go', 'guile', 'haskell', 'java', 'javascript', 'lua', 'ocaml', 'perl', 'php', 'python', 'ruby1.8', 'ruby1.9', 'scala', 'scheme']:
my_config = ConfigParser.SafeConfigParser()
my_config.read('./config/lang-{0}.conf'.format(language))
new_test = ''
for section in my_config.sections():
if not section.startswith('test-'):
continue
new_test += "LanguageTest('{0}', {1},\n".format(section, language)
new_test += " source = ( '{:<60}\\n'\n".format(my_config.get(section, 'source').split('\n')[0])
for source_line in my_config.get(section, 'source').split('\n')[1:]:
new_test += " '{:<60}\\n'\n".format(source_line)
new_test += " ),\n"
new_test += " stdout = '{0}',\n".format(_get_pattern(my_config, section, 'stdout'))
new_test += " stderr = '{0}',\n".format(_get_pattern(my_config, section, 'stderr'))
new_test += " returncode = {0},\n".format(my_config.get(section, 'exitstatus'))
error = my_config.get(section, 'error')
new_test += " error = {0})\n".format("'" + error + "'" if error else 'None')
new_test += "\n"
with open('./config/{0}.py'.format(language), 'w') as f:
f.write(new_test)