Skip to content

Commit 7c8179e

Browse files
committed
test notebooks
1 parent 6009244 commit 7c8179e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_notebooks.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
from collections.abc import Iterable
3+
from pathlib import Path
4+
5+
from testbook import testbook
6+
7+
TIMEOUT: int = 60 * 3 # 3 minutes
8+
9+
ROOT_DIRECTORY = Path(__file__).parent
10+
11+
12+
def test_notebooks():
13+
for notebook_path in _get_notebooks():
14+
with testbook(notebook_path, execute=True, timeout=TIMEOUT) as tb:
15+
pass # we simply wish it to run without errors
16+
17+
18+
# TODO: change this function to `from utils_for_tests import iterate_notebooks`, after we merge PR#109
19+
def _get_notebooks() -> Iterable[str]:
20+
if os.environ.get("SHOULD_TEST_ALL_FILES", "") == "true":
21+
notebooks_to_test = _get_all_notebooks()
22+
else:
23+
if os.environ.get("HAS_ANY_IPYNB_CHANGED", "") == "true":
24+
notebooks_to_test = os.environ.get("LIST_OF_IPYNB_CHANGED", "").split()
25+
else:
26+
notebooks_to_test = []
27+
28+
return notebooks_to_test
29+
30+
31+
def _get_all_notebooks(directory=ROOT_DIRECTORY):
32+
for root, dirs, files in os.walk(directory):
33+
for file in files:
34+
if file.endswith(".ipynb"):
35+
yield os.path.join(root, file)

0 commit comments

Comments
 (0)