From a31dbd1bb63ef1fc2153823e5acd642a5a08f0d4 Mon Sep 17 00:00:00 2001 From: Christopher Banck Date: Thu, 21 Mar 2024 11:50:00 +0100 Subject: [PATCH] add code analysis and output stream to testcontainers (#114) * add output stream to testcontainers * add code analysis for local package test --- tools/testcontainers.py | 19 +++++++++++++------ tools/validate.sh | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/testcontainers.py b/tools/testcontainers.py index e7dc1a1..4f041b8 100644 --- a/tools/testcontainers.py +++ b/tools/testcontainers.py @@ -51,11 +51,16 @@ def __init__( }, ) - def exec_cmd_stream(self, command): + def exec_cmd_stream(self, command, verbose=True): """Execute a command and stream output.""" - _, stream = self.container.exec_run(cmd=command, stream=True) + exec_id = self.container.client.api.exec_create(self.container.id, command) + stream = self.container.client.api.exec_start(exec_id, stream=True) for data in stream: - print(data.decode(), end="") + if verbose: + print(data.decode(), end="") + result = self.container.client.api.exec_inspect(exec_id)["ExitCode"] + if result != 0: + exit(1) def exec_cmd(self, command, verbose=True): """Execute a command and validate return code.""" @@ -130,9 +135,11 @@ def remove(self): ) cmd = "sh -c 'python tools/tests.py -u $USERNAME -p $PASSWORD -c $CONFIG" if args["module"] == "local": - testcontainers.exec_cmd("pip install .", args["verbose"]) + testcontainers.exec_cmd_stream("pip install .[develop]", args["verbose"]) + print("Running black, flake8, isort and pyright:") + testcontainers.exec_cmd_stream("tools/validate.sh", args["verbose"]) else: - testcontainers.exec_cmd( + testcontainers.exec_cmd_stream( "pip install pye3dc=={}".format(args["module"]), args["verbose"] ) cmd = cmd + " -m" @@ -144,5 +151,5 @@ def remove(self): cmd = cmd + " -v'" else: cmd = cmd + "'" - testcontainers.exec_cmd(cmd) + testcontainers.exec_cmd_stream(cmd) testcontainers.remove() diff --git a/tools/validate.sh b/tools/validate.sh index 143530c..d3d2ab2 100755 --- a/tools/validate.sh +++ b/tools/validate.sh @@ -7,4 +7,4 @@ isort ./ --check -q echo "running black" black ./ --check echo "running pyright" -pyright --pythonversion "3.8" --level error \ No newline at end of file +pyright --level error \ No newline at end of file