diff --git a/jupyter-tensorflow-full/tests/imports.py b/jupyter-tensorflow-full/tests/imports.py new file mode 100755 index 0000000..71502b2 --- /dev/null +++ b/jupyter-tensorflow-full/tests/imports.py @@ -0,0 +1,24 @@ +# +# This python script tests loading of required modules +# +import tensorflow as tf +import kfp +import kfp_server_api +import kfserving +import bokeh +import cloudpickle +import dill +import ipympl +import ipywidgets +import jupyterlab_git +import matplotlib +import pandas +# TO-DO verify how exactly scikit-image is installed +#import scikit_image +import scikit_learn +import scipy +import seaborn +import xgboost + +# this string is expected by test script +print("PASSED") diff --git a/jupyter-tensorflow-full/tests/test_imports.py b/jupyter-tensorflow-full/tests/test_imports.py new file mode 100755 index 0000000..a46f9a5 --- /dev/null +++ b/jupyter-tensorflow-full/tests/test_imports.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. +# +# +from pathlib import Path + +import os +import subprocess +import yaml + + +def main(): + """Test running container and imports.""" + rock = yaml.safe_load(Path("rockcraft.yaml").read_text()) + name = rock["name"] + rock_version = rock["version"] + arch = list(rock["platforms"].keys())[0] + rock_image = f"{name}_{rock_version}_{arch}" + LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}" + + print(f"Running command in {LOCAL_ROCK_IMAGE}") + script_command = ["bash", "-c", "export PYTHONPATH=$PYTHONPATH:/opt/conda/lib/python3.8/site-packages/keras/api/keras/wrappers/:/opt/conda/lib/python3.8/site-packages/ && python3 /home/jovyan/imports.py"] + pwd = os.getcwd() + output = subprocess.run(["docker", "run", "-v", f"{pwd}/tests/:/home/jovyan", LOCAL_ROCK_IMAGE, "exec", "pebble", "exec"] + script_command, stdout=subprocess.PIPE).stdout.decode('utf-8') + assert "PASSED" in output + +if __name__ == "__main__": + main() diff --git a/jupyter-tensorflow-full/tox.ini b/jupyter-tensorflow-full/tox.ini index f96b0a6..3ee3136 100644 --- a/jupyter-tensorflow-full/tox.ini +++ b/jupyter-tensorflow-full/tox.ini @@ -35,4 +35,5 @@ commands = docker save $ROCK > $ROCK.tar' # run rock tests pytest -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests + python {toxinidir}/tests/test_imports.py python {toxinidir}/tests/test_access.py