Skip to content
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
11 changes: 11 additions & 0 deletions tests/notebooks/test_hhl_lanchester.py
Original file line number Diff line number Diff line change
@@ -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
Empty file.
11 changes: 11 additions & 0 deletions tests/notebooks/test_qaoa_maxcut.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/notebooks/test_rainbow_options_direct_method.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/notebooks/test_rectangles_packing_grid.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 0 additions & 21 deletions tests/notebooks/test_shor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions tests/notebooks/test_shor_modular_exponentiation.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/notebooks/test_time_marching.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions tests/test_all_notebooks_are_tested.py
Original file line number Diff line number Diff line change
@@ -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
)
6 changes: 4 additions & 2 deletions tests/utils_for_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 [
Expand Down