2022-06-07 19:00:46 -04:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
from os import path
|
2022-12-05 08:30:26 -05:00
|
|
|
from sys import argv
|
|
|
|
from yaml import safe_load
|
2022-06-07 19:00:46 -04:00
|
|
|
|
2022-12-05 08:30:26 -05:00
|
|
|
def main(test_filepath, template_filepath, cases_filepath):
|
|
|
|
cases = safe_load(open(cases_filepath))
|
2022-06-07 19:00:46 -04:00
|
|
|
|
|
|
|
jinja_env = Environment(
|
|
|
|
keep_trailing_newline=True,
|
2022-12-05 08:30:26 -05:00
|
|
|
loader=FileSystemLoader(path.dirname(template_filepath)),
|
2022-06-07 19:00:46 -04:00
|
|
|
)
|
2022-12-05 08:30:26 -05:00
|
|
|
jinja_template = jinja_env.get_template(path.basename(template_filepath))
|
2022-06-07 19:00:46 -04:00
|
|
|
|
|
|
|
result = jinja_template.render(
|
|
|
|
cases=cases,
|
|
|
|
escape_str=escape_str,
|
|
|
|
escape_int=escape_int,
|
|
|
|
len=len,
|
|
|
|
)
|
|
|
|
|
2022-12-05 08:30:26 -05:00
|
|
|
with open(test_filepath, 'w') as f:
|
2022-06-07 19:00:46 -04:00
|
|
|
f.write(result)
|
|
|
|
|
|
|
|
def escape_int(n):
|
|
|
|
return str(n)
|
|
|
|
|
|
|
|
def escape_str(s):
|
|
|
|
return '"' + s + '"'
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2022-12-05 08:30:26 -05:00
|
|
|
print(argv)
|
|
|
|
|
|
|
|
template_filepath = argv[1]
|
|
|
|
cases_filepath = argv[2]
|
|
|
|
test_filepath = argv[3]
|
|
|
|
|
|
|
|
print('test_filepath: %s' % test_filepath)
|
|
|
|
print('template_filepath: %s' % template_filepath)
|
|
|
|
print('cases_filepath: %s' % cases_filepath)
|
|
|
|
|
|
|
|
if path.exists(test_filepath) and not path.isfile(test_filepath):
|
|
|
|
raise RuntimeError('invalid test file path')
|
|
|
|
if not path.isfile(template_filepath):
|
|
|
|
raise RuntimeError('invalid template file path')
|
|
|
|
if not path.isfile(cases_filepath):
|
|
|
|
raise RuntimeError('invalid cases file path')
|
|
|
|
|
|
|
|
main(test_filepath, template_filepath, cases_filepath)
|