Mercurial > libervia-backend
diff tests/e2e/run_e2e.py @ 4305:4cd4922de876
tests: reformat tests using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:11:56 +0200 |
parents | dfccc90cacc6 |
children |
line wrap: on
line diff
--- a/tests/e2e/run_e2e.py Fri Sep 06 18:07:44 2024 +0200 +++ b/tests/e2e/run_e2e.py Thu Sep 26 16:11:56 2024 +0200 @@ -30,6 +30,7 @@ from libervia.backend.core import exceptions from libervia.backend.tools.common import regex import yaml + try: from yaml import CLoader as Loader, CDumper as Dumper except ImportError: @@ -43,7 +44,8 @@ OPT_VISUAL = "--visual" OPT_DEV_MODE = "--dev-mode" -dev_mode_inst = dedent("""\ +dev_mode_inst = dedent( + """\ Here is a short script to start working with a logged account: from helium import * @@ -52,7 +54,8 @@ write("account1", "login") write("test", "password") click("log in") - """) + """ +) report_buffer = io.StringIO() live_out_buf = [] live_err_buf = [] @@ -63,7 +66,7 @@ # we may get bytes when buffer is reached and we are in the middle of an unicode # sequence. In this case we buffer it, and print it when it's complete if isinstance(data, str): - data = b''.join(live_out_buf).decode() + data + data = b"".join(live_out_buf).decode() + data live_out_buf.clear() else: live_out_buf.append(data) @@ -80,7 +83,7 @@ def live_err(data): if live_err_buf: if isinstance(data, str): - data = b''.join(live_err_buf).decode() + data + data = b"".join(live_err_buf).decode() + data live_err_buf.clear() else: live_err_buf.append(data) @@ -111,22 +114,24 @@ environment = override["services"]["backend"].setdefault("environment", {}) environment[name] = value + def write_report_log(path, log_raw, with_ansi=False): log_raw = str(log_raw) if with_ansi: # we save 2 versions: one with ANSI escape codes report_ansi = path.with_suffix(".ansi") - with report_ansi.open('w') as f: + with report_ansi.open("w") as f: f.write(log_raw) # and one cleaner, without them report_log = path.with_suffix(".log") - with report_log.open('w') as f: - f.write(regex.RE_ANSI_REMOVE.sub('', log_raw)) + with report_log.open("w") as f: + f.write(regex.RE_ANSI_REMOVE.sub("", log_raw)) else: report_log = path.with_suffix(".log") - with report_log.open('w') as f: + with report_log.open("w") as f: f.write(log_raw) + def use_e2e_env(): rev = os.getenv("DOCKER_LIBERVIA_REV", "dev") print(f"Running tests for Libervia {rev}") @@ -181,7 +186,8 @@ with tempfile.TemporaryDirectory(prefix="libervia_test_e2e_") as temp_dir: override_path = Path(temp_dir) / "test_override.yml" override = yaml.load( - dedent(f"""\ + dedent( + f"""\ version: "3.6" services: backend: @@ -205,8 +211,8 @@ target: {libervia_templates_target} read_only: true """ - ), - Loader=Loader + ), + Loader=Loader, ) if keep_profiles: @@ -222,24 +228,35 @@ yaml.dump(override, f, Dumper=Dumper) docker_compose = sh.docker_compose.bake( - "-f", compose_e2e_path, "-f", override_path) + "-f", compose_e2e_path, "-f", override_path + ) docker_compose.up("-d") p = docker_compose.exec( - "--workdir", "/src/libervia-backend/tests", "backend", - "pytest", "-o", "cache_dir=/tmp", *sys.argv[1:], color="yes", - _in=sys.stdin, _out=live_out, _out_bufsize=0, _err=live_err, _err_bufsize=0, - _bg=True + "--workdir", + "/src/libervia-backend/tests", + "backend", + "pytest", + "-o", + "cache_dir=/tmp", + *sys.argv[1:], + color="yes", + _in=sys.stdin, + _out=live_out, + _out_bufsize=0, + _err=live_err, + _err_bufsize=0, + _bg=True, ) if visual: - vnc_port = docker_compose.port("backend", "5900").split(':', 1)[1].strip() + vnc_port = docker_compose.port("backend", "5900").split(":", 1)[1].strip() p_vnc = sh.vncviewer( f"localhost:{vnc_port}", _bg=True, # vncviewer exits with 1 when we send an SIGTERM to it, and it's printed # before we can catch it (it's happening in a thread). Thus we set exit # code 1 as OK to avoid the backtrace. - _ok_code=[0, 1] + _ok_code=[0, 1], ) else: p_vnc = None @@ -254,17 +271,13 @@ # with `isoformat()`. sh.docker.cp(f"{libervia_cont_id}:/reports", f"./{report_dest}") write_report_log( - report_dest/"report", - report_buffer.getvalue(), - with_ansi=True + report_dest / "report", report_buffer.getvalue(), with_ansi=True ) write_report_log( - report_dest/"backend", - docker_compose.logs("--no-log-prefix", "backend") + report_dest / "backend", docker_compose.logs("--no-log-prefix", "backend") ) write_report_log( - report_dest/"web", - docker_compose.logs("--no-log-prefix", "web") + report_dest / "web", docker_compose.logs("--no-log-prefix", "web") ) print(f"report saved to {report_dest}") sys.exit(e.exit_code)