Skip to content

Commit

Permalink
Merge pull request #1389 from mathbunnyru/asalikhov/assert_after_logs
Browse files Browse the repository at this point in the history
Move assert after logs output to make debug easier
  • Loading branch information
mathbunnyru committed Jun 27, 2021
2 parents aee3cbb + 5c860df commit c65c56f
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion all-spark-notebook/test/test_spark_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_nbconvert(container, test_file):
command=["start.sh", "bash", "-c", command],
)
rv = c.wait(timeout=timeout_ms / 10 + 10)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
expected_file = f"{output_dir}/{test_file}.md"
assert expected_file in logs, f"Expected file {expected_file} not generated"
2 changes: 1 addition & 1 deletion base-notebook/test/test_package_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_package_manager(container, package_manager, version_arg):
)
rv = c.wait(timeout=5)
logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs)
assert (
rv == 0 or rv["StatusCode"] == 0
), f"Package manager {package_manager} not working"
LOGGER.debug(logs)
2 changes: 1 addition & 1 deletion base-notebook/test/test_start_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def test_start_notebook(container, http_client, env, expected_server):
)
c = container.run(tty=True, environment=env, command=["start-notebook.sh"])
resp = http_client.get("http://localhost:8888")
assert resp.status_code == 200, "Server is not listening"
logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs)
assert resp.status_code == 200, "Server is not listening"
assert (
f"Executing the command: jupyter {expected_server}" in logs
), f"Not the expected command (jupyter {expected_server}) was launched"
Expand Down
2 changes: 1 addition & 1 deletion datascience-notebook/test/test_julia.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def test_julia(container):
command = "julia --version"
cmd = running_container.exec_run(command)
output = cmd.output.decode("utf-8")
assert cmd.exit_code == 0, f"Command {command} failed {output}"
LOGGER.debug(output)
assert cmd.exit_code == 0, f"Command {command} failed {output}"
2 changes: 1 addition & 1 deletion minimal-notebook/test/test_nbconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_nbconvert(container, test_file, output_format):
command=["start.sh", "bash", "-c", command],
)
rv = c.wait(timeout=30)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
expected_file = f"{output_dir}/{test_file}.{output_format}"
assert expected_file in logs, f"Expected file {expected_file} not generated"
2 changes: 1 addition & 1 deletion pyspark-notebook/test/test_spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def test_pyspark(container):
command=['start.sh', 'python', '-c', 'import pyspark']
)
rv = c.wait(timeout=30)
assert rv == 0 or rv["StatusCode"] == 0, "pyspark not in PYTHONPATH"
logs = c.logs(stdout=True).decode('utf-8')
LOGGER.debug(logs)
assert rv == 0 or rv["StatusCode"] == 0, "pyspark not in PYTHONPATH"
4 changes: 2 additions & 2 deletions scipy-notebook/test/test_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def test_matplotlib(container, test_file, expected_file, description):
)
command = f"python {cont_data_dir}/{test_file}"
cmd = running_container.exec_run(command)
assert cmd.exit_code == 0, f"Command {command} failed"
LOGGER.debug(cmd.output.decode("utf-8"))
assert cmd.exit_code == 0, f"Command {command} failed"
# Checking if the file is generated
# https://stackoverflow.com/a/15895594/4413446
command = f"test -s {output_dir}/{expected_file}"
cmd = running_container.exec_run(command)
assert cmd.exit_code == 0, f"Command {command} failed"
LOGGER.debug(cmd.output.decode("utf-8"))
assert cmd.exit_code == 0, f"Command {command} failed"
2 changes: 1 addition & 1 deletion scipy-notebook/test/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def test_pandas(container, name, command_list):
command = ';'.join(command_list)
c = container.run(tty=True, command=["start.sh", "python", "-c", command])
rv = c.wait(timeout=30)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
2 changes: 1 addition & 1 deletion tagging/docker_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def __exit__(self, exc_type, exc_value, traceback):
def run_simple_command(container, cmd: str, print_result: bool = True):
logger.info(f"Running cmd: '{cmd}' on container: {container}")
out = container.exec_run(cmd)
assert out.exit_code == 0, f"Command: {cmd} failed"
result = out.output.decode("utf-8").rstrip()
if print_result:
logger.info(f"Command result: {result}")
assert out.exit_code == 0, f"Command: {cmd} failed"
return result
2 changes: 1 addition & 1 deletion tensorflow-notebook/test/test_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def test_tensorflow(container, name, command):
LOGGER.info(f"Testing tensorflow: {name} ...")
c = container.run(tty=True, command=["start.sh", "python", "-c", command])
rv = c.wait(timeout=30)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"

0 comments on commit c65c56f

Please sign in to comment.