diff --git a/tests/notebooks/test_hhl_lanchester.py b/tests/notebooks/test_hhl_lanchester.py new file mode 100644 index 000000000..c2fefc17c --- /dev/null +++ b/tests/notebooks/test_hhl_lanchester.py @@ -0,0 +1,11 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("hhl_lanchester", timeout_seconds=450) +def test_notebook(tb: TestbookNotebookClient) -> None: + pass # TODO diff --git a/tests/notebooks/test_logical_qubits_by_alice_and_bob.py b/tests/notebooks/test_logical_qubits_by_alice_and_bob.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/notebooks/test_qaoa_maxcut.py b/tests/notebooks/test_qaoa_maxcut.py new file mode 100644 index 000000000..4e3245ac1 --- /dev/null +++ b/tests/notebooks/test_qaoa_maxcut.py @@ -0,0 +1,11 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("qaoa_maxcut", timeout_seconds=300) +def test_notebook(tb: TestbookNotebookClient) -> None: + pass # TODO diff --git a/tests/notebooks/test_rainbow_options_direct_method.py b/tests/notebooks/test_rainbow_options_direct_method.py new file mode 100644 index 000000000..86489b1dc --- /dev/null +++ b/tests/notebooks/test_rainbow_options_direct_method.py @@ -0,0 +1,11 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("rainbow_options_direct_method", timeout_seconds=1000) +def test_notebook(tb: TestbookNotebookClient) -> None: + pass # TODO diff --git a/tests/notebooks/test_rectangles_packing_grid.py b/tests/notebooks/test_rectangles_packing_grid.py new file mode 100644 index 000000000..82aa8c15b --- /dev/null +++ b/tests/notebooks/test_rectangles_packing_grid.py @@ -0,0 +1,11 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("rectangles_packing_grid", timeout_seconds=1800) +def test_notebook(tb: TestbookNotebookClient) -> None: + pass # TODO diff --git a/tests/notebooks/test_shor.py b/tests/notebooks/test_shor.py index afae17f56..e6670d196 100644 --- a/tests/notebooks/test_shor.py +++ b/tests/notebooks/test_shor.py @@ -19,24 +19,3 @@ def test_notebook(tb: TestbookNotebookClient) -> None: # test notebook content pass # TODO - - -@wrap_testbook("shor_modular_exponentiation", timeout_seconds=300) -def test_notebook(tb: TestbookNotebookClient) -> None: - # test models - validate_quantum_model(tb.ref("qmod_1")) - validate_quantum_model(tb.ref("qmod_2")) - # test quantum programs - validate_quantum_program_size( - tb.ref("qprog_1"), - expected_width=8, # actual width: 8 - expected_depth=300, # actual depth: 296 - ) - validate_quantum_program_size( - tb.ref("qprog_2"), - expected_width=22, # actual width: 22 - expected_depth=30000, # actual depth: 26607 - ) - - # test notebook content - pass # TODO diff --git a/tests/notebooks/test_shor_modular_exponentiation.py b/tests/notebooks/test_shor_modular_exponentiation.py new file mode 100644 index 000000000..3b18b9c19 --- /dev/null +++ b/tests/notebooks/test_shor_modular_exponentiation.py @@ -0,0 +1,27 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("shor_modular_exponentiation", timeout_seconds=300) +def test_notebook(tb: TestbookNotebookClient) -> None: + # test models + validate_quantum_model(tb.ref("qmod_1")) + validate_quantum_model(tb.ref("qmod_2")) + # test quantum programs + validate_quantum_program_size( + tb.ref("qprog_1"), + expected_width=8, # actual width: 8 + expected_depth=300, # actual depth: 296 + ) + validate_quantum_program_size( + tb.ref("qprog_2"), + expected_width=22, # actual width: 22 + expected_depth=30000, # actual depth: 26607 + ) + + # test notebook content + pass # TODO diff --git a/tests/notebooks/test_time_marching.py b/tests/notebooks/test_time_marching.py new file mode 100644 index 000000000..1e93a3c76 --- /dev/null +++ b/tests/notebooks/test_time_marching.py @@ -0,0 +1,11 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("time_marching", timeout_seconds=500) +def test_notebook(tb: TestbookNotebookClient) -> None: + pass # TODO diff --git a/tests/test_all_notebooks_are_tested.py b/tests/test_all_notebooks_are_tested.py new file mode 100644 index 000000000..76bcf7bc3 --- /dev/null +++ b/tests/test_all_notebooks_are_tested.py @@ -0,0 +1,22 @@ +import pytest +import os +from utils_for_tests import get_all_notebooks, ROOT_DIRECTORY, resolve_notebook_path + + +@pytest.mark.parametrize("notebook_name", map(os.path.basename, get_all_notebooks())) +def test_is_notebook_tested(notebook_name: str): + if not _should_skip_notebook(notebook_name): + expected_test_name = f"test_{notebook_name[:-6]}.py" # [:-6] removes ".ipynb" + assert list( + ROOT_DIRECTORY.rglob(expected_test_name) + ), f"No test was found for '{notebook_name}'. Expecting to find '{expected_test_name}'" + + +def _should_skip_notebook(notebook_name: str) -> bool: + notebook_path = resolve_notebook_path(notebook_name) + + return ( + "/functions/" in notebook_path + or "/community/" in notebook_path + or "/.ipynb_checkpoints/" in notebook_path + ) diff --git a/tests/utils_for_tests.py b/tests/utils_for_tests.py index 311f6397a..4fcdf6bf3 100644 --- a/tests/utils_for_tests.py +++ b/tests/utils_for_tests.py @@ -7,7 +7,7 @@ def iterate_notebooks() -> list[str]: if os.environ.get("SHOULD_TEST_ALL_FILES", "") == "true": - notebooks_to_test = _get_all_notebooks() + notebooks_to_test = get_all_notebooks() else: notebooks_to_test = os.environ.get("LIST_OF_IPYNB_CHANGED", "").split() @@ -19,8 +19,10 @@ def iterate_notebook_names() -> list[str]: return list(map(os.path.basename, iterate_notebooks())) +# do not use `get_all_notebooks` unless you're sure it's the right one. +# 95% of the tests would use `iterate_notebooks` @lru_cache -def _get_all_notebooks( +def get_all_notebooks( directory: Path = ROOT_DIRECTORY, suffix: str = ".ipynb" ) -> list[str]: return [