Files
EnvBao/tests/test_version_script.py
T
mattandClaude Sonnet 5.5 d5636c46c7
test / test (push) Failing after 2s
release / validate (push) Successful in 2s
release / build (linux-amd64, linux-amd64) (push) Successful in 38s
release / build (macos-arm64, macos-arm64) (push) Successful in 45s
release / build (linux-arm64, linux-arm64) (push) Successful in 1m19s
release / release (push) Successful in 15s
Initial implementation of EnvBao
Single-binary CLI that injects environment variables from an OpenBao
server into the shell via eval "$(envbao)".

- Strict permission policy for ~/.envbao (exits 78 if unsafe)
- KV v1/v2 engine with auto-detection, pluggable engine registry
- Safe quoting for bash/zsh/sh/fish, protected-variable denylist
- Audit logging (stderr, private rotating file, syslog); no secrets logged
- Gitea pipelines for tests and SemVer-tag releases
- PyInstaller spec, docs, BSD-3-Clause licence

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 21:20:15 +01:00

72 lines
1.8 KiB
Python

import importlib.util
from pathlib import Path
import pytest
_spec = importlib.util.spec_from_file_location(
"version_from_tag", Path(__file__).parent.parent / "scripts" / "version_from_tag.py"
)
assert _spec and _spec.loader
vft = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(vft)
@pytest.mark.parametrize(
"tag, version",
[
("v0.0.1", "0.0.1"),
("v1.2.3", "1.2.3"),
("v10.20.30", "10.20.30"),
("v1.0.0-rc.1", "1.0.0-rc.1"),
("v1.0.0-alpha+001", "1.0.0-alpha+001"),
("v1.0.0+20130313144700", "1.0.0+20130313144700"),
],
)
def test_valid_tags(tag: str, version: str) -> None:
assert vft.parse_tag(tag) == version
@pytest.mark.parametrize(
"tag",
[
"1.2.3",
"v1.2",
"v01.2.3",
"v1.2.3.4",
"v1.2.3-",
"v1.2.3-01",
"latest",
"",
"v1.2.3 ",
"V1.2.3",
],
)
def test_invalid_tags(tag: str) -> None:
with pytest.raises(ValueError, match="not a valid semver"):
vft.parse_tag(tag)
def test_main_writes_version(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
target = tmp_path / "_version.py"
monkeypatch.setattr(vft, "VERSION_FILE", target)
assert vft.main(["x", "v2.0.1"]) == 0
assert '__version__ = "2.0.1"' in target.read_text()
assert capsys.readouterr().out == "2.0.1\n"
def test_write_version_real(tmp_path: Path) -> None:
target = tmp_path / "v.py"
vft.write_version("3.1.4", target)
assert "Overwritten" in target.read_text() and '"3.1.4"' in target.read_text()
def test_main_rejects_bad_tag(capsys: pytest.CaptureFixture[str]) -> None:
assert vft.main(["x", "nope"]) == 1
assert "not a valid semver" in capsys.readouterr().err
def test_main_usage() -> None:
assert vft.main(["x"]) == 2