"""Empreinte des fichiers statiques (paramètre ?v=).""" from __future__ import annotations import re import shortstats from shortstats.web import templating from shortstats.web.templating import assets_version def test_assets_version_follows_content(tmp_path, monkeypatch): (tmp_path / "app.js").write_text("console.log(1);") (tmp_path / "vendor").mkdir() (tmp_path / "vendor" / "lib.js").write_text("x") before = assets_version(tmp_path) assert re.fullmatch(r"[0-9a-f]{16}", before) and before == assets_version(tmp_path) # le numéro de version n'y entre pas monkeypatch.setattr(templating, "__version__", "0+autre") monkeypatch.setattr(shortstats, "__version__", "0+autre") assert assets_version(tmp_path) == before (tmp_path / "app.js").write_text("console.log(2);") changed = assets_version(tmp_path) assert changed != before (tmp_path / "vendor" / "lib.js").write_text("y") assert assets_version(tmp_path) != changed changed = assets_version(tmp_path) (tmp_path / "vendor" / "lib.js").rename(tmp_path / "vendor" / "lib2.js") # même contenu, autre nom assert assets_version(tmp_path) != changed