-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds tests for the code blocks in the README and our user guides. Also, fixes one bug that got unveiled.
- Loading branch information
Showing
8 changed files
with
60 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Test the code provided in the docs.""" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from .utils import extract_code_blocks | ||
|
||
|
||
def test_readme(): | ||
"""The blocks in the README become a valid python script when concatenated.""" | ||
readme_code = extract_code_blocks("README.md") | ||
exec(readme_code) | ||
|
||
|
||
@pytest.mark.parametrize("file", Path("docs/userguide/").rglob("*.md")) | ||
def test_userguide(file: Path): | ||
"""The blocks in the user guide become a valid python script when concatenated.""" | ||
userguide_code = extract_code_blocks(file) | ||
exec(userguide_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Test if all examples can be run without error.""" | ||
|
||
import runpy | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from baybe.surrogates import _ONNX_INSTALLED | ||
from baybe.utils.chemistry import _MORDRED_INSTALLED, _RDKIT_INSTALLED | ||
|
||
_CHEM_INSTALLED = _MORDRED_INSTALLED and _RDKIT_INSTALLED | ||
|
||
|
||
@pytest.mark.slow | ||
@pytest.mark.skipif( | ||
not (_CHEM_INSTALLED and _ONNX_INSTALLED), reason="skipped for core tests" | ||
) | ||
@pytest.mark.parametrize("example", Path("examples/").rglob("*.py")) | ||
def test_example(example: Path): | ||
"""Test an individual example by running it.""" | ||
runpy.run_path(str(example)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Utilities for doc testing.""" | ||
|
||
import re | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
|
||
def extract_code_blocks(path: Union[str, Path]) -> str: | ||
"""Extract all python code blocks from the specified file into a single string.""" | ||
contents = Path(path).read_text() | ||
code_blocks = re.findall(r"```python\s+(.*?)\s+```", contents, flags=re.DOTALL) | ||
concatenated_code = "\n".join(code_blocks) | ||
|
||
return concatenated_code |
This file was deleted.
Oops, something went wrong.