Skip to content

Commit 4fc916e

Browse files
committed
testing common tests CI
1 parent 98a99f8 commit 4fc916e

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,28 @@ undeploy-c9s-%-c9s-python-3.9: bin/kubectl
394394
# ARG 1: UBI flavor
395395
# ARG 1: Python kernel
396396
define test_with_papermill
397+
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "python3 -m pip install papermill toml" ; \
398+
$(call test_with_papermill_common,$(1),$(2),$(3)) ; \
399+
$(call test_with_papermill_specific,$(1),$(2),$(3))
400+
endef
401+
402+
define test_with_papermill_common
403+
$(eval PREFIX_NAME := $(subst /,-,$(1)_$(2))) \
404+
$(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" ; \
405+
if [ $$? -ne 0 ]; then \
406+
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." ; \
407+
exit 1 ; \
408+
fi ; \
409+
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "cat $(PREFIX_NAME)_common_error.txt | grep --quiet FAILED" ; \
410+
if [ $$? -eq 0 ]; then \
411+
echo "ERROR: The $(1) $(2) notebook common tests encountered a failure. The make process has been aborted." ; \
412+
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "cat $(PREFIX_NAME)_common_error.txt" ; \
413+
exit 1 ; \
414+
fi
415+
endef
416+
417+
define test_with_papermill_specific
397418
$(eval PREFIX_NAME := $(subst /,-,$(1)_$(2))) \
398-
$(KUBECTL_BIN) exec $(FULL_NOTEBOOK_NAME) -- /bin/sh -c "python3 -m pip install papermill" ; \
399419
$(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" ; \
400420
if [ $$? -ne 0 ]; then \
401421
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." ; \
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "initial_id",
7+
"metadata": {
8+
"collapsed": true
9+
},
10+
"outputs": [],
11+
"source": [
12+
"import unittest\n",
13+
"from platform import python_version\n",
14+
"import importlib\n",
15+
"import toml\n",
16+
"\n",
17+
"def parse_pyproject_toml():\n",
18+
" with open('pyproject.toml', 'r') as file:\n",
19+
" pyproject_data = toml.load(file)\n",
20+
"\n",
21+
" dependencies = pyproject_data.get('tool', {}).get('poetry', {}).get('dependencies', {})\n",
22+
" dependencies.pop('python', None)\n",
23+
"\n",
24+
" return dependencies\n",
25+
"\n",
26+
"def parse_poetry_lock():\n",
27+
" with open('poetry.lock', 'r') as file:\n",
28+
" lock_data = toml.load(file)\n",
29+
"\n",
30+
" dependencies = {}\n",
31+
" for package in lock_data.get('package', []):\n",
32+
" name = package['name']\n",
33+
" version = package['version']\n",
34+
" dependencies[name] = version\n",
35+
"\n",
36+
" return dependencies\n",
37+
"\n",
38+
"def parse_python_version():\n",
39+
" with open('.python-version', 'r') as file:\n",
40+
" python_version = file.read()\n",
41+
" file.close()\n",
42+
"\n",
43+
" return python_version\n",
44+
"\n",
45+
"def get_major_minor(s):\n",
46+
" return '.'.join(s.split('.')[:2])\n",
47+
"\n",
48+
"class CommonTests(unittest.TestCase):\n",
49+
" def test_python_version(self):\n",
50+
" expected_major_minor = parse_python_version()\n",
51+
" actual_major_minor = get_major_minor(python_version())\n",
52+
" self.assertEqual(actual_major_minor, expected_major_minor, \"incorrect python version\")\n",
53+
"\n",
54+
" def test_dependencies_versions(self):\n",
55+
" direct_dependencies_map = parse_pyproject_toml()\n",
56+
" all_dependencies_map = parse_poetry_lock()\n",
57+
"\n",
58+
" for package, defined_version in direct_dependencies_map.items():\n",
59+
" expected_version = all_dependencies_map[package]\n",
60+
" installed_version = importlib.metadata.version(package)\n",
61+
" self.assertEqual(installed_version, expected_version, f\"incorrect {package} version\")\n",
62+
"\n",
63+
"unittest.main(argv=[''], verbosity=2, exit=False)"
64+
]
65+
}
66+
],
67+
"metadata": {
68+
"kernelspec": {
69+
"display_name": "Python 3",
70+
"language": "python",
71+
"name": "python3"
72+
},
73+
"language_info": {
74+
"codemirror_mode": {
75+
"name": "ipython",
76+
"version": 2
77+
},
78+
"file_extension": ".py",
79+
"mimetype": "text/x-python",
80+
"name": "python",
81+
"nbconvert_exporter": "python",
82+
"pygments_lexer": "ipython2",
83+
"version": "2.7.6"
84+
}
85+
},
86+
"nbformat": 4,
87+
"nbformat_minor": 5
88+
}

0 commit comments

Comments
 (0)