Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tester not working #10

Merged
merged 4 commits into from
Sep 9, 2024
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
2 changes: 0 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.10"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# NOTE: This also serves as a test for the action.
- name: Docs
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ runs:

- name: Install
run: |
pip install git+https://github.com/ApeWorX/sphinx-ape.git@main
pip install sphinx-ape
shell: bash

- name: Build Docs
Expand Down
7 changes: 7 additions & 0 deletions codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: "Ape CodeQL config"

queries:
- uses: security-and-quality

paths:
- sphinx_ape
5 changes: 5 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
extensions = ["sphinx_ape"]

doctest_global_setup = """
from sphinx_ape.build import BuildMode, DocumentationBuilder
from pathlib import Path
"""
3 changes: 2 additions & 1 deletion sphinx_ape/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def extract_package_name(directory: Optional[Path] = None) -> str:
if pkg_name is None and (directory / "pyproject.toml").is_file():
pkg_name = _extract_name_from_pyproject_toml(directory / "pyproject.toml")
if pkg_name is None:
raise ApeDocsBuildError("No package name found.")
path = f"{directory}".replace(f"{Path.home()}", "$HOME")
raise ApeDocsBuildError(f"No package name found at '{path}'.")

return PACKAGE_ALIASES.get(pkg_name, pkg_name)

Expand Down
4 changes: 1 addition & 3 deletions sphinx_ape/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ def build(self):
Build the documentation.

Example:
>>> from sphinx_ape.build import BuildMode, DocumentationBuilder
>>> from pathlib import Path
>>> builder = DocumentationBuilder(
... mode=BuildMode.LATEST,
... base_path=Path("."),
... base_path=Path.cwd(),
... name="sphinx-ape"
... )
>>> builder.build()
Expand Down
30 changes: 19 additions & 11 deletions sphinx_ape/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ class DocumentationTester(Documentation):
Small wrapper around sphinx-build's doctest command.
"""

@property
def doctest_folder(self) -> Path:
"""
The path to doctest's build folder.
"""
return self.build_path.parent / "doctest"

@property
def doctest_output_file(self) -> Path:
"""
The path to doctest's output file.
"""
return self.build_path.parent / "doctest" / "output.txt"
return self.doctest_folder / "output.txt"

def test(self):
"""
Expand All @@ -24,18 +31,19 @@ def test(self):
Raises:
:class:`~sphinx_ape.exceptions.ApeDocsTestError`
"""
try:
subprocess.run(
["sphinx-build", "-b", "doctest", "docs", "docs/_build/doctest"], check=True
)
except subprocess.CalledProcessError as err:
raise ApeDocsBuildError(str(err)) from err

if self.doctest_output_file.is_file():
return

self._run_tests()
output = self.doctest_output_file.read_text() if self.doctest_output_file.is_file() else ""
if "0 failed" in output or "0 tests" in output:
# Either no failures or no tests ran.
return

# Failures.
raise ApeDocsTestError(output)

def _run_tests(self):
try:
subprocess.run(
["sphinx-build", "-b", "doctest", "docs", str(self.doctest_folder)], check=True
)
except subprocess.CalledProcessError as err:
raise ApeDocsBuildError(str(err)) from err
10 changes: 10 additions & 0 deletions tests/test_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pathlib import Path

from sphinx_ape.testing import DocumentationTester


class TestDocumentationTester:
def test_test(self, temp_path):
tester = DocumentationTester(base_path=Path(__file__).parent.parent)
tester.test()
assert tester.doctest_output_file.is_file()