From ca7a3bdbbd771c3cec8128e510b429bde961d23c Mon Sep 17 00:00:00 2001
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
Date: Wed, 16 Mar 2022 09:53:58 -0400
Subject: [PATCH] Make decoding error tests endian-independent
Fixes #755, test failures on s390x.
The test byte string on little-endian hosts is the same as it was before
this commit. On big-endian hosts, the test byte string now matches the
one used on little-endian hosts, which makes the nature and message of
the exception being tested endianness-independent.
---
pynetdicom/tests/test_utils.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/pynetdicom/tests/test_utils.py b/pynetdicom/tests/test_utils.py
index e0779894d..09b0c2fe8 100644
--- a/pynetdicom/tests/test_utils.py
+++ b/pynetdicom/tests/test_utils.py
@@ -1,5 +1,6 @@
"""Unit tests for the pynetdicom.utils module."""
+from codecs import BOM_UTF32_LE
from io import BytesIO
from threading import Thread
import logging
@@ -230,7 +231,7 @@ def test_bytes(self):
def test_bytes_decoding_error(self, caplog):
"""Test invalid bytes raises exception"""
- b = "1.2.3".encode("utf_32")
+ b = BOM_UTF32_LE + "1.2.3".encode("utf_32_le")
assert isinstance(b, bytes)
msg = (
r"Unable to decode 'FF FE 00 00 31 00 00 00 2E 00 00 00 32 00 00 "
@@ -312,7 +313,7 @@ class TestDecodeBytes:
def test_decoding_error(self, caplog):
"""Test decoding error raises and logs"""
- b = "1.2.3".encode("utf_32")
+ b = BOM_UTF32_LE + "1.2.3".encode("utf_32_le")
with caplog.at_level(logging.ERROR, logger="pynetdicom"):
msg = (
r"Unable to decode 'FF FE 00 00 31 00 00 00 2E 00 00 00 32 "
@@ -325,7 +326,7 @@ def test_decoding_error(self, caplog):
def test_decoding_error_fallback(self, caplog, utf8):
"""Test decoding error raises and logs"""
- b = "1.2.3".encode("utf_32")
+ b = BOM_UTF32_LE + "1.2.3".encode("utf_32_le")
with caplog.at_level(logging.ERROR, logger="pynetdicom"):
msg = (
r"Unable to decode 'FF FE 00 00 31 00 00 00 2E 00 00 00 32 "