Coverage for tests/test_commit.py: 100.00%
7 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-02 00:26 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-02 00:26 +0200
1"""Tests for the `commit` module."""
3from __future__ import annotations
5import pytest
7from git_changelog.commit import Commit
10@pytest.mark.parametrize(
11 ("body", "expected_trailers"),
12 [
13 ("t1: v1\nt2: v2", {"t1": "v1", "t2": "v2"}), # ok
14 ("body\n\nt1: v1\nt2: v2", {"t1": "v1", "t2": "v2"}), # ok
15 ("t1: v1\nt2:v2", {}), # missing space after colon
16 ("t1: v1\nt2: v2\n\nf", {}), # trailers not last
17 ("t1: v1\nt2 v2", {}), # not all trailers
18 (
19 "something: else\n\nt1: v1\nt2: v2",
20 {"t1": "v1", "t2": "v2"},
21 ), # parse footer only
22 ],
23)
24def test_parsing_trailers(body: str, expected_trailers: dict[str, str]) -> None:
25 """Assert trailers are parsed correctly.
27 Parameters:
28 body: A commit message body.
29 expected_trailers: The trailers we expect to be parsed.
30 """
31 commit = Commit(
32 commit_hash="aaaaaaaa",
33 subject="Summary",
34 body=body.split("\n"),
35 parse_trailers=True,
36 )
37 assert commit.trailers == expected_trailers