Skip to content

Commit

Permalink
Fix test_dataclasses for Python 3.13 (cython#6262)
Browse files Browse the repository at this point in the history
An exception changed.

Part of cython#6251
  • Loading branch information
da-woods committed Jun 25, 2024
1 parent e2fc0c7 commit 927bc6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Tools/dataclass_test_data/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3739,10 +3739,11 @@ class C:
self.assertEqual((c1.x, c1.y), (5, 10))

# Trying to replace y is an error.
with self.assertRaisesRegex(ValueError, 'init=False'):
# Tests modified to account for changed exception in Python 3.13
with self.assertRaisesRegex((ValueError, TypeError), 'init=False'):
replace(c, x=2, y=30)

with self.assertRaisesRegex(ValueError, 'init=False'):
with self.assertRaisesRegex((ValueError, TypeError), 'init=False'):
replace(c, y=30)

def test_classvar(self):
Expand Down Expand Up @@ -3775,7 +3776,8 @@ def __post_init__(self, y):

c = C(1, 10)
self.assertEqual(c.x, 10)
with self.assertRaisesRegex(ValueError, r"InitVar 'y' must be "
# Note - test modified to account for change in exception in Python 3.13
with self.assertRaisesRegex((ValueError, TypeError), r"InitVar 'y' must be "
"specified with replace()"):
replace(c, x=3)
c = replace(c, x=3, y=5)
Expand Down
6 changes: 3 additions & 3 deletions tests/run/test_dataclasses.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,9 @@ class TestReplace(unittest.TestCase):
c.y = 20
c1 = replace(c, x=5)
self.assertEqual((c1.x, c1.y), (5, 10))
with self.assertRaises(ValueError):
with self.assertRaises((ValueError, TypeError)):
replace(c, x=2, y=30)
with self.assertRaises(ValueError):
with self.assertRaises((ValueError, TypeError)):
replace(c, y=30)

def test_classvar(self):
Expand All @@ -1238,7 +1238,7 @@ class TestReplace(unittest.TestCase):
C = C_TestReplace_test_initvar_is_specified
c = C(1, 10)
self.assertEqual(c.x, 10)
with self.assertRaises(ValueError):
with self.assertRaises((ValueError, TypeError)):
replace(c, x=3)
c = replace(c, x=3, y=5)
self.assertEqual(c.x, 15)
Expand Down

0 comments on commit 927bc6b

Please sign in to comment.