Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add html-snapshot testing with basic fixture
Browse files Browse the repository at this point in the history
pedro-psb committed Oct 11, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
joehendrix Joe Hendrix
1 parent caf2e15 commit b8ed486
Showing 4 changed files with 107 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pulp_docs/main.py
Original file line number Diff line number Diff line change
@@ -85,7 +85,10 @@ def serve(self, config: Config, dry_run: bool = False):
return
subprocess.run(cmd, env=env)

def build(self, config: Config, dry_run: bool = False):
def build(
self, config: Config, dry_run: bool = False, target: t.Optional[Path] = None
):
# TODO: implement target
# Process option to pass to command
cmd = ["mkdocs", "build"]

46 changes: 46 additions & 0 deletions src/pulp_docs/test_tools/snapshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from pathlib import Path
from pulp_docs.main import PulpDocs, Config


def snapshot_fixture(fixture_dir: Path, repolist: Path, target: Path) -> Path:
"""Builds snapshot of the fixture-docs using @fixture_dir and @repolist at @target.
The snapshot should be taken after someone carefully inspect the core elements of
the site looks as expected, like:
* Navigation display: nav items that should and shouldnt be there.
* Special pages behave as expected, like RestAPI, Changes and index pages.
* Regular pages exists (or dont exist) where expected inside plugins and sections.
The snapshot is not intended to provide a 1:1 comparision, but more of a structural
comparision, so at least we catch obivous structural regressions.
Params:
fixture_dir: A dir which should contain `{repository_name}/{repository_tree}`
repolist: A yaml file containing the aggregation config.
target: Dir where to write the build.
Returns:
The Path of the new snapshot. The dirname is commit hash at the moment of the
which snapshot.
"""
# Guards to avoid surprises
if not fixture_dir.is_dir():
raise ValueError(f"'fixture_dir' should be a dir: {fixture_dir}")
if not list(fixture_dir.iterdir()):
raise ValueError(f"'fixture_dir' should NOT be empty.: {fixture_dir}")

if not target.is_dir():
raise ValueError(f"'fixture_dir' should be a dir: {target}")
if list(fixture_dir.iterdir()):
raise ValueError(f"'target' must be empty.: {target}")

if repolist.suffix not in (".yml", "yaml"):
raise ValueError(f"'repolist' must be a YAML file: {repolist.name}")

# TODO: test this.
config = Config()
config.repolist = repolist.absolute()
pulp_docs = PulpDocs(config)
pulp_docs.build(target=target)

return Path()
47 changes: 47 additions & 0 deletions tests/doctrees/pulpcore_only.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
################
### PULPCORE ###
################
# Minimal setup with pulpcore only.

[[ pulpcore ]]

path = 'pulpcore/CHANGES.md'
data = '''
# Changelog
## x.y.z (YYYY-MM-DD)
#### Features
- feature-changes-check
#### Bugfixes
- bugfixes-changes-check
'''

[[ pulpcore ]]

path = 'pulpcore/index.md'
data = '''
# Welcome to Pulpcore
pulpcore-index-check
'''

[[ pulpcore ]]

path = 'pulpcore/guides/guides1.md'
data = '''
# Guide1
guide1-check
'''

[[ pulpcore ]]

path = 'pulpcore/guides/guides2.md'

data = '''
# Guide2
guide2-check
'''
10 changes: 10 additions & 0 deletions tests/test_fixture_snapshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pulp_docs.test_tools.snapshot import snapshot_fixture
from pathlib import Path


def test_snapshot_fixture(tmp_path):
"""Test that using different fixture_dir or repolist the snapshot is different."""
fixture_dir = Path()
target = Path()
repolist = Path()
dirname = snapshot_fixture(fixture_dir, repolist, target)

0 comments on commit b8ed486

Please sign in to comment.