From d713d8e76ad36d7db89d78e57731b3e381ad3023 Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 13:31:54 +0100 Subject: [PATCH 01/10] Move example tests to docs subfolder --- ruff.toml | 1 + tests/docs/__init__.py | 0 tests/{ => docs}/test_examples.py | 0 3 files changed, 1 insertion(+) create mode 100644 tests/docs/__init__.py rename tests/{ => docs}/test_examples.py (100%) diff --git a/ruff.toml b/ruff.toml index 9596402ed..6add2d104 100644 --- a/ruff.toml +++ b/ruff.toml @@ -26,6 +26,7 @@ extend-ignore = [ "baybe/exceptions.py" = ["D205", "D212", "D415"] # Missing module docstrings in module/package "tests/__init__.py" = ["D100", "D104"] +"tests/docs/__init__.py" = ["D100", "D104"] "tests/serialization/__init__.py" = ["D100", "D104"] "tests/validation/__init__.py" = ["D100", "D104"] "docs/conf.py" = ["D100"] diff --git a/tests/docs/__init__.py b/tests/docs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_examples.py b/tests/docs/test_examples.py similarity index 100% rename from tests/test_examples.py rename to tests/docs/test_examples.py From 1c0801333dc4f224c710fa6103f4f95153270317 Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 13:32:20 +0100 Subject: [PATCH 02/10] Add test for README code blocks --- tests/docs/test_readme.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/docs/test_readme.py diff --git a/tests/docs/test_readme.py b/tests/docs/test_readme.py new file mode 100644 index 000000000..18744b2de --- /dev/null +++ b/tests/docs/test_readme.py @@ -0,0 +1,20 @@ +"""Test the code provided in the README.""" + +import re + + +def extract_code_blocks(filename: str) -> str: + """Extract all python code blocks from the specified file into a single string.""" + with open(filename, "r") as file: + contents = file.read() + + code_blocks = re.findall(r"```python\s+(.*?)\s+```", contents, flags=re.DOTALL) + concatenated_code = "\n".join(code_blocks) + + return concatenated_code + + +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) From f28c4f861dd5638a66a106f45ea1a524ac825562 Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 13:56:59 +0100 Subject: [PATCH 03/10] Move code block extraction to utilities module --- tests/docs/test_readme.py | 13 +------------ tests/docs/utils.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 tests/docs/utils.py diff --git a/tests/docs/test_readme.py b/tests/docs/test_readme.py index 18744b2de..0929269cd 100644 --- a/tests/docs/test_readme.py +++ b/tests/docs/test_readme.py @@ -1,17 +1,6 @@ """Test the code provided in the README.""" -import re - - -def extract_code_blocks(filename: str) -> str: - """Extract all python code blocks from the specified file into a single string.""" - with open(filename, "r") as file: - contents = file.read() - - code_blocks = re.findall(r"```python\s+(.*?)\s+```", contents, flags=re.DOTALL) - concatenated_code = "\n".join(code_blocks) - - return concatenated_code +from .utils import extract_code_blocks def test_readme(): diff --git a/tests/docs/utils.py b/tests/docs/utils.py new file mode 100644 index 000000000..cb3c022bb --- /dev/null +++ b/tests/docs/utils.py @@ -0,0 +1,14 @@ +"""Utilities for doc testing.""" + +import re + + +def extract_code_blocks(filename: str) -> str: + """Extract all python code blocks from the specified file into a single string.""" + with open(filename, "r") as file: + contents = file.read() + + code_blocks = re.findall(r"```python\s+(.*?)\s+```", contents, flags=re.DOTALL) + concatenated_code = "\n".join(code_blocks) + + return concatenated_code From 2812bf5e8e2b9c8a44dfb6d2579bfe69fb9985ae Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 14:18:40 +0100 Subject: [PATCH 04/10] Use path objects --- tests/docs/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/docs/utils.py b/tests/docs/utils.py index cb3c022bb..83f9bca5f 100644 --- a/tests/docs/utils.py +++ b/tests/docs/utils.py @@ -1,13 +1,13 @@ """Utilities for doc testing.""" import re +from pathlib import Path +from typing import Union -def extract_code_blocks(filename: str) -> str: +def extract_code_blocks(path: Union[str, Path]) -> str: """Extract all python code blocks from the specified file into a single string.""" - with open(filename, "r") as file: - contents = file.read() - + contents = Path(path).read_text() code_blocks = re.findall(r"```python\s+(.*?)\s+```", contents, flags=re.DOTALL) concatenated_code = "\n".join(code_blocks) From 888ab3c9e0d36c191b54e3fc96c7d1a762096326 Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 14:19:07 +0100 Subject: [PATCH 05/10] Add tests for user guide pages --- tests/docs/test_docs.py | 20 ++++++++++++++++++++ tests/docs/test_readme.py | 9 --------- 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 tests/docs/test_docs.py delete mode 100644 tests/docs/test_readme.py diff --git a/tests/docs/test_docs.py b/tests/docs/test_docs.py new file mode 100644 index 000000000..613048575 --- /dev/null +++ b/tests/docs/test_docs.py @@ -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) diff --git a/tests/docs/test_readme.py b/tests/docs/test_readme.py deleted file mode 100644 index 0929269cd..000000000 --- a/tests/docs/test_readme.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Test the code provided in the README.""" - -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) From 2ed2b4bdfd4e0ed441158777864f3d2f5e82112d Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 14:20:31 +0100 Subject: [PATCH 06/10] Fix operator in constraints user guide --- docs/userguide/constraints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/constraints.md b/docs/userguide/constraints.md index bc5202b9a..4488c6949 100644 --- a/docs/userguide/constraints.md +++ b/docs/userguide/constraints.md @@ -99,7 +99,7 @@ from baybe.constraints import ThresholdCondition ThresholdCondition( # will select all values above 150 threshold = 150, - operator = ">", + operator = "=", tolerance = 0.2 # optional, with this 149.82 would still be valid ) ``` From a3df853f54bbf0f8f0b1f25bb04f964cc36938cb Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 14:38:52 +0100 Subject: [PATCH 07/10] Clean up example tests --- tests/docs/test_examples.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/docs/test_examples.py b/tests/docs/test_examples.py index 49453d6b4..b426843f8 100644 --- a/tests/docs/test_examples.py +++ b/tests/docs/test_examples.py @@ -11,15 +11,11 @@ _CHEM_INSTALLED = _MORDRED_INSTALLED and _RDKIT_INSTALLED -example_list = list(Path(".").glob("examples/*/*.py")) - -EXAMPLES = [str(file) for file in example_list] - - -if _CHEM_INSTALLED and _ONNX_INSTALLED: - - @pytest.mark.slow - @pytest.mark.parametrize("example", EXAMPLES) - def test_example(example: str): - """Test an individual example by running it.""" - runpy.run_path(example) +@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: str): + """Test an individual example by running it.""" + runpy.run_path(example) From ee9fc6c68390444935b93374ce031116f6aeae6f Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 11 Dec 2023 14:40:40 +0100 Subject: [PATCH 08/10] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 112e4734e..1f537f4e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Target enums - `mypy` for targets and intervals +- Tests for code blocks in README and user guides ### Changed - Renamed `bounds_transform_func` target attribute to `transformation` - `Interval.is_bounded` now implements the mathematical definition of boundedness - Moved and renamed target transform utility functions +### Fixed +- Wrong threshold operator in constraints user guide + ### Removed - Conda install instructions and version badge From 5fc1d330e8faf03d6e6d04720cbd88f7f0800f8b Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 18 Dec 2023 09:22:37 +0100 Subject: [PATCH 09/10] Remove tolerance argument in constraints user guide example --- CHANGELOG.md | 2 +- docs/userguide/constraints.md | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f537f4e6..b2a3a5bc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved and renamed target transform utility functions ### Fixed -- Wrong threshold operator in constraints user guide +- Wrong use of `tolerance` argument in constraints user guide ### Removed - Conda install instructions and version badge diff --git a/docs/userguide/constraints.md b/docs/userguide/constraints.md index 4488c6949..ca6c1efe5 100644 --- a/docs/userguide/constraints.md +++ b/docs/userguide/constraints.md @@ -99,8 +99,7 @@ from baybe.constraints import ThresholdCondition ThresholdCondition( # will select all values above 150 threshold = 150, - operator = "=", - tolerance = 0.2 # optional, with this 149.82 would still be valid + operator = ">", ) ``` From 9a82e615a833c38fe37170b4064653bf85c9e5e4 Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Mon, 18 Dec 2023 09:44:06 +0100 Subject: [PATCH 10/10] Fix path in example tests --- tests/docs/test_examples.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/docs/test_examples.py b/tests/docs/test_examples.py index b426843f8..737573ac2 100644 --- a/tests/docs/test_examples.py +++ b/tests/docs/test_examples.py @@ -16,6 +16,6 @@ not (_CHEM_INSTALLED and _ONNX_INSTALLED), reason="skipped for core tests" ) @pytest.mark.parametrize("example", Path("examples/").rglob("*.py")) -def test_example(example: str): +def test_example(example: Path): """Test an individual example by running it.""" - runpy.run_path(example) + runpy.run_path(str(example))