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')