generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
172 additions
and
39 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
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,10 @@ | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def temp_path(): | ||
with tempfile.TemporaryDirectory() as temp: | ||
yield Path(temp).resolve() |
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,72 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from sphinx_ape.build import BuildMode, DocumentationBuilder | ||
|
||
|
||
class TestBuildMode: | ||
@pytest.mark.parametrize("val", ("latest", 0, "pull_request", "buildmode.latest")) | ||
def test_init_latest(self, val): | ||
mode = BuildMode.init("val") | ||
assert mode is BuildMode.LATEST | ||
|
||
@pytest.mark.parametrize("val", ("release", 1, "buildmode.release")) | ||
def test_init_release(self, val): | ||
mode = BuildMode.init(val) | ||
assert mode is BuildMode.RELEASE | ||
|
||
|
||
class TestDocumentationBuilder: | ||
@pytest.fixture(autouse=True) | ||
def mock_sphinx(self, mocker): | ||
def run_mock_sphinx(path, *args, **kwargs): | ||
path.mkdir(parents=True) | ||
buildfile = path / "build.txt" | ||
buildfile.touch() | ||
|
||
mock = mocker.patch("sphinx_ape.build.sphinx_build") | ||
mock.side_effect = run_mock_sphinx | ||
return mock | ||
|
||
@pytest.fixture(autouse=True) | ||
def mock_git(self, mocker): | ||
return mocker.patch("sphinx_ape.build.git") | ||
|
||
def test_build_latest(self, mock_sphinx, temp_path): | ||
builder = DocumentationBuilder(mode=BuildMode.LATEST, base_path=temp_path) | ||
builder.build() | ||
call_path = mock_sphinx.call_args[0][0] | ||
self.assert_build_path(call_path, "latest") | ||
|
||
def test_build_release(self, mock_sphinx, mock_git, temp_path): | ||
tag = "v1.0.0" | ||
mock_git.return_value = tag | ||
builder = DocumentationBuilder(mode=BuildMode.RELEASE, base_path=temp_path) | ||
builder.build() | ||
call_path = mock_sphinx.call_args[0][0] | ||
self.assert_build_path(call_path, tag) | ||
# Latest and Stable should also have been created! | ||
self.assert_build_path(call_path.parent / "latest", "latest") | ||
self.assert_build_path(call_path.parent / "stable", "stable") | ||
|
||
@pytest.mark.parametrize("sub_tag", ("alpha", "beta")) | ||
def test_build_alpha_release(self, sub_tag, mock_sphinx, mock_git, temp_path): | ||
""" | ||
We don't build version releases when using alpha or beta, but we | ||
still update "stable" and "latest". | ||
""" | ||
tag = f"v1.0.0{sub_tag}" | ||
mock_git.return_value = tag | ||
builder = DocumentationBuilder(mode=BuildMode.RELEASE, base_path=temp_path) | ||
builder.build() | ||
call_path = mock_sphinx.call_args[0][0] | ||
self.assert_build_path(call_path, "stable") | ||
# Latest should also have been created! | ||
self.assert_build_path(call_path.parent / "latest", "latest") | ||
|
||
def assert_build_path(self, path: Path, expected: str): | ||
assert path.name == expected # Tag, latest, or stable | ||
assert path.parent.name == "sphinx-ape" # Project name, happens to be this lib | ||
assert path.parent.parent.name == "_build" # Sphinx-ism | ||
assert path.parent.parent.parent.name == "docs" # Sphinx-ism |
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,27 @@ | ||
from sphinx_ape.utils import extract_package_name | ||
|
||
|
||
def test_extract_package_name_setup_py(temp_path): | ||
setup_py = temp_path / "setup.py" | ||
name = "ape-myplugin" | ||
content = f""" | ||
#!/usr/bin/env python | ||
from setuptools import find_packages, setup | ||
extras_require = {{ | ||
"test": [ # `test` GitHub Action jobs uses this | ||
"pytest>=6.0", # Core testing package | ||
], | ||
}} | ||
setup( | ||
name="{name}", | ||
classifiers=[ | ||
"Development Status :: 5 - Production/Stable", | ||
"Programming Language :: Python :: 3.12", | ||
], | ||
) | ||
""" | ||
setup_py.write_text(content) | ||
|
||
actual = extract_package_name(temp_path) | ||
assert actual == name |