Skip to content

Commit

Permalink
Improve test and add tox
Browse files Browse the repository at this point in the history
- Isolation: Build test should not hit the internet now
- Add tox: Running from 3.8..3.12
- Fix incompat: 3.11/3.12 were complaining about RepoStatus dataclass
  • Loading branch information
pedro-psb committed Jan 16, 2024
1 parent 3324111 commit f678a19
Show file tree
Hide file tree
Showing 32 changed files with 34 additions and 18 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@ And thats it, the magic is done.

## Setup

Recommended of getting it up and running:
Recommended way for daily usage:

```bash
$ virtualenv --python python3.8 pulpdocs-venv
$ . pulpdocs-venv/bin/activate
$ pip install git+https://github.com/pedro-psb/pulp-docs
$ pulp-docs --help
$ pipx install git+https://github.com/pedro-psb/pulp-docs --include-deps
$ pulp-docs serve
```

Known issues:
- doesn't work with newer versions of python, like 3.12
- doesn't work with pipx (some problem with data assets packaging)

For development, use your prefered method!
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ pulp_docs = ["data/**"]
[tool.setuptools.packages.find]
where = ["src"]


19 changes: 11 additions & 8 deletions src/pulp_docs/plugin_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@
RESTAPI_TEMPLATE = "https://docs.pulpproject.org/{}/restapi.html"


@dataclass
# @dataclass # raising errors in py311/312
class RepoStatus:
"""
Usefull status information about a downloaded repository.
"""

download_source: t.Optional[str] = None
use_local_checkout: bool = False
has_readme: bool = True
has_changelog: bool = True
has_staging_docs: bool = True
using_cache: bool = False
original_refs: t.Optional[str] = None # as defined in repolist.yml
def __init__(self, **kwargs):
self.download_source = kwargs.get("download_source", None)
self.download_source = kwargs.get("download_source", None)
self.use_local_checkout = kwargs.get("use_local_checkout", False)
self.has_readme = kwargs.get("has_readme", True)
self.has_changelog = kwargs.get("has_changelog", True)
self.has_staging_docs = kwargs.get("has_staging_docs", True)
self.using_cache = kwargs.get("using_cache", False)
self.original_refs = kwargs.get("original_refs", None)


@dataclass
class Repo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ This is a landing page.
[:octicons-arrow-right-24: License](#)

</div>

9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import pytest
import subprocess
from click.testing import CliRunner

from pulp_docs.main import main
Expand All @@ -23,8 +24,16 @@ def test_trivial():


def test_build(tmp_path):
"""Sanity check build cmd"""
# setup folder structure so test uses local fixtures
fixture_path = Path("tests/fixtures/pulpcore").absolute()
dest_path = tmp_path / "workdir" / fixture_path.name
shutil.copytree(fixture_path, dest_path)
subprocess.run(["git", "-C", str(dest_path.absolute()), "init"])

runner = CliRunner()
with runner.isolated_filesystem(temp_dir=tmp_path):
os.chdir(dest_path) # using local checkout depends on cwd
result = runner.invoke(main, "build", env={"TMPDIR": str(tmp_path.absolute())})
assert result.exit_code == 0
assert Path("site").exists()
10 changes: 10 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tox]
requires =
tox>=4
env_list = py{38,39,310,311,312}

[testenv]
description = run tests
deps = pytest
commands =
pytest {posargs:tests}

0 comments on commit f678a19

Please sign in to comment.