55from test import conftest
66
77import pytest
8+ from conftest import commit_factory
89from faker import Faker
910from pytest import param
1011
1112from generate_changelog import configuration , templating
12- from generate_changelog .configuration import DEFAULT_SECTION_PATTERNS , get_config
13+ from generate_changelog .configuration import DEFAULT_COMMIT_CLASSIFIERS , get_config
1314from generate_changelog .context import CommitContext
1415
1516FIXTURES_DIR = Path (__file__ ).parent / "fixtures"
1920@pytest .mark .parametrize (
2021 ["string" , "expected" ],
2122 (
22- param ("Newly added something" , "New" ),
23- param ("added something new" , "New" ),
24- param ("changed something new" , "Updates" ),
25- param ("Updates something old" , "Updates" ),
26- param ("renamed something I didn't like." , "Updates" ),
27- param ("Removed something old" , "Updates" ),
28- param ("deletes something old" , "Updates" ),
29- param ("improved something old" , "Updates" ),
30- param ("refactored something old" , "Updates" ),
31- param ("fixed an error or something" , "Fixes" ),
32- param ("I don't know what this does" , "Other" ),
23+ param (commit_factory ( summary = "Newly added something" ) , "New" ),
24+ param (commit_factory ( summary = "added something new" ) , "New" ),
25+ param (commit_factory ( summary = "changed something new" ) , "Updates" ),
26+ param (commit_factory ( summary = "Updates something old" ) , "Updates" ),
27+ param (commit_factory ( summary = "renamed something I didn't like." ) , "Updates" ),
28+ param (commit_factory ( summary = "Removed something old" ) , "Updates" ),
29+ param (commit_factory ( summary = "deletes something old" ) , "Updates" ),
30+ param (commit_factory ( summary = "improved something old" ) , "Updates" ),
31+ param (commit_factory ( summary = "refactored something old" ) , "Updates" ),
32+ param (commit_factory ( summary = "fixed an error or something" ) , "Fixes" ),
33+ param (commit_factory ( summary = "I don't know what this does" ) , "Other" ),
3334 ),
3435)
3536def test_first_matching (string , expected ):
3637 """The first matching function should properly categorize a string."""
37- assert templating .first_matching (DEFAULT_SECTION_PATTERNS , string ) == expected
38+ assert templating .first_matching (DEFAULT_COMMIT_CLASSIFIERS , string ) == expected
3839
3940
4041def test_commit_context ():
@@ -45,6 +46,7 @@ def test_commit_context():
4546 commit_datetime = commit .committed_datetime ,
4647 committer = f"{ commit .committer .name } <{ commit .committer .email } >" ,
4748 summary = commit .summary ,
49+ grouping = ("a" , "b" ),
4850 body = "\n " .join (commit .message .splitlines ()[1 :]),
4951 )
5052 assert commit .hexsha [:7 ] == context .short_sha
@@ -62,6 +64,7 @@ def test_commit_with_no_email():
6264 commit_datetime = commit .committed_datetime ,
6365 committer = f"{ commit .committer .name } <{ commit .committer .email } >" ,
6466 summary = commit .summary ,
67+ grouping = (None ,),
6568 body = "\n " .join (commit .message .splitlines ()[1 :]),
6669 metadata = {"trailers" : {"co-authored-by" : [name_only ]}},
6770 )
@@ -77,10 +80,10 @@ def test_get_context_from_tags(default_repo):
7780 v = context [0 ]
7881 assert v .label == get_config ().unreleased_label
7982 assert v .date_time .date () == datetime .date (2022 , 1 , 6 )
80- assert len (v .sections ) == 1
81- assert v .sections [0 ].label == "Updates"
82- assert len (v .sections [0 ].commits ) == 1
83- assert v .sections [0 ].commits [0 ].metadata ["trailers" ]["co-committed-by" ] == [
83+ assert len (v .grouped_commits ) == 1
84+ assert v .grouped_commits [0 ].grouping == ( "Updates" ,)
85+ assert len (v .grouped_commits [0 ].commits ) == 1
86+ assert v .grouped_commits [0 ].commits [0 ].metadata ["trailers" ]["co-committed-by" ] == [
8487 "Juliet <juliet@example.com>" ,
8588 "Charly <charly@example.com>" ,
8689 ]
@@ -89,11 +92,11 @@ def test_get_context_from_tags(default_repo):
8992 assert v .label == "0.0.3"
9093 assert v .previous_tag == "0.0.2"
9194 assert v .date_time .date () == datetime .date (2022 , 1 , 5 )
92- assert len (v .sections ) == 1
93- assert v .sections [0 ].label == "New"
94- assert len (v .sections [0 ].commits ) == 2
95- assert len (v .sections [0 ].commits [0 ].metadata ["trailers" ]) == 5
96- assert len (v .sections [0 ].commits [1 ].metadata ["trailers" ]) == 0
95+ assert len (v .grouped_commits ) == 1
96+ assert v .grouped_commits [0 ].grouping == ( "New" ,)
97+ assert len (v .grouped_commits [0 ].commits ) == 2
98+ assert len (v .grouped_commits [0 ].commits [0 ].metadata ["trailers" ]) == 5
99+ assert len (v .grouped_commits [0 ].commits [1 ].metadata ["trailers" ]) == 0
97100
98101
99102def test_render (default_repo , capsys ):
0 commit comments