7
7
TOML_STR = r"""
8
8
[tool.commitizen.customize]
9
9
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
10
- example = "feature: this feature enable customize through config file"
10
+ example = "feature: this feature enables customization through a config file"
11
11
schema = "<type>: <body>"
12
12
schema_pattern = "(feature|bug fix):(\\s.*)"
13
13
commit_parser = "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
50
50
],
51
51
"customize": {
52
52
"message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
53
- "example": "feature: this feature enable customize through config file",
53
+ "example": "feature: this feature enables customization through a config file",
54
54
"schema": "<type>: <body>",
55
55
"schema_pattern": "(feature|bug fix):(\\s.*)",
56
56
"bump_pattern": "^(break|new|fix|hotfix)",
106
106
- pyproject.toml
107
107
customize:
108
108
message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
109
- example: 'feature: this feature enable customize through config file'
109
+ example: 'feature: this feature enables customization through a config file'
110
110
schema: "<type>: <body>"
111
111
schema_pattern: "(feature|bug fix):(\\ s.*)"
112
112
bump_pattern: "^(break|new|fix|hotfix)"
134
134
message: Do you want to add body message in commit?
135
135
"""
136
136
137
+ TOML_WITH_UNICODE = r"""
138
+ [tool.commitizen]
139
+ name = "cz_customize"
140
+ version = "1.0.0"
141
+ version_files = [
142
+ "commitizen/__version__.py",
143
+ "pyproject.toml:version"
144
+ ]
145
+ [tool.commitizen.customize]
146
+ message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
147
+ example = "✨ feature: this feature enables customization through a config file"
148
+ schema = "<type>: <body>"
149
+ schema_pattern = "(✨ feature|🐛 bug fix):(\\s.*)"
150
+ commit_parser = "^(?P<change_type>✨ feature|🐛 bug fix):\\s(?P<message>.*)?"
151
+ changelog_pattern = "^(✨ feature|🐛 bug fix)?(!)?"
152
+ change_type_map = {"✨ feature" = "Feat", "🐛 bug fix" = "Fix"}
153
+ bump_pattern = "^(✨ feat|🐛 bug fix)"
154
+ bump_map = {"break" = "MAJOR", "✨ feat" = "MINOR", "🐛 bug fix" = "MINOR"}
155
+ change_type_order = ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"]
156
+ info = "This is a customized cz with emojis 🎉!"
157
+ [[tool.commitizen.customize.questions]]
158
+ type = "list"
159
+ name = "change_type"
160
+ choices = [
161
+ {value = "✨ feature", name = "✨ feature: A new feature."},
162
+ {value = "🐛 bug fix", name = "🐛 bug fix: A bug fix."}
163
+ ]
164
+ message = "Select the type of change you are committing"
165
+ [[tool.commitizen.customize.questions]]
166
+ type = "input"
167
+ name = "message"
168
+ message = "Body."
169
+ [[tool.commitizen.customize.questions]]
170
+ type = "confirm"
171
+ name = "show_message"
172
+ message = "Do you want to add body message in commit?"
173
+ """
174
+
175
+ JSON_WITH_UNICODE = r"""
176
+ {
177
+ "commitizen": {
178
+ "name": "cz_customize",
179
+ "version": "1.0.0",
180
+ "version_files": [
181
+ "commitizen/__version__.py",
182
+ "pyproject.toml:version"
183
+ ],
184
+ "customize": {
185
+ "message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
186
+ "example": "✨ feature: this feature enables customization through a config file",
187
+ "schema": "<type>: <body>",
188
+ "schema_pattern": "(✨ feature|🐛 bug fix):(\\s.*)",
189
+ "bump_pattern": "^(✨ feat|🐛 bug fix)",
190
+ "bump_map": {
191
+ "break": "MAJOR",
192
+ "✨ feat": "MINOR",
193
+ "🐛 bug fix": "MINOR"
194
+ },
195
+ "commit_parser": "^(?P<change_type>✨ feature|🐛 bug fix):\\s(?P<message>.*)?",
196
+ "changelog_pattern": "^(✨ feature|🐛 bug fix)?(!)?",
197
+ "change_type_map": {"✨ feature": "Feat", "🐛 bug fix": "Fix"},
198
+ "change_type_order": ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"],
199
+ "info": "This is a customized cz with emojis 🎉!",
200
+ "questions": [
201
+ {
202
+ "type": "list",
203
+ "name": "change_type",
204
+ "choices": [
205
+ {
206
+ "value": "✨ feature",
207
+ "name": "✨ feature: A new feature."
208
+ },
209
+ {
210
+ "value": "🐛 bug fix",
211
+ "name": "🐛 bug fix: A bug fix."
212
+ }
213
+ ],
214
+ "message": "Select the type of change you are committing"
215
+ },
216
+ {
217
+ "type": "input",
218
+ "name": "message",
219
+ "message": "Body."
220
+ },
221
+ {
222
+ "type": "confirm",
223
+ "name": "show_message",
224
+ "message": "Do you want to add body message in commit?"
225
+ }
226
+ ]
227
+ }
228
+ }
229
+ }
230
+ """
137
231
138
232
TOML_STR_INFO_PATH = """
139
233
[tool.commitizen.customize]
140
234
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
141
- example = "feature: this feature enable customize through config file"
235
+ example = "feature: this feature enables customization through a config file"
142
236
schema = "<type>: <body>"
143
237
bump_pattern = "^(break|new|fix|hotfix)"
144
238
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
150
244
"commitizen": {
151
245
"customize": {
152
246
"message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
153
- "example": "feature: this feature enable customize through config file",
247
+ "example": "feature: this feature enables customization through a config file",
154
248
"schema": "<type>: <body>",
155
249
"bump_pattern": "^(break|new|fix|hotfix)",
156
250
"bump_map": {
169
263
commitizen:
170
264
customize:
171
265
message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
172
- example: 'feature: this feature enable customize through config file'
266
+ example: 'feature: this feature enables customization through a config file'
173
267
schema: "<type>: <body>"
174
268
bump_pattern: "^(break|new|fix|hotfix)"
175
269
bump_map:
183
277
TOML_STR_WITHOUT_INFO = """
184
278
[tool.commitizen.customize]
185
279
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
186
- example = "feature: this feature enable customize through config file"
280
+ example = "feature: this feature enables customization through a config file"
187
281
schema = "<type>: <body>"
188
282
bump_pattern = "^(break|new|fix|hotfix)"
189
283
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
194
288
"commitizen": {
195
289
"customize": {
196
290
"message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
197
- "example": "feature: this feature enable customize through config file",
291
+ "example": "feature: this feature enables customization through a config file",
198
292
"schema": "<type>: <body>",
199
293
"bump_pattern": "^(break|new|fix|hotfix)",
200
294
"bump_map": {
212
306
commitizen:
213
307
customize:
214
308
message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
215
- example: 'feature: this feature enable customize through config file'
309
+ example: 'feature: this feature enables customization through a config file'
216
310
schema: "<type>: <body>"
217
311
bump_pattern: "^(break|new|fix|hotfix)"
218
312
bump_map:
@@ -260,6 +354,16 @@ def config_without_info(request):
260
354
return request .param
261
355
262
356
357
+ @pytest .fixture (
358
+ params = [
359
+ TomlConfig (data = TOML_WITH_UNICODE , path = "not_exist.toml" ),
360
+ JsonConfig (data = JSON_WITH_UNICODE , path = "not_exist.json" ),
361
+ ]
362
+ )
363
+ def config_with_unicode (request ):
364
+ return request .param
365
+
366
+
263
367
def test_initialize_cz_customize_failed ():
264
368
with pytest .raises (MissingCzCustomizeConfigError ) as excinfo :
265
369
config = BaseConfig ()
@@ -273,6 +377,11 @@ def test_bump_pattern(config):
273
377
assert cz .bump_pattern == "^(break|new|fix|hotfix)"
274
378
275
379
380
+ def test_bump_pattern_unicode (config_with_unicode ):
381
+ cz = CustomizeCommitsCz (config_with_unicode )
382
+ assert cz .bump_pattern == "^(✨ feat|🐛 bug fix)"
383
+
384
+
276
385
def test_bump_map (config ):
277
386
cz = CustomizeCommitsCz (config )
278
387
assert cz .bump_map == {
@@ -283,6 +392,15 @@ def test_bump_map(config):
283
392
}
284
393
285
394
395
+ def test_bump_map_unicode (config_with_unicode ):
396
+ cz = CustomizeCommitsCz (config_with_unicode )
397
+ assert cz .bump_map == {
398
+ "break" : "MAJOR" ,
399
+ "✨ feat" : "MINOR" ,
400
+ "🐛 bug fix" : "MINOR" ,
401
+ }
402
+
403
+
286
404
def test_change_type_order (config ):
287
405
cz = CustomizeCommitsCz (config )
288
406
assert cz .change_type_order == [
@@ -294,6 +412,17 @@ def test_change_type_order(config):
294
412
]
295
413
296
414
415
+ def test_change_type_order_unicode (config_with_unicode ):
416
+ cz = CustomizeCommitsCz (config_with_unicode )
417
+ assert cz .change_type_order == [
418
+ "perf" ,
419
+ "BREAKING CHANGE" ,
420
+ "feat" ,
421
+ "fix" ,
422
+ "refactor" ,
423
+ ]
424
+
425
+
297
426
def test_questions (config ):
298
427
cz = CustomizeCommitsCz (config )
299
428
questions = cz .questions ()
@@ -317,6 +446,29 @@ def test_questions(config):
317
446
assert list (questions ) == expected_questions
318
447
319
448
449
+ def test_questions_unicode (config_with_unicode ):
450
+ cz = CustomizeCommitsCz (config_with_unicode )
451
+ questions = cz .questions ()
452
+ expected_questions = [
453
+ {
454
+ "type" : "list" ,
455
+ "name" : "change_type" ,
456
+ "choices" : [
457
+ {"value" : "✨ feature" , "name" : "✨ feature: A new feature." },
458
+ {"value" : "🐛 bug fix" , "name" : "🐛 bug fix: A bug fix." },
459
+ ],
460
+ "message" : "Select the type of change you are committing" ,
461
+ },
462
+ {"type" : "input" , "name" : "message" , "message" : "Body." },
463
+ {
464
+ "type" : "confirm" ,
465
+ "name" : "show_message" ,
466
+ "message" : "Do you want to add body message in commit?" ,
467
+ },
468
+ ]
469
+ assert list (questions ) == expected_questions
470
+
471
+
320
472
def test_answer (config ):
321
473
cz = CustomizeCommitsCz (config )
322
474
answers = {
@@ -337,9 +489,42 @@ def test_answer(config):
337
489
assert message == "feature:"
338
490
339
491
492
+ def test_answer_unicode (config_with_unicode ):
493
+ cz = CustomizeCommitsCz (config_with_unicode )
494
+ answers = {
495
+ "change_type" : "✨ feature" ,
496
+ "message" : "this feature enables customization through a config file" ,
497
+ "show_message" : True ,
498
+ }
499
+ message = cz .message (answers )
500
+ assert (
501
+ message == "✨ feature: this feature enables customization through a config file"
502
+ )
503
+
504
+ cz = CustomizeCommitsCz (config_with_unicode )
505
+ answers = {
506
+ "change_type" : "✨ feature" ,
507
+ "message" : "this feature enables customization through a config file" ,
508
+ "show_message" : False ,
509
+ }
510
+ message = cz .message (answers )
511
+ assert message == "✨ feature:"
512
+
513
+
340
514
def test_example (config ):
341
515
cz = CustomizeCommitsCz (config )
342
- assert "feature: this feature enable customize through config file" in cz .example ()
516
+ assert (
517
+ "feature: this feature enables customization through a config file"
518
+ in cz .example ()
519
+ )
520
+
521
+
522
+ def test_example_unicode (config_with_unicode ):
523
+ cz = CustomizeCommitsCz (config_with_unicode )
524
+ assert (
525
+ "✨ feature: this feature enables customization through a config file"
526
+ in cz .example ()
527
+ )
343
528
344
529
345
530
def test_schema (config ):
@@ -352,11 +537,21 @@ def test_schema_pattern(config):
352
537
assert r"(feature|bug fix):(\s.*)" in cz .schema_pattern ()
353
538
354
539
540
+ def test_schema_pattern_unicode (config_with_unicode ):
541
+ cz = CustomizeCommitsCz (config_with_unicode )
542
+ assert r"(✨ feature|🐛 bug fix):(\s.*)" in cz .schema_pattern ()
543
+
544
+
355
545
def test_info (config ):
356
546
cz = CustomizeCommitsCz (config )
357
547
assert "This is a customized cz." in cz .info ()
358
548
359
549
550
+ def test_info_unicode (config_with_unicode ):
551
+ cz = CustomizeCommitsCz (config_with_unicode )
552
+ assert "This is a customized cz with emojis 🎉!" in cz .info ()
553
+
554
+
360
555
def test_info_with_info_path (tmpdir , config_info ):
361
556
with tmpdir .as_cwd ():
362
557
tmpfile = tmpdir .join ("info.txt" )
@@ -376,11 +571,28 @@ def test_commit_parser(config):
376
571
assert cz .commit_parser == "^(?P<change_type>feature|bug fix):\\ s(?P<message>.*)?"
377
572
378
573
574
+ def test_commit_parser_unicode (config_with_unicode ):
575
+ cz = CustomizeCommitsCz (config_with_unicode )
576
+ assert (
577
+ cz .commit_parser == "^(?P<change_type>✨ feature|🐛 bug fix):\\ s(?P<message>.*)?"
578
+ )
579
+
580
+
379
581
def test_changelog_pattern (config ):
380
582
cz = CustomizeCommitsCz (config )
381
583
assert cz .changelog_pattern == "^(feature|bug fix)?(!)?"
382
584
383
585
586
+ def test_changelog_pattern_unicode (config_with_unicode ):
587
+ cz = CustomizeCommitsCz (config_with_unicode )
588
+ assert cz .changelog_pattern == "^(✨ feature|🐛 bug fix)?(!)?"
589
+
590
+
384
591
def test_change_type_map (config ):
385
592
cz = CustomizeCommitsCz (config )
386
593
assert cz .change_type_map == {"feature" : "Feat" , "bug fix" : "Fix" }
594
+
595
+
596
+ def test_change_type_map_unicode (config_with_unicode ):
597
+ cz = CustomizeCommitsCz (config_with_unicode )
598
+ assert cz .change_type_map == {"✨ feature" : "Feat" , "🐛 bug fix" : "Fix" }
0 commit comments