@@ -230,6 +230,35 @@ def test_render_styled_with_embeded_image_path(self):
230230 img .save (io .BytesIO ())
231231 os .remove (tmpfile )
232232
233+ @unittest .skipIf (not pil_Image , "Requires PIL" )
234+ def test_embedded_image_and_error_correction (self ):
235+ "If an embedded image is specified, error correction must be the highest so the QR code is readable"
236+ tmpfile = os .path .join (self .tmpdir , "test.png" )
237+ embedded_img = pil_Image .new ("RGB" , (10 , 10 ), color = "red" )
238+ embedded_img .save (tmpfile )
239+
240+ qr = qrcode .QRCode (error_correction = qrcode .ERROR_CORRECT_L )
241+ qr .add_data (UNICODE_TEXT )
242+ with self .assertRaises (ValueError ):
243+ qr .make_image (embeded_image_path = tmpfile )
244+
245+ qr = qrcode .QRCode (error_correction = qrcode .ERROR_CORRECT_M )
246+ qr .add_data (UNICODE_TEXT )
247+ with self .assertRaises (ValueError ):
248+ qr .make_image (embeded_image_path = tmpfile )
249+
250+ qr = qrcode .QRCode (error_correction = qrcode .ERROR_CORRECT_Q )
251+ qr .add_data (UNICODE_TEXT )
252+ with self .assertRaises (ValueError ):
253+ qr .make_image (embeded_image_path = tmpfile )
254+
255+ # The only accepted correction level when an embedded image is provided
256+ qr = qrcode .QRCode (error_correction = qrcode .ERROR_CORRECT_H )
257+ qr .add_data (UNICODE_TEXT )
258+ qr .make_image (embeded_image_path = tmpfile )
259+
260+ os .remove (tmpfile )
261+
233262 @unittest .skipIf (not pil_Image , "Requires PIL" )
234263 def test_render_styled_with_square_module_drawer (self ):
235264 qr = qrcode .QRCode (error_correction = qrcode .ERROR_CORRECT_L )
0 commit comments