tools/tinytest-codegen.py: Generate code for upytesthelper.

The way tinytest was used in qemu-arm test target is that it didn't test
much. MicroPython tests are based on matching the test output against
reference output, but qemu-arm's implementation didn't do that, it
effectively tested just that there was no exception during test
execution. "upytesthelper" wrapper was introduce to fix it, and so
test generator is now switched to generate test code for it.

Also, fix PEP8 and other codestyle issues.
This commit is contained in:
Paul Sokolovsky 2017-12-11 19:52:06 +02:00
parent 140bbced6f
commit 48e931e1d3
1 changed files with 27 additions and 21 deletions

View File

@ -5,6 +5,7 @@ from glob import glob
from re import sub
def escape(s):
s = s.decode()
lookup = {
'\0': '\\0',
'\t': '\\t',
@ -18,15 +19,20 @@ def escape(s):
def chew_filename(t):
return { 'func': "test_{}_fn".format(sub(r'/|\.|-', '_', t)), 'desc': t.split('/')[1] }
def script_to_map(t):
r = { 'name': chew_filename(t)['func'] }
with open(t) as f: r['script'] = escape(''.join(f.readlines()))
def script_to_map(test_file):
r = {"name": chew_filename(test_file)["func"]}
with open(test_file, "rb") as f:
r["script"] = escape(f.read())
with open(test_file + ".exp", "rb") as f:
r["output"] = escape(f.read())
return r
test_function = (
"void {name}(void* data) {{\n"
" const char * pystr = {script};\n"
" do_str(pystr);\n"
" static const char pystr[] = {script};\n"
" static const char exp[] = {output};\n"
" upytest_set_expected_output(exp, sizeof(exp) - 1);\n"
" upytest_execute_test(pystr);\n"
"}}"
)