Skip to content

Commit

Permalink
Assume utf-32 is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 9, 2022
1 parent ccb2214 commit ab10e94
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions cssutils/tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@

from cssutils import codec

try:
codecs.lookup("utf-32")
except LookupError:
haveutf32 = False
else:
haveutf32 = True

iostream = io.BytesIO


Expand Down Expand Up @@ -76,11 +69,10 @@ def test_detectencoding_str(self):
"utf-16",
True,
)
if haveutf32:
assert codec.detectencoding_str('\xff\xfe\x00\x00'.encode("utf-32")) == (
"utf-32",
True,
)
assert codec.detectencoding_str('\xff\xfe\x00\x00'.encode("utf-32")) == (
"utf-32",
True,
)
assert codec.detectencoding_str('\x00'.encode()) == (None, False)
assert codec.detectencoding_str('\x00\x33'.encode()) == ("utf-8", False)
assert codec.detectencoding_str('\x00\x00'.encode()) == (None, False)
Expand All @@ -90,26 +82,24 @@ def test_detectencoding_str(self):
False,
)
assert codec.detectencoding_str('\x00\x00\x00\x33'.encode()) == ("utf-8", False)
if haveutf32:
assert codec.detectencoding_str('\x00\x00\x00@'.encode()) == (
"utf-32-be",
False,
)
assert codec.detectencoding_str('\x00\x00\xfe\xff'.encode('utf-32')) == (
"utf-32",
True,
)
assert codec.detectencoding_str('\x00\x00\x00@'.encode()) == (
"utf-32-be",
False,
)
assert codec.detectencoding_str('\x00\x00\xfe\xff'.encode('utf-32')) == (
"utf-32",
True,
)
assert codec.detectencoding_str('@'.encode()) == (None, False)
assert codec.detectencoding_str('@\x33'.encode()) == ("utf-8", False)
assert codec.detectencoding_str('@\x00'.encode()) == (None, False)
assert codec.detectencoding_str('@\x00\x33'.encode()) == ("utf-8", False)
assert codec.detectencoding_str('@\x00\x00'.encode()) == (None, False)
assert codec.detectencoding_str('@\x00\x00\x33'.encode()) == ("utf-8", False)
if haveutf32:
assert codec.detectencoding_str('@\x00\x00\x00'.encode()) == (
"utf-32-le",
False,
)
assert codec.detectencoding_str('@\x00\x00\x00'.encode()) == (
"utf-32-le",
False,
)
assert codec.detectencoding_str('@c'.encode()) == (None, False)
assert codec.detectencoding_str('@ch'.encode()) == (None, False)
assert codec.detectencoding_str('@cha'.encode()) == (None, False)
Expand Down Expand Up @@ -207,10 +197,9 @@ def checkauto(encoding, input='@charset "x";g\xfcrk\u20ac{}'):
checkauto("utf-16")
checkauto("utf-16-le")
checkauto("utf-16-be")
if haveutf32:
checkauto("utf-32")
checkauto("utf-32-le")
checkauto("utf-32-be")
checkauto("utf-32")
checkauto("utf-32-le")
checkauto("utf-32-be")

def checkdecl(encoding, input='@charset "%s";g\xfcrk{}'):
# Check stateless decoder with encoding autodetection
Expand Down Expand Up @@ -310,10 +299,9 @@ def check(encoding, input='@charset "x";g\xfcrk\u20ac{}'):
check("utf-16")
check("utf-16-le")
check("utf-16-be")
if haveutf32:
check("utf-32")
check("utf-32-le")
check("utf-32-be")
check("utf-32")
check("utf-32-le")
check("utf-32-be")
check("utf-8")
check("iso-8859-1", '@charset "x";g\xfcrk{}')
check("iso-8859-15")
Expand Down

0 comments on commit ab10e94

Please sign in to comment.