11from __future__ import annotations
22
3+ import re
34import unittest
5+ from datetime import date
46from importlib .metadata import version
57from pathlib import Path
68
79import pyiecwind
810from pyiecwind import VERSION , models
911
1012
13+ def _cff_field (name : str ) -> str :
14+ """Return the value of a top-level scalar field in CITATION.cff.
15+
16+ Parsed with a regex so the test needs no YAML dependency; the file is a flat
17+ list of ``key: value`` pairs, so this is sufficient and dependency-free.
18+ """
19+
20+ root = Path (__file__ ).resolve ().parents [1 ]
21+ text = (root / "CITATION.cff" ).read_text (encoding = "utf-8" )
22+ match = re .search (rf"^{ re .escape (name )} :\s*(.+?)\s*$" , text , re .MULTILINE )
23+ assert match is not None , f"CITATION.cff is missing a '{ name } ' field"
24+ return match .group (1 ).strip ().strip ('"' ).strip ("'" )
25+
26+
1127class VersionTests (unittest .TestCase ):
1228 """Guard against the historical drift where models.py hardcoded a version
1329 (1.0.0) different from the one declared in pyproject.toml (0.1.0)."""
@@ -31,6 +47,18 @@ def test_pyproject_version_matches_installed_metadata(self) -> None:
3147 data = tomllib .loads ((root / "pyproject.toml" ).read_text (encoding = "utf-8" ))
3248 self .assertEqual (data ["project" ]["version" ], version ("pyiecwind" ))
3349
50+ def test_citation_version_matches_installed_metadata (self ) -> None :
51+ # CITATION.cff is hand-maintained YAML, not single-sourced like the
52+ # package version; this guard fails the build if it drifts behind a release.
53+ self .assertEqual (_cff_field ("version" ), version ("pyiecwind" ))
54+
55+ def test_citation_release_date_is_iso (self ) -> None :
56+ released = _cff_field ("date-released" )
57+ try :
58+ date .fromisoformat (released )
59+ except ValueError :
60+ self .fail (f"CITATION.cff date-released { released !r} is not an ISO YYYY-MM-DD date" )
61+
3462
3563if __name__ == "__main__" :
3664 unittest .main ()
0 commit comments