|
| 1 | +# Invoke is broken on Python 3.11 |
| 2 | +# https://github.com/pyinvoke/invoke/issues/833#issuecomment-1293148106 |
| 3 | +import inspect |
| 4 | +import os |
| 5 | +import re |
| 6 | +import shutil |
| 7 | +import sys |
| 8 | +import tempfile |
| 9 | +from enum import Enum |
| 10 | +from pathlib import Path |
| 11 | +from typing import Dict, Optional |
| 12 | + |
| 13 | +if not hasattr(inspect, "getargspec"): |
| 14 | + inspect.getargspec = inspect.getfullargspec |
| 15 | + |
| 16 | +import invoke |
| 17 | +from invoke import task |
| 18 | + |
| 19 | +# Specifying encoding because Windows crashes otherwise when running Invoke |
| 20 | +# tasks below: |
| 21 | +# UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' |
| 22 | +# in position 16: character maps to <undefined> |
| 23 | +# People say, it might also be possible to export PYTHONIOENCODING=utf8 but this |
| 24 | +# seems to work. |
| 25 | +# FIXME: If you are a Windows user and expert, please advise on how to do this |
| 26 | +# properly. |
| 27 | +sys.stdout = open(1, "w", encoding="utf-8", closefd=False, buffering=1) |
| 28 | + |
| 29 | + |
| 30 | +def run_invoke( |
| 31 | + context, |
| 32 | + cmd, |
| 33 | + environment: Optional[dict] = None, |
| 34 | + pty: bool = False, |
| 35 | + warn: bool = False, |
| 36 | +) -> invoke.runners.Result: |
| 37 | + def one_line_command(string): |
| 38 | + return re.sub("\\s+", " ", string).strip() |
| 39 | + |
| 40 | + return context.run( |
| 41 | + one_line_command(cmd), |
| 42 | + env=environment, |
| 43 | + hide=False, |
| 44 | + warn=warn, |
| 45 | + pty=pty, |
| 46 | + echo=True, |
| 47 | + ) |
| 48 | + |
| 49 | + |
| 50 | +@task(aliases=["ti"]) |
| 51 | +def test_integration( |
| 52 | + context, |
| 53 | + focus=None, |
| 54 | + debug=False, |
| 55 | + no_parallelization=False, |
| 56 | + fail_first=False, |
| 57 | +): |
| 58 | + clean_itest_artifacts(context) |
| 59 | + |
| 60 | + cwd = os.getcwd() |
| 61 | + |
| 62 | + parse_syntax_script = f'node \\"{cwd}/parse_syntax.js\\"' |
| 63 | + |
| 64 | + debug_opts = "-vv --show-all" if debug else "" |
| 65 | + focus_or_none = f"--filter {focus}" if focus else "" |
| 66 | + fail_first_argument = "--max-failures 1" if fail_first else "" |
| 67 | + parallelize_opts = "" if not no_parallelization else "--threads 1" |
| 68 | + test_folder = f"{cwd}/tests/integration" |
| 69 | + |
| 70 | + itest_command = f""" |
| 71 | + lit |
| 72 | + --param PARSE_SYNTAX_EXEC="{parse_syntax_script}" |
| 73 | + -v |
| 74 | + {debug_opts} |
| 75 | + {focus_or_none} |
| 76 | + {fail_first_argument} |
| 77 | + {parallelize_opts} |
| 78 | + {test_folder} |
| 79 | + """ |
| 80 | + run_invoke( |
| 81 | + context, |
| 82 | + itest_command, |
| 83 | + ) |
| 84 | + |
| 85 | +@task |
| 86 | +def clean_itest_artifacts(context): |
| 87 | + # The command sometimes exits with 1 even if the files are deleted. |
| 88 | + # warn=True ensures that the execution continues. |
| 89 | + run_invoke( |
| 90 | + context, |
| 91 | + """ |
| 92 | + git clean -dX --force --quiet tests/integration/ |
| 93 | + """, |
| 94 | + warn=True, |
| 95 | + ) |
0 commit comments