Skip to content

Commit

Permalink
tests: Replace assertRaisesRegexp with assertRaisesRegex
Browse files Browse the repository at this point in the history
unittest.TestCase.assertRaisesRegexp was deprecated in Python 3.2 and is
removed in Python 3.12.
  • Loading branch information
swt2c committed Feb 2, 2023
1 parent af88104 commit dae602d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/PexpectTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def assertRaises(self, excClass):
raise AssertionError("%s was not raised" % excClass)

@contextlib.contextmanager
def assertRaisesRegexp(self, excClass, pattern):
def assertRaisesRegex(self, excClass, pattern):
import re
try:
yield
Expand Down
8 changes: 4 additions & 4 deletions tests/test_expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,13 @@ def test_greed_exact(self):

def test_bad_arg(self):
p = pexpect.spawn('cat')
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect(1)
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect([1, b'2'])
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect_exact(1)
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect_exact([1, b'2'])

def test_timeout_none(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_bad_child_pid(self):
# Force an invalid state to test isalive
child.ptyproc.terminated = 0
try:
with self.assertRaisesRegexp(pexpect.ExceptionPexpect,
with self.assertRaisesRegex(pexpect.ExceptionPexpect,
".*" + expect_errmsg):
child.isalive()
finally:
Expand All @@ -224,7 +224,7 @@ def test_bad_child_pid(self):
def test_bad_arguments_suggest_fdpsawn(self):
" assert custom exception for spawn(int). "
expect_errmsg = "maybe you want to use fdpexpect.fdspawn"
with self.assertRaisesRegexp(pexpect.ExceptionPexpect,
with self.assertRaisesRegex(pexpect.ExceptionPexpect,
".*" + expect_errmsg):
pexpect.spawn(1)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_popen_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ def test_unexpected_eof(self):

def test_bad_arg(self):
p = PopenSpawn('cat')
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect(1)
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect([1, b'2'])
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect_exact(1)
with self.assertRaisesRegexp(TypeError, '.*must be one of'):
with self.assertRaisesRegex(TypeError, '.*must be one of'):
p.expect_exact([1, b'2'])

def test_timeout_none(self):
Expand Down

0 comments on commit dae602d

Please sign in to comment.