Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Add jupyter notebook to tests #6717

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ matplotlib
cffi
scipy
setproctitle
nbmake
68 changes: 68 additions & 0 deletions tests/python/test_ipython.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "51b3b00e",
"metadata": {},
"source": [
"# Count primes below a given bound"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83062572",
"metadata": {},
"outputs": [],
"source": [
"import taichi as ti\n",
"\n",
"def test_kernel_print():\n",
" N = 10000\n",
" ti.init()\n",
" @ti.func\n",
" def is_prime(n: int):\n",
" result = True\n",
" for k in range(2, int(n**0.5) + 1):\n",
" if n % k == 0:\n",
" result = False\n",
" break\n",
" return result\n",
"\n",
" @ti.kernel\n",
" def count_primes(n: int) -> int:\n",
" count = 0\n",
" for k in range(2, n):\n",
" if is_prime(k):\n",
" count += 1\n",
"\n",
" return count\n",
"\n",
" count_primes(N)\n",
" \n",
"test_kernel_print()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
3 changes: 2 additions & 1 deletion tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _test_python(args):
# auto-complete file names
if not f.startswith('test_'):
f = 'test_' + f
if not f.endswith('.py'):
if not (f.endswith('.py') or f.endswith('.ipynb')):
f = f + '.py'
file = os.path.join(test_dir, f)
has_tests = False
Expand All @@ -164,6 +164,7 @@ def _test_python(args):
else:
# run all the tests
pytest_args = [test_dir]
pytest_args += ['--nbmake']
if args.verbose:
pytest_args += ['-v']
if args.rerun:
Expand Down