More test coverage (71%)
This commit is contained in:
parent
9a2516d858
commit
f82fd894ca
8 changed files with 605 additions and 10 deletions
31
tests/test_fsutil_extra.py
Normal file
31
tests/test_fsutil_extra.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_stat_triplet_falls_back_to_numeric_ids(tmp_path: Path, monkeypatch):
|
||||
"""If uid/gid cannot be resolved, stat_triplet should return numeric strings."""
|
||||
from enroll.fsutil import stat_triplet
|
||||
|
||||
p = tmp_path / "f"
|
||||
p.write_text("x", encoding="utf-8")
|
||||
os.chmod(p, 0o644)
|
||||
|
||||
import grp
|
||||
import pwd
|
||||
|
||||
def _no_user(_uid): # pragma: no cover - executed via monkeypatch
|
||||
raise KeyError
|
||||
|
||||
def _no_group(_gid): # pragma: no cover - executed via monkeypatch
|
||||
raise KeyError
|
||||
|
||||
monkeypatch.setattr(pwd, "getpwuid", _no_user)
|
||||
monkeypatch.setattr(grp, "getgrgid", _no_group)
|
||||
|
||||
owner, group, mode = stat_triplet(str(p))
|
||||
|
||||
assert owner.isdigit()
|
||||
assert group.isdigit()
|
||||
assert mode == "0644"
|
||||
Loading…
Add table
Add a link
Reference in a new issue