Skip to content

Commit a31dbd1

Browse files
authored
add code analysis and output stream to testcontainers (#114)
* add output stream to testcontainers * add code analysis for local package test
1 parent 1537ab6 commit a31dbd1

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

tools/testcontainers.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ def __init__(
5151
},
5252
)
5353

54-
def exec_cmd_stream(self, command):
54+
def exec_cmd_stream(self, command, verbose=True):
5555
"""Execute a command and stream output."""
56-
_, stream = self.container.exec_run(cmd=command, stream=True)
56+
exec_id = self.container.client.api.exec_create(self.container.id, command)
57+
stream = self.container.client.api.exec_start(exec_id, stream=True)
5758
for data in stream:
58-
print(data.decode(), end="")
59+
if verbose:
60+
print(data.decode(), end="")
61+
result = self.container.client.api.exec_inspect(exec_id)["ExitCode"]
62+
if result != 0:
63+
exit(1)
5964

6065
def exec_cmd(self, command, verbose=True):
6166
"""Execute a command and validate return code."""
@@ -130,9 +135,11 @@ def remove(self):
130135
)
131136
cmd = "sh -c 'python tools/tests.py -u $USERNAME -p $PASSWORD -c $CONFIG"
132137
if args["module"] == "local":
133-
testcontainers.exec_cmd("pip install .", args["verbose"])
138+
testcontainers.exec_cmd_stream("pip install .[develop]", args["verbose"])
139+
print("Running black, flake8, isort and pyright:")
140+
testcontainers.exec_cmd_stream("tools/validate.sh", args["verbose"])
134141
else:
135-
testcontainers.exec_cmd(
142+
testcontainers.exec_cmd_stream(
136143
"pip install pye3dc=={}".format(args["module"]), args["verbose"]
137144
)
138145
cmd = cmd + " -m"
@@ -144,5 +151,5 @@ def remove(self):
144151
cmd = cmd + " -v'"
145152
else:
146153
cmd = cmd + "'"
147-
testcontainers.exec_cmd(cmd)
154+
testcontainers.exec_cmd_stream(cmd)
148155
testcontainers.remove()

tools/validate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ isort ./ --check -q
77
echo "running black"
88
black ./ --check
99
echo "running pyright"
10-
pyright --pythonversion "3.8" --level error
10+
pyright --level error

0 commit comments

Comments
 (0)