Skip to content

Commit

Permalink
testing common tests CI
Browse files Browse the repository at this point in the history
  • Loading branch information
paulovmr committed Jul 12, 2024
1 parent 98a99f8 commit 4fc916e
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,28 @@ undeploy-c9s-%-c9s-python-3.9: bin/kubectl
# ARG 1: UBI flavor
# ARG 1: Python kernel
define test_with_papermill
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "python3 -m pip install papermill toml" ; \
$(call test_with_papermill_common,$(1),$(2),$(3)) ; \
$(call test_with_papermill_specific,$(1),$(2),$(3))
endef

define test_with_papermill_common
$(eval PREFIX_NAME := $(subst /,-,$(1)_$(2))) \
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "wget ${NOTEBOOK_REPO_BRANCH_BASE}/jupyter/common/test/test_notebook_common.ipynb -O test_notebook_common.ipynb && python3 -m papermill test_notebook_common.ipynb $(PREFIX_NAME)_common_output.ipynb --kernel python3 --stderr-file $(PREFIX_NAME)_common_error.txt" ; \
if [ $$? -ne 0 ]; then \
echo "ERROR: The $(1) $(2) notebook common tests encountered a failure. To investigate the issue, you can review the logs located in the ocp-ci cluster on 'artifacts/notebooks-e2e-tests/jupyter-$(1)-$(2)-$(3)-test-e2e' directory or run 'cat $(PREFIX_NAME)_common_error.txt' within your container. The make process has been aborted." ; \
exit 1 ; \
fi ; \
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "cat $(PREFIX_NAME)_common_error.txt | grep --quiet FAILED" ; \
if [ $$? -eq 0 ]; then \
echo "ERROR: The $(1) $(2) notebook common tests encountered a failure. The make process has been aborted." ; \
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "cat $(PREFIX_NAME)_common_error.txt" ; \
exit 1 ; \
fi
endef

define test_with_papermill_specific
$(eval PREFIX_NAME := $(subst /,-,$(1)_$(2))) \
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "python3 -m pip install papermill" ; \
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "wget ${NOTEBOOK_REPO_BRANCH_BASE}/jupyter/$(1)/$(2)-$(3)/test/test_notebook.ipynb -O test_notebook.ipynb && python3 -m papermill test_notebook.ipynb $(PREFIX_NAME)_output.ipynb --kernel python3 --stderr-file $(PREFIX_NAME)_error.txt" ; \
if [ $$? -ne 0 ]; then \
echo "ERROR: The $(1) $(2) notebook encountered a failure. To investigate the issue, you can review the logs located in the ocp-ci cluster on 'artifacts/notebooks-e2e-tests/jupyter-$(1)-$(2)-$(3)-test-e2e' directory or run 'cat $(PREFIX_NAME)_error.txt' within your container. The make process has been aborted." ; \
Expand Down
88 changes: 88 additions & 0 deletions jupyter/common/test/test_notebook_common.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import unittest\n",
"from platform import python_version\n",
"import importlib\n",
"import toml\n",
"\n",
"def parse_pyproject_toml():\n",
" with open('pyproject.toml', 'r') as file:\n",
" pyproject_data = toml.load(file)\n",
"\n",
" dependencies = pyproject_data.get('tool', {}).get('poetry', {}).get('dependencies', {})\n",
" dependencies.pop('python', None)\n",
"\n",
" return dependencies\n",
"\n",
"def parse_poetry_lock():\n",
" with open('poetry.lock', 'r') as file:\n",
" lock_data = toml.load(file)\n",
"\n",
" dependencies = {}\n",
" for package in lock_data.get('package', []):\n",
" name = package['name']\n",
" version = package['version']\n",
" dependencies[name] = version\n",
"\n",
" return dependencies\n",
"\n",
"def parse_python_version():\n",
" with open('.python-version', 'r') as file:\n",
" python_version = file.read()\n",
" file.close()\n",
"\n",
" return python_version\n",
"\n",
"def get_major_minor(s):\n",
" return '.'.join(s.split('.')[:2])\n",
"\n",
"class CommonTests(unittest.TestCase):\n",
" def test_python_version(self):\n",
" expected_major_minor = parse_python_version()\n",
" actual_major_minor = get_major_minor(python_version())\n",
" self.assertEqual(actual_major_minor, expected_major_minor, \"incorrect python version\")\n",
"\n",
" def test_dependencies_versions(self):\n",
" direct_dependencies_map = parse_pyproject_toml()\n",
" all_dependencies_map = parse_poetry_lock()\n",
"\n",
" for package, defined_version in direct_dependencies_map.items():\n",
" expected_version = all_dependencies_map[package]\n",
" installed_version = importlib.metadata.version(package)\n",
" self.assertEqual(installed_version, expected_version, f\"incorrect {package} version\")\n",
"\n",
"unittest.main(argv=[''], verbosity=2, exit=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 4fc916e

Please sign in to comment.