diff --git a/.github/workflows/ci-toolchain.yml b/.github/workflows/ci-toolchain.yml index 41d7442f2..d2bc82809 100644 --- a/.github/workflows/ci-toolchain.yml +++ b/.github/workflows/ci-toolchain.yml @@ -72,7 +72,7 @@ jobs: python-version: '3.x' - name: Install e3 - run: pip install --upgrade e3-testsuite + run: pip install --upgrade -r testsuite/requirements.txt - name: Run testsuite run: cd testsuite; ./run.py -E diff --git a/testsuite/Dockerfile b/testsuite/Dockerfile index 6eaae2bcc..3a93b9b4f 100644 --- a/testsuite/Dockerfile +++ b/testsuite/Dockerfile @@ -15,7 +15,10 @@ RUN apt-get update && apt-get install -y \ sudo \ util-linux # for `unshare` -RUN pip3 install e3-testsuite +# Use parent testsuite python packages here too, as they are potential imports +# of the drivers and helpers that may be needed in the wrapped test. +COPY ./testsuite/requirements.txt /testsuite/requirements.txt +RUN pip3 install -r /testsuite/requirements.txt WORKDIR /testsuite USER user diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 6ddc8dee0..48254611f 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -4,12 +4,15 @@ import os import os.path +import platform +import pexpect import re -from shutil import copytree +import sys from e3.fs import mkdir from e3.os.process import Run, quote_arg from e3.testsuite.driver.classic import ProcessResult +from shutil import copytree TESTSUITE_ROOT = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) @@ -127,6 +130,44 @@ def run_alr(*args, **kwargs): return ProcessResult(p.status, p.out.replace('\r\n', '\n')) +def run_alr_interactive(args: [str], input: [str], timeout=5) -> str: + """ + NON-WINDOWS-ONLY + Run "alr" with the given arguments, feeding it the given input. No other + arguments like -q or -d are added. + + :param args: List of arguments to pass to "alr". + :param input: String to feed to the subprocess's standard input. + :param timeout: Timeout in seconds for the subprocess to complete. + """ + # Check whether on Windows to fail early (revisit if pexpect is updated?) + if platform.system() == "Windows": + print('SKIP: pexpect unavailable on Windows') + sys.exit(0) + + # Run interactively using pexpect (run with input fails as it is not + # detected as tty and input is closed prematurely) + child = pexpect.spawn('alr', args=args, timeout=timeout) + for line in input: + child.sendline(line) + + # Wait for the process to finish + try: + child.expect(pexpect.EOF) + child.close() + except pexpect.exceptions.TIMEOUT: + raise RuntimeError(f"pexpect timeout with alr output:\n" + f"{child.before.decode('utf-8')}") + + # Assert proper output code + assert child.exitstatus == 0, \ + f"Unexpected exit status: {child.exitstatus}\n" + \ + f"Output: {child.before.decode('utf-8')}" + + # Return command output with CRLF replaced by LF (as does run_alr) + return child.before.decode('utf-8').replace('\r\n', '\n') + + def fixtures_path(*args): """ Return a path under the testsuite `fixtures` directory. diff --git a/testsuite/requirements.txt b/testsuite/requirements.txt index b0fd578d0..dcaf78ee3 100644 --- a/testsuite/requirements.txt +++ b/testsuite/requirements.txt @@ -1,2 +1,3 @@ docker e3-testsuite +pexpect diff --git a/testsuite/tests/init/default-licenses/test.py b/testsuite/tests/init/default-licenses/test.py new file mode 100644 index 000000000..741472f11 --- /dev/null +++ b/testsuite/tests/init/default-licenses/test.py @@ -0,0 +1,32 @@ +""" +Check that offered default licenses are all valid +""" + +import os +import shutil + +from drivers.alr import run_alr, run_alr_interactive + +# iterate over values 1..8 +for i in range(1, 9): + + # Run interactively + run_alr_interactive(['init', '--bin', 'xxx'], + input=['', # Description + '', # Full user name + '', # Github login + '', # Email + f'{i}', # License + '', # Tags + ''], # Website + timeout=3) + + # Check that it can be shown, which will load the manifest + os.chdir("xxx") + p = run_alr("show") + + # Prepare for next iteration + os.chdir("..") + shutil.rmtree("xxx") + +print('SUCCESS') diff --git a/testsuite/tests/init/default-licenses/test.yaml b/testsuite/tests/init/default-licenses/test.yaml new file mode 100644 index 000000000..187c05aa3 --- /dev/null +++ b/testsuite/tests/init/default-licenses/test.yaml @@ -0,0 +1,2 @@ +driver: python-script +indexes: {}