From 8ffb585659e301b605f0faa938ce9e5165b51d1d Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 26 Jan 2021 21:35:01 +0100 Subject: [PATCH] New function to write a whole .data file Signed-off-by: Gilles Peskine --- scripts/mbedtls_dev/test_case.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/mbedtls_dev/test_case.py b/scripts/mbedtls_dev/test_case.py index 8ef18510c..a6ed8fc90 100644 --- a/scripts/mbedtls_dev/test_case.py +++ b/scripts/mbedtls_dev/test_case.py @@ -17,7 +17,8 @@ # limitations under the License. import binascii -from typing import Any, List, Optional +import sys +from typing import Any, Iterable, List, Optional import typing_extensions #pylint: disable=import-error class Writable(typing_extensions.Protocol): @@ -86,3 +87,21 @@ class TestCase: if self.dependencies: out.write('depends_on:' + ':'.join(self.dependencies) + '\n') out.write(self.function + ':' + ':'.join(self.arguments) + '\n') + + + +def write_data_file(filename: str, + test_cases: Iterable[TestCase], + caller: Optional[str] = None) -> None: + """Write the test cases to the specified file. + + If the file already exists, it is overwritten. + """ + if caller is None: + caller = sys.argv[0] + with open(filename, 'w') as out: + out.write('# Automatically generated by {}. Do not edit!\n' + .format(caller)) + for tc in test_cases: + tc.write(out) + out.write('\n# End of automatically generated file.\n')