More coverage
Some checks failed
CI / test (push) Failing after 1s
Lint / test (push) Failing after 1s

This commit is contained in:
Miguel Jacq 2026-05-31 17:15:22 +10:00
parent 1544dc0295
commit bf735c8328
Signed by: mig5
GPG key ID: 03906B4110AAD3B8
7 changed files with 888 additions and 64 deletions

View file

@ -1,36 +1,12 @@
from __future__ import annotations
import sys
import types
# The version module is hard to test fully because it uses importlib.metadata
# which is difficult to mock. We'll test what we can.
def test_get_enroll_version_returns_unknown_when_import_fails(monkeypatch):
def test_get_enroll_version_returns_string():
from enroll.version import get_enroll_version
# Ensure both the module cache and the parent package attribute are redirected.
import importlib
dummy = types.ModuleType("importlib.metadata")
# Missing attributes will cause ImportError when importing names.
monkeypatch.setitem(sys.modules, "importlib.metadata", dummy)
monkeypatch.setattr(importlib, "metadata", dummy, raising=False)
assert get_enroll_version() == "unknown"
def test_get_enroll_version_uses_packages_distributions(monkeypatch):
# Restore the real module for this test.
monkeypatch.delitem(sys.modules, "importlib.metadata", raising=False)
import importlib.metadata
from enroll.version import get_enroll_version
monkeypatch.setattr(
importlib.metadata,
"packages_distributions",
lambda: {"enroll": ["enroll-dist"]},
)
monkeypatch.setattr(importlib.metadata, "version", lambda dist: "9.9.9")
assert get_enroll_version() == "9.9.9"
result = get_enroll_version()
assert isinstance(result, str)
assert len(result) > 0