Coverage for tests/test_conventional_commit_style.py: 100.00%

86 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-02 00:26 +0200

1"""Tests for the conventional commit convention.""" 

2 

3from __future__ import annotations 

4 

5from git_changelog.commit import Commit, ConventionalCommitConvention 

6 

7 

8def test_conventional_convention_breaking_change() -> None: 

9 """Breaking change (singular) is correctly identified.""" 

10 subject = "feat: this is a new breaking feature" 

11 body = ["BREAKING CHANGE: there is a breaking feature in this code"] 

12 commit = Commit( 

13 commit_hash="aaaaaaa", 

14 subject=subject, 

15 body=body, 

16 author_date="1574340645", 

17 committer_date="1574340645", 

18 ) 

19 convention = ConventionalCommitConvention() 

20 commit_dict = convention.parse_commit(commit) 

21 assert commit_dict["type"] == "Features" 

22 assert commit_dict["scope"] is None 

23 assert commit_dict["is_major"] 

24 assert not commit_dict["is_minor"] 

25 assert not commit_dict["is_patch"] 

26 

27 

28def test_conventional_convention_breaking_changes() -> None: 

29 """Breaking changes (plural) are correctly identified.""" 

30 subject = "feat: this is a new breaking feature" 

31 body = ["BREAKING CHANGES: there is a breaking feature in this code"] 

32 commit = Commit( 

33 commit_hash="aaaaaaa", 

34 subject=subject, 

35 body=body, 

36 author_date="1574340645", 

37 committer_date="1574340645", 

38 ) 

39 convention = ConventionalCommitConvention() 

40 commit_dict = convention.parse_commit(commit) 

41 assert commit_dict["type"] == "Features" 

42 assert commit_dict["scope"] is None 

43 assert commit_dict["is_major"] 

44 assert not commit_dict["is_minor"] 

45 assert not commit_dict["is_patch"] 

46 

47 

48def test_conventional_convention_subject_breaking_change() -> None: 

49 """Breaking change in the subject (!) are correctly identified.""" 

50 subject = "feat!: this is a new breaking feature" 

51 body = ["There is a breaking feature in this code"] 

52 commit = Commit( 

53 commit_hash="aaaaaaa", 

54 subject=subject, 

55 body=body, 

56 author_date="1574340645", 

57 committer_date="1574340645", 

58 ) 

59 convention = ConventionalCommitConvention() 

60 commit_dict = convention.parse_commit(commit) 

61 assert commit_dict["type"] == "Features" 

62 assert commit_dict["scope"] is None 

63 assert commit_dict["is_major"] 

64 assert not commit_dict["is_minor"] 

65 assert not commit_dict["is_patch"] 

66 

67 

68def test_conventional_convention_subject_breaking_change_with_scope() -> None: 

69 """Breaking change in the subject (!) with scope are correctly identified.""" 

70 subject = "feat(scope)!: this is a new breaking feature" 

71 body = ["There is a breaking feature in this code"] 

72 commit = Commit( 

73 commit_hash="aaaaaaa", 

74 subject=subject, 

75 body=body, 

76 author_date="1574340645", 

77 committer_date="1574340645", 

78 ) 

79 convention = ConventionalCommitConvention() 

80 commit_dict = convention.parse_commit(commit) 

81 assert commit_dict["type"] == "Features" 

82 assert commit_dict["scope"] == "scope" 

83 assert commit_dict["is_major"] 

84 assert not commit_dict["is_minor"] 

85 assert not commit_dict["is_patch"] 

86 

87 

88def test_conventional_convention_feat() -> None: 

89 """Feature commit is correctly identified.""" 

90 subject = "feat: this is a new feature" 

91 commit = Commit( 

92 commit_hash="aaaaaaa", 

93 subject=subject, 

94 author_date="1574340645", 

95 committer_date="1574340645", 

96 ) 

97 convention = ConventionalCommitConvention() 

98 commit_dict = convention.parse_commit(commit) 

99 assert commit_dict["type"] == "Features" 

100 assert commit_dict["scope"] is None 

101 assert not commit_dict["is_major"] 

102 assert commit_dict["is_minor"] 

103 assert not commit_dict["is_patch"] 

104 

105 

106def test_conventional_convention_feat_with_scope() -> None: 

107 """Feature commit is correctly identified.""" 

108 subject = "feat(scope): this is a new feature" 

109 commit = Commit( 

110 commit_hash="aaaaaaa", 

111 subject=subject, 

112 author_date="1574340645", 

113 committer_date="1574340645", 

114 ) 

115 convention = ConventionalCommitConvention() 

116 commit_dict = convention.parse_commit(commit) 

117 assert commit_dict["type"] == "Features" 

118 assert commit_dict["scope"] == "scope" 

119 assert not commit_dict["is_major"] 

120 assert commit_dict["is_minor"] 

121 assert not commit_dict["is_patch"] 

122 

123 

124def test_conventional_convention_fix() -> None: 

125 """Bug fix commit is correctly identified.""" 

126 subject = "fix: this is a bug fix" 

127 commit = Commit( 

128 commit_hash="aaaaaaa", 

129 subject=subject, 

130 author_date="1574340645", 

131 committer_date="1574340645", 

132 ) 

133 convention = ConventionalCommitConvention() 

134 commit_dict = convention.parse_commit(commit) 

135 assert commit_dict["type"] == "Bug Fixes" 

136 assert commit_dict["scope"] is None 

137 assert not commit_dict["is_major"] 

138 assert not commit_dict["is_minor"] 

139 assert commit_dict["is_patch"] 

140 

141 

142def test_conventional_convention_fix_with_scope() -> None: 

143 """Bug fix commit is correctly identified.""" 

144 subject = "fix(scope): this is a bug fix" 

145 commit = Commit( 

146 commit_hash="aaaaaaa", 

147 subject=subject, 

148 author_date="1574340645", 

149 committer_date="1574340645", 

150 ) 

151 convention = ConventionalCommitConvention() 

152 commit_dict = convention.parse_commit(commit) 

153 assert commit_dict["type"] == "Bug Fixes" 

154 assert commit_dict["scope"] == "scope" 

155 assert not commit_dict["is_major"] 

156 assert not commit_dict["is_minor"] 

157 assert commit_dict["is_patch"]