Skip to content

Commit

Permalink
add code analysis and output stream to testcontainers (#114)
Browse files Browse the repository at this point in the history
* add output stream to testcontainers
* add code analysis for local package test
  • Loading branch information
vchrisb authored Mar 21, 2024
1 parent 1537ab6 commit a31dbd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions tools/testcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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"
Expand All @@ -144,5 +151,5 @@ def remove(self):
cmd = cmd + " -v'"
else:
cmd = cmd + "'"
testcontainers.exec_cmd(cmd)
testcontainers.exec_cmd_stream(cmd)
testcontainers.remove()
2 changes: 1 addition & 1 deletion tools/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ isort ./ --check -q
echo "running black"
black ./ --check
echo "running pyright"
pyright --pythonversion "3.8" --level error
pyright --level error

0 comments on commit a31dbd1

Please sign in to comment.