Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use assertRaisesRegex instead of assertRaisesRegexp for Python 3.11 compatibility. #106

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pyzbar/tests/test_pyzbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def setUp(self):
)
self.maxDiff = None

# assertRaisesRegexp was a deprecated alias removed in Python 3.11
if not hasattr(self, 'assertRaisesRegex'):
self.assertRaisesRegex = self.assertRaisesRegexp

def tearDown(self):
self.code128 = self.empty = self.qrcode = None

Expand Down Expand Up @@ -145,31 +149,31 @@ def test_external_dependencies(self):
@patch('pyzbar.pyzbar.zbar_image_create')
def test_zbar_image_create_fail(self, zbar_image_create):
zbar_image_create.return_value = None
self.assertRaisesRegexp(
self.assertRaisesRegex(
PyZbarError, 'Could not create zbar image', decode, self.code128
)
zbar_image_create.assert_called_once_with()

@patch('pyzbar.pyzbar.zbar_image_scanner_create')
def test_zbar_image_scanner_create_fail(self, zbar_image_scanner_create):
zbar_image_scanner_create.return_value = None
self.assertRaisesRegexp(
self.assertRaisesRegex(
PyZbarError, 'Could not create image scanner', decode, self.code128
)
zbar_image_scanner_create.assert_called_once_with()

@patch('pyzbar.pyzbar.zbar_scan_image')
def test_zbar_scan_image_fail(self, zbar_scan_image):
zbar_scan_image.return_value = -1
self.assertRaisesRegexp(
self.assertRaisesRegex(
PyZbarError, 'Unsupported image format', decode, self.code128
)
self.assertEqual(1, zbar_scan_image.call_count)

def test_unsupported_bits_per_pixel(self):
# 16 bits-per-pixel
data = (list(range(3 * 3 * 2)), 3, 3)
self.assertRaisesRegexp(
self.assertRaisesRegex(
PyZbarError,
r'Unsupported bits-per-pixel \[16\]. Only \[8\] is supported.',
decode, data
Expand All @@ -179,7 +183,7 @@ def test_unsupported_bits_per_pixel(self):
def test_inconsistent_dimensions(self):
# Ten bytes but width x height indicates nine bytes
data = (list(range(10)), 3, 3)
self.assertRaisesRegexp(
self.assertRaisesRegex(
PyZbarError,
(
r'Inconsistent dimensions: image data of 10 bytes is not '
Expand Down