Skip to content

Commit

Permalink
Fix AttributeError tests for Python 3.11
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
musicinmybrain committed Mar 16, 2022
1 parent d945d13 commit 2126bd9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions pynetdicom/tests/test_assoc_user.py
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pynetdicom/tests/test_presentation.py
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2126bd9

Please sign in to comment.