Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions tests/testPackageMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,43 @@
REPO_ROOT = Path(__file__).resolve().parent.parent


# A release, or a PEP 440 pre-release of one: `RELEASING.md` tags a candidate `vX.Y.Zrc1` and
# the release workflow refuses a tag that does not match `__version__`, so the version carries
# the suffix for as long as the candidate is the tip.
RELEASE_VERSION = re.compile(r"^(?P<release>\d+\.\d+\.\d+)(?P<pre>(?:a|b|rc)\d+)?$")


def _version_tuple(version):
return tuple(int(part) for part in version.split("."))
"""Ordered as `SmdaFunction` orders a report's version: a pre-release below its own release."""
match = RELEASE_VERSION.match(version)
if match is None:
raise ValueError(f"not a release or a pre-release of one: {version!r}")
release = tuple(int(part) for part in match.group("release").split("."))
return (release, 0 if match.group("pre") else 1)


class TestPackageMetadata(unittest.TestCase):
def test_the_two_version_strings_agree(self):
self.assertEqual(smda.__version__, SmdaConfig.VERSION)

def test_the_version_is_a_three_part_release(self):
self.assertRegex(smda.__version__, r"^\d+\.\d+\.\d+$")
def test_the_version_is_a_three_part_release_or_a_candidate_for_one(self):
match = RELEASE_VERSION.match(smda.__version__)

self.assertIsNotNone(match, f"{smda.__version__!r} is neither a release nor a candidate")
self.assertRegex(match.group("release"), r"^\d+\.\d+\.\d+$")

def test_a_candidate_orders_below_the_release_it_is_a_candidate_for(self):
# the ordering the escaper-marker and changelog checks below depend on, and the same one
# report import uses, so a candidate is never taken for the release itself
self.assertLess(_version_tuple("4.8.0rc1"), _version_tuple("4.8.0"))
self.assertLess(_version_tuple("4.7.9"), _version_tuple("4.8.0rc1"))
# candidates of one release are not ordered against each other: nothing here needs it,
# and inventing an order for a1 against b1 would be a rule with no reader
self.assertEqual(_version_tuple("4.8.0a1"), _version_tuple("4.8.0rc1"))

for rejected in ("4.8", "4.8.0-dev", "4.8.0.1", "v4.8.0", ""):
with self.subTest(version=rejected), self.assertRaises(ValueError):
_version_tuple(rejected)

def test_the_escaper_compatibility_marker_is_a_three_part_release(self):
self.assertRegex(SmdaConfig.ESCAPER_DOWNWARD_COMPATIBILITY, r"^\d+\.\d+\.\d+$")
Expand Down Expand Up @@ -58,10 +85,13 @@ def _documentedVersions(self):
Releases cut from keep-a-changelog onward head their section `## [vX.Y.Z] - date`;
the ones before it keep the one-line ` * date: vX.Y.Z - ` shape under Older releases.
Both are read, so this keeps working across the release that introduces the first of
the new form rather than failing on it.
the new form rather than failing on it. A candidate heads a section of its own, so a
tagged `vX.Y.Zrc1` documents itself the way a release does.
"""
changelog = (REPO_ROOT / "CHANGELOG.md").read_text(encoding="utf-8")
headings = re.findall(r"^## \[v([\d.]+)\] - \d{4}-\d{2}-\d{2}", changelog, re.MULTILINE)
headings = re.findall(
r"^## \[v(\d+\.\d+\.\d+(?:(?:a|b|rc)\d+)?)\] - \d{4}-\d{2}-\d{2}", changelog, re.MULTILINE
)
legacy = re.findall(r"^ \* \d{4}-\d{2}-\d{2}: v([\d.]+)\s*-", changelog, re.MULTILINE)
return headings + legacy

Expand Down