Blob Blame History Raw
From 2126bd932d6dfb3f07045eb9400acb7eaa1b3069 Mon Sep 17 00:00:00 2001
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
Date: Wed, 16 Mar 2022 09:30:47 -0400
Subject: [PATCH] Fix AttributeError tests for Python 3.11

In Python 3.11, the messages associated with some AttributeErrors have
changed. Adjust the message patterns in affected tests to accommodate
both new and old message styles.

Fixes #753.
---
 pynetdicom/tests/test_assoc_user.py   | 28 +++++++++++++--------------
 pynetdicom/tests/test_presentation.py |  4 ++--
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/pynetdicom/tests/test_assoc_user.py b/pynetdicom/tests/test_assoc_user.py
index 95a623f4d..8f5ecb0b5 100644
--- a/pynetdicom/tests/test_assoc_user.py
+++ b/pynetdicom/tests/test_assoc_user.py
@@ -164,7 +164,7 @@ def test_mode_assignment_raises(self):
         """Test that assigning mode after init raises exception."""
         user = ServiceUser(self.assoc, mode="acceptor")
         assert user.mode == "acceptor"
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.mode = "requestor"
 
         assert user.mode == "acceptor"
@@ -297,22 +297,22 @@ def test_primitive_assignment_raises(self):
         with pytest.raises(RuntimeError, match=msg):
             user.implementation_version_name = "1.2.3"
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.asynchronous_operations = (1, 1)
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.role_selection = {}
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.sop_class_common_extended = {}
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.sop_class_extended = {}
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.user_identity = "test"
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.extended_negotiation = []
 
     def test_add_neg_pre(self):
@@ -1477,7 +1477,7 @@ def test_mode_assignment_raises(self):
         """Test that assigning mode after init raises exception."""
         user = ServiceUser(self.assoc, mode="requestor")
         assert user.mode == "requestor"
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.mode = "acceptor"
 
         assert user.mode == "requestor"
@@ -1601,22 +1601,22 @@ def test_primitive_assignment_raises(self):
         with pytest.raises(RuntimeError, match=msg):
             user.implementation_version_name = "1.2.3"
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.asynchronous_operations = (1, 1)
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.role_selection = {}
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.sop_class_common_extended = {}
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.sop_class_extended = {}
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.user_identity = "test"
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             user.extended_negotiation = []
 
     def test_accepted_common_raises(self):
diff --git a/pynetdicom/tests/test_presentation.py b/pynetdicom/tests/test_presentation.py
index 8153bb10a..54cd194f6 100644
--- a/pynetdicom/tests/test_presentation.py
+++ b/pynetdicom/tests/test_presentation.py
@@ -374,7 +374,7 @@ def test_as_scp(self):
         context = build_context("1.2.3")
         assert context.as_scp is None
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             context.as_scp = True
 
         context._as_scp = True
@@ -387,7 +387,7 @@ def test_as_scu(self):
         context = build_context("1.2.3")
         assert context.as_scu is None
 
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
             context.as_scu = True
 
         context._as_scu = True