Files
Reithan-negative_rejection_…/tests/test_version.py
T
Reithan 950b55df5f Add __version__, patch-time version+pred-type log, platform-agnostic issue template (#39)
## What
Groundwork folded ahead of the held v1.0.0 release (publish-neutral —
**`pyproject.toml` is untouched**, so this does not trigger the registry
auto-publish):

1. **`NRS.__version__`** — added `__version__ = "0.7.4"` (mirrors the
current `pyproject.toml` version) in `NRS/nodes_NRS.py`, re-exported
from a new `NRS/__init__.py` so `NRS.__version__` is importable.
Commented to bump both together at release.
2. **Patch-time log line** — `patch()` now emits, right after
prediction-type detection:
`logging.info(f"NRS v{__version__}: prediction type detected ->
{pred_type.name}")`
So a user's console shows which NRS version ran and which prediction
space it selected (the key diagnostic for the flow-family
reclassification).
3. **GitHub bug-report issue form** —
`.github/ISSUE_TEMPLATE/bug_report.yml` + `config.yml`. Captures the NRS
version + detected prediction type (from the new log line),
model/sampler family, skew/stretch/squash values, expected vs actual,
repro, and console log.
- **Platform-agnostic:** NRS ships for ComfyUI *and* the A1111 family,
so the form has a **Platform / UI** dropdown — `ComfyUI, AUTOMATIC1111,
Forge, reForge, Forge Neo, Stability Matrix, Other` — with a free-text
follow-up and a generic "Platform version" field (no ComfyUI-only
wording).

## Tests
`tests/test_version.py`: asserts `NRS.__version__` is a valid `X.Y.Z`
string, matches `pyproject.toml` (catches future drift), and (via
`caplog`) that `patch()` emits the exact version + pred-type log line.

## Notes
- Adding `NRS/__init__.py` turned `NRS` from an implicit namespace
package into a real package, which newly triggered ruff's `N999` on the
pre-existing mixed-case filename `nodes_NRS.py`. Since `pyproject.toml`
is off-limits here, it's suppressed with an in-file `# ruff: noqa: N999`
pragma (with an explanatory comment) — consistent with the existing
per-file `N802/N804` carve-out for that same file. Renaming the file is
out of scope (breaks imports).

## Validation
- `ruff check .` → clean.
- `pytest --cov=NRS --cov-branch` → **45 passed** (42 + 3 new).
- diff-cover branch gate (mirrors CI) → **100%** on changed code.
- `pyproject.toml` / `uv.lock` untouched; issue-form YAML validated with
`yaml.safe_load`.
2026-08-14 02:24:47 -07:00

55 lines
1.8 KiB
Python

"""Tests for NRS package version metadata and the patch()-time version/pred-type log line."""
import re
import sys
from pathlib import Path
# Add project root to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent))
import NRS # noqa: E402
import NRS.nodes_NRS as nodes_NRS # noqa: E402, N812
_SEMVER_RE = re.compile(r"^\d+\.\d+\.\d+$")
def test_version_is_nonempty_semver_string():
"""NRS.__version__ must be importable and look like a X.Y.Z version."""
assert isinstance(NRS.__version__, str)
assert NRS.__version__
assert _SEMVER_RE.match(NRS.__version__), f"__version__ {NRS.__version__!r} is not X.Y.Z"
def test_version_matches_pyproject():
"""__version__ must be kept in lock-step with pyproject.toml's version field."""
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"
text = pyproject_path.read_text()
match = re.search(r'(?m)^version\s*=\s*"([^"]+)"', text)
assert match, "Could not find version in pyproject.toml"
assert NRS.__version__ == match.group(1)
class _StubModel:
"""Minimal stand-in that resolves to PredictionType.EPS via the direct-hit path."""
def __init__(self):
self.model_type = "eps"
def clone(self):
return self
def set_model_sampler_cfg_function(self, fn, flag):
self._captured_fn = fn
def test_patch_logs_version_and_pred_type(caplog):
"""patch() must announce the NRS version and detected prediction type."""
node = nodes_NRS.NRS()
model = _StubModel()
with caplog.at_level("INFO"):
node.patch(model, skew=2.0, stretch=5.0, squash=0.75)
expected = f"NRS v{NRS.__version__}: prediction type detected -> {nodes_NRS.PredictionType.EPS.name}"
assert any(expected in rec.message for rec in caplog.records)