3 # This script converts API YAML files into markdown documentation
4 # and prints it to standard out.
9 def single_test(name:str, test)->str:
10 if "example" not in test: return
11 if name.startswith("Path.") or name in ['exit', 'say', 'print', 'sleep', 'fail', 'getenv', 'setenv', 'at_cleanup', 'ask']:
12 return f" if no # Test {name}\n " + test["example"].replace('\n', '\n ').strip()
13 return f" do # Test {name}\n " + test["example"].replace('\n', '\n ').strip()
15 def print_tests(yaml_doc:str):
16 data = yaml.safe_load(yaml_doc)
19 for name in sorted([k for k in data.keys()]):
20 t = single_test(name, data[name])
21 if t: all_tests.append(t)
23 print("# This file contains auto-generated tests from the examples in api/*.yaml\n")
25 print('\n\n'.join(all_tests))
27 if __name__ == "__main__":
31 for filename in sys.argv[1:]:
32 with open(filename, "r") as f:
34 print_tests(all_files)
36 print_tests(sys.stdin.read())