1
0
Fork 0

Adding upstream version 4.6.0+dfsg.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-04-21 10:42:01 +02:00
parent f3ad83a1a5
commit 167a3f8553
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
275 changed files with 30423 additions and 0 deletions

53
tests/test_cmd.py Normal file
View file

@ -0,0 +1,53 @@
import pytest
from commitizen import cmd
from commitizen.exceptions import CharacterSetDecodeError
# https://docs.python.org/3/howto/unicode.html
def test_valid_utf8_encoded_strings():
valid_strings = (
"",
"ascii",
"🤦🏻‍♂️",
"",
"\u0000",
)
assert all(s == cmd._try_decode(s.encode("utf-8")) for s in valid_strings)
# A word of caution: just because an encoding can be guessed for a given
# sequence of bytes and because that guessed encoding may yield a decoded
# string, does not mean that that string was the original! For more, see:
# https://docs.python.org/3/library/codecs.html#standard-encodings
# Pick a random, non-utf8 encoding to test.
def test_valid_cp1250_encoded_strings():
valid_strings = (
"",
"ascii",
"äöüß",
"ça va",
"jak se máte",
)
for s in valid_strings:
assert cmd._try_decode(s.encode("cp1250")) or True
def test_invalid_bytes():
invalid_bytes = (b"\x73\xe2\x9d\xff\x00",)
for s in invalid_bytes:
with pytest.raises(CharacterSetDecodeError):
cmd._try_decode(s)
def test_always_fail_decode():
class _bytes(bytes):
def decode(self, encoding="utf-8", errors="strict"):
raise UnicodeDecodeError(
encoding, self, 0, 0, "Failing intentionally for testing"
)
with pytest.raises(CharacterSetDecodeError):
cmd._try_decode(_bytes())