Skip to content

Commit

Permalink
Move skip to the test ; add caching
Browse files Browse the repository at this point in the history
  • Loading branch information
classiqdor committed Nov 14, 2024
1 parent ea0894e commit afdd9ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions tests/notebooks/algorithms/test_bernstein_vazirani.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
execute_testbook_with_timeout,
)
from testbook.client import TestbookNotebookClient # type: ignore[import]
from tests.utils.utils_for_tests import should_skip_notebook


@pytest.make.skipif(should_skip_notebook("bernstein_vazirani"))
@execute_testbook_with_timeout("bernstein_vazirani", timeout_seconds=20)
def test_bernstein_vazirani(tb: TestbookNotebookClient) -> None:
# test models
Expand Down
6 changes: 1 addition & 5 deletions tests/utils/utils_for_testbook.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import base64
import json
import os
import pytest
import pickle
import re
from typing import Any, Callable

from testbook import testbook # type: ignore[import]
from testbook.client import TestbookNotebookClient # type: ignore[import]
from tests.utils.utils_for_tests import resolve_notebook_path, should_test_notebook
from tests.utils.utils_for_tests import resolve_notebook_path

from classiq.interface.generator.quantum_program import QuantumProgram

Expand All @@ -19,9 +18,6 @@ def execute_testbook_with_timeout(
def inner_decorator(func: Callable) -> Any:
notebook_path = resolve_notebook_path(notebook_name)

if not should_test_notebook(notebook_path):
pytest.skip("Skipped")

for decorator in [
testbook(notebook_path, execute=True, timeout=timeout_seconds),
_build_cd_decorator(notebook_path),
Expand Down
16 changes: 11 additions & 5 deletions tests/utils/utils_for_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from functools import lru_cache
from collections.abc import Iterable
from pathlib import Path

Expand All @@ -14,17 +15,22 @@ def iterate_notebooks() -> Iterable[str]:
return notebooks_to_test


@lru_cache
def _get_all_notebooks(directory: Path = ROOT_DIRECTORY) -> Iterable[str]:
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".ipynb"):
yield os.path.join(root, file)
return [
file
for root, _, files in os.walk(directory)
for file in files
if file.endswith(".ipynb")
]


def should_test_notebook(notebook_path: str) -> bool:
def should_skip_notebook(notebook_name: str) -> bool:
notebook_path = resolve_notebook_path(notebook_name)
return notebook_path in list(iterate_notebooks())


@lru_cache
def resolve_notebook_path(notebook_name: str) -> str:
notebook_name_lower = notebook_name.lower()
if not notebook_name_lower.endswith(".ipynb"):
Expand Down

0 comments on commit afdd9ca

Please sign in to comment.