|
1 | | -# Helper function for generating test files |
| 1 | +### CLI tools for testing consistency (but not correctness) of code snippets |
| 2 | +# See the heading "Code Snippets" in Development.md for more details about usage. |
| 3 | +# |
| 4 | +# |
| 5 | +# Author: Håvard Damm-Johnsen <havard-dj@proton.me> |
| 6 | + |
2 | 7 | # NB: magma is currently not supported, run manually instead |
3 | 8 |
|
| 9 | + |
4 | 10 | from pathlib import Path |
5 | 11 | import yaml |
6 | 12 | import argparse |
@@ -120,7 +126,6 @@ def _eval_code_file(data, lang, proc, logfile): |
120 | 126 | for line in lines: |
121 | 127 | if lang == 'magma': |
122 | 128 | print(line) |
123 | | - |
124 | 129 | try: |
125 | 130 | proc.run_command(line, timeout=60*3) |
126 | 131 | except Exception: |
@@ -223,12 +228,16 @@ def create_snippet_tests(yaml_file_path=None, ignore_langs=[], test=False, only_ |
223 | 228 | snippet_test = contents['snippet_test'] |
224 | 229 |
|
225 | 230 | snippet_langs = {'gp' if k == 'pari' else k for k in contents['prompt'].keys()} |
226 | | - snippet_langs &= langs # intersection of sets |
| 231 | + snippet_langs &= langs # intersect set with langs |
227 | 232 |
|
228 | 233 | for _, items in snippet_test.items(): |
229 | 234 | label = items['label'] |
230 | 235 |
|
231 | 236 | for lang in snippet_langs: |
| 237 | + test_langs = items.get('langs') |
| 238 | + # If we specify languages, only test those. Should fix the problem in PR #6934 |
| 239 | + if test_langs is not None and lang not in test_langs: |
| 240 | + continue |
232 | 241 | url = items['url'].format(lang=lang) |
233 | 242 | filename = code_file.stem + "-" + label + "-" + lang + ".log" |
234 | 243 |
|
@@ -271,10 +280,10 @@ def create_snippet_tests(yaml_file_path=None, ignore_langs=[], test=False, only_ |
271 | 280 | if __name__ == '__main__': |
272 | 281 | parser = argparse.ArgumentParser("Generate snippet tests") |
273 | 282 | parser.add_argument("cmd", help="*generate* test files or run *test*s", choices=['generate', 'test']) |
274 | | - parser.add_argument("-i", "--ignore", help="ignore languages", action='append', nargs='+', default=[]) |
275 | | - parser.add_argument("-o", "--only", help="only languages", action='append', nargs='+', default=None) |
276 | | - parser.add_argument("-f", "--file", help="run on single file", type=str) |
277 | | - parser.add_argument("-e", "--error-file", help="write errors to file", type=str) |
| 283 | + parser.add_argument("-i", "--ignore", help="Ignore languages - these will not be run", action='append', nargs='+', default=[]) |
| 284 | + parser.add_argument("-o", "--only", help="Only languages - only these languages will be run ", action='append', nargs='+', default=None) |
| 285 | + parser.add_argument("-f", "--file", help="Run test or generate on a single file", type=str) |
| 286 | + parser.add_argument("-e", "--error-file", help="Specify error log file (otherwise stdout)", type=str) |
278 | 287 |
|
279 | 288 | args = parser.parse_args() |
280 | 289 |
|
|
0 commit comments