7b0aee6
From 2126bd932d6dfb3f07045eb9400acb7eaa1b3069 Mon Sep 17 00:00:00 2001
7b0aee6
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
7b0aee6
Date: Wed, 16 Mar 2022 09:30:47 -0400
7b0aee6
Subject: [PATCH] Fix AttributeError tests for Python 3.11
7b0aee6
7b0aee6
In Python 3.11, the messages associated with some AttributeErrors have
7b0aee6
changed. Adjust the message patterns in affected tests to accommodate
7b0aee6
both new and old message styles.
7b0aee6
7b0aee6
Fixes #753.
7b0aee6
---
7b0aee6
 pynetdicom/tests/test_assoc_user.py   | 28 +++++++++++++--------------
7b0aee6
 pynetdicom/tests/test_presentation.py |  4 ++--
7b0aee6
 2 files changed, 16 insertions(+), 16 deletions(-)
7b0aee6
7b0aee6
diff --git a/pynetdicom/tests/test_assoc_user.py b/pynetdicom/tests/test_assoc_user.py
7b0aee6
index 95a623f4d..8f5ecb0b5 100644
7b0aee6
--- a/pynetdicom/tests/test_assoc_user.py
7b0aee6
+++ b/pynetdicom/tests/test_assoc_user.py
7b0aee6
@@ -164,7 +164,7 @@ def test_mode_assignment_raises(self):
7b0aee6
         """Test that assigning mode after init raises exception."""
7b0aee6
         user = ServiceUser(self.assoc, mode="acceptor")
7b0aee6
         assert user.mode == "acceptor"
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.mode = "requestor"
7b0aee6
 
7b0aee6
         assert user.mode == "acceptor"
7b0aee6
@@ -297,22 +297,22 @@ def test_primitive_assignment_raises(self):
7b0aee6
         with pytest.raises(RuntimeError, match=msg):
7b0aee6
             user.implementation_version_name = "1.2.3"
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.asynchronous_operations = (1, 1)
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.role_selection = {}
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.sop_class_common_extended = {}
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.sop_class_extended = {}
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.user_identity = "test"
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.extended_negotiation = []
7b0aee6
 
7b0aee6
     def test_add_neg_pre(self):
7b0aee6
@@ -1477,7 +1477,7 @@ def test_mode_assignment_raises(self):
7b0aee6
         """Test that assigning mode after init raises exception."""
7b0aee6
         user = ServiceUser(self.assoc, mode="requestor")
7b0aee6
         assert user.mode == "requestor"
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.mode = "acceptor"
7b0aee6
 
7b0aee6
         assert user.mode == "requestor"
7b0aee6
@@ -1601,22 +1601,22 @@ def test_primitive_assignment_raises(self):
7b0aee6
         with pytest.raises(RuntimeError, match=msg):
7b0aee6
             user.implementation_version_name = "1.2.3"
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.asynchronous_operations = (1, 1)
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.role_selection = {}
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.sop_class_common_extended = {}
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.sop_class_extended = {}
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.user_identity = "test"
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             user.extended_negotiation = []
7b0aee6
 
7b0aee6
     def test_accepted_common_raises(self):
7b0aee6
diff --git a/pynetdicom/tests/test_presentation.py b/pynetdicom/tests/test_presentation.py
7b0aee6
index 8153bb10a..54cd194f6 100644
7b0aee6
--- a/pynetdicom/tests/test_presentation.py
7b0aee6
+++ b/pynetdicom/tests/test_presentation.py
7b0aee6
@@ -374,7 +374,7 @@ def test_as_scp(self):
7b0aee6
         context = build_context("1.2.3")
7b0aee6
         assert context.as_scp is None
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             context.as_scp = True
7b0aee6
 
7b0aee6
         context._as_scp = True
7b0aee6
@@ -387,7 +387,7 @@ def test_as_scu(self):
7b0aee6
         context = build_context("1.2.3")
7b0aee6
         assert context.as_scu is None
7b0aee6
 
7b0aee6
-        with pytest.raises(AttributeError, match=r"can't set attribute"):
7b0aee6
+        with pytest.raises(AttributeError, match=r"can't set attribute|has no setter"):
7b0aee6
             context.as_scu = True
7b0aee6
 
7b0aee6
         context._as_scu = True