Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 757d98c

Browse files
test(unicode): add tests
1 parent a3d30ad commit 757d98c

File tree

1 file changed

+222
-10
lines changed

1 file changed

+222
-10
lines changed

tests/test_cz_customize.py

Lines changed: 222 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
TOML_STR = r"""
88
[tool.commitizen.customize]
99
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"
1111
schema = "<type>: <body>"
1212
schema_pattern = "(feature|bug fix):(\\s.*)"
1313
commit_parser = "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
@@ -50,7 +50,7 @@
5050
],
5151
"customize": {
5252
"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",
5454
"schema": "<type>: <body>",
5555
"schema_pattern": "(feature|bug fix):(\\s.*)",
5656
"bump_pattern": "^(break|new|fix|hotfix)",
@@ -106,7 +106,7 @@
106106
- pyproject.toml
107107
customize:
108108
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'
110110
schema: "<type>: <body>"
111111
schema_pattern: "(feature|bug fix):(\\s.*)"
112112
bump_pattern: "^(break|new|fix|hotfix)"
@@ -134,11 +134,105 @@
134134
message: Do you want to add body message in commit?
135135
"""
136136

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+
"""
137231

138232
TOML_STR_INFO_PATH = """
139233
[tool.commitizen.customize]
140234
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"
142236
schema = "<type>: <body>"
143237
bump_pattern = "^(break|new|fix|hotfix)"
144238
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
@@ -150,7 +244,7 @@
150244
"commitizen": {
151245
"customize": {
152246
"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",
154248
"schema": "<type>: <body>",
155249
"bump_pattern": "^(break|new|fix|hotfix)",
156250
"bump_map": {
@@ -169,7 +263,7 @@
169263
commitizen:
170264
customize:
171265
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'
173267
schema: "<type>: <body>"
174268
bump_pattern: "^(break|new|fix|hotfix)"
175269
bump_map:
@@ -183,7 +277,7 @@
183277
TOML_STR_WITHOUT_INFO = """
184278
[tool.commitizen.customize]
185279
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"
187281
schema = "<type>: <body>"
188282
bump_pattern = "^(break|new|fix|hotfix)"
189283
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
@@ -194,7 +288,7 @@
194288
"commitizen": {
195289
"customize": {
196290
"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",
198292
"schema": "<type>: <body>",
199293
"bump_pattern": "^(break|new|fix|hotfix)",
200294
"bump_map": {
@@ -212,7 +306,7 @@
212306
commitizen:
213307
customize:
214308
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'
216310
schema: "<type>: <body>"
217311
bump_pattern: "^(break|new|fix|hotfix)"
218312
bump_map:
@@ -260,6 +354,16 @@ def config_without_info(request):
260354
return request.param
261355

262356

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+
263367
def test_initialize_cz_customize_failed():
264368
with pytest.raises(MissingCzCustomizeConfigError) as excinfo:
265369
config = BaseConfig()
@@ -273,6 +377,11 @@ def test_bump_pattern(config):
273377
assert cz.bump_pattern == "^(break|new|fix|hotfix)"
274378

275379

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+
276385
def test_bump_map(config):
277386
cz = CustomizeCommitsCz(config)
278387
assert cz.bump_map == {
@@ -283,6 +392,15 @@ def test_bump_map(config):
283392
}
284393

285394

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+
286404
def test_change_type_order(config):
287405
cz = CustomizeCommitsCz(config)
288406
assert cz.change_type_order == [
@@ -294,6 +412,17 @@ def test_change_type_order(config):
294412
]
295413

296414

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+
297426
def test_questions(config):
298427
cz = CustomizeCommitsCz(config)
299428
questions = cz.questions()
@@ -317,6 +446,29 @@ def test_questions(config):
317446
assert list(questions) == expected_questions
318447

319448

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+
320472
def test_answer(config):
321473
cz = CustomizeCommitsCz(config)
322474
answers = {
@@ -337,9 +489,42 @@ def test_answer(config):
337489
assert message == "feature:"
338490

339491

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+
340514
def test_example(config):
341515
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+
)
343528

344529

345530
def test_schema(config):
@@ -352,11 +537,21 @@ def test_schema_pattern(config):
352537
assert r"(feature|bug fix):(\s.*)" in cz.schema_pattern()
353538

354539

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+
355545
def test_info(config):
356546
cz = CustomizeCommitsCz(config)
357547
assert "This is a customized cz." in cz.info()
358548

359549

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+
360555
def test_info_with_info_path(tmpdir, config_info):
361556
with tmpdir.as_cwd():
362557
tmpfile = tmpdir.join("info.txt")
@@ -376,11 +571,28 @@ def test_commit_parser(config):
376571
assert cz.commit_parser == "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
377572

378573

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+
379581
def test_changelog_pattern(config):
380582
cz = CustomizeCommitsCz(config)
381583
assert cz.changelog_pattern == "^(feature|bug fix)?(!)?"
382584

383585

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+
384591
def test_change_type_map(config):
385592
cz = CustomizeCommitsCz(config)
386593
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

Comments
 (0)