Fix test suite without PIL
The library and its testsuite has expanded, requiring imports to be caught as well as more tests skipped.
This commit is contained in:
parent
3c685bed60
commit
e767f861b0
@ -8,6 +8,8 @@ Summary: Python QR Code image generator
|
|||||||
License: BSD
|
License: BSD
|
||||||
URL: https://github.com/lincolnloop/python-qrcode
|
URL: https://github.com/lincolnloop/python-qrcode
|
||||||
Source0: https://pypi.python.org/packages/source/q/qrcode/qrcode-%{version}.tar.gz
|
Source0: https://pypi.python.org/packages/source/q/qrcode/qrcode-%{version}.tar.gz
|
||||||
|
# skip all PIL-dependent tests on RHEL
|
||||||
|
Patch0: qrcode-7.3.1-image-tests.patch
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
|
|
||||||
BuildRequires: python3-devel
|
BuildRequires: python3-devel
|
||||||
@ -43,7 +45,7 @@ Summary: Python 3 QR Code image generator (core library)
|
|||||||
Core Python 3 module for QR code generation. Does not contain image rendering.
|
Core Python 3 module for QR code generation. Does not contain image rendering.
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup -n qrcode-%{version}
|
%autosetup -n qrcode-%{version} -p1
|
||||||
|
|
||||||
# The pure plugin requires pymaging which is not packaged in Fedora.
|
# The pure plugin requires pymaging which is not packaged in Fedora.
|
||||||
rm qrcode/image/pure.py*
|
rm qrcode/image/pure.py*
|
||||||
@ -69,10 +71,6 @@ rm -r %{buildroot}%{python3_sitelib}/%{pkgname}/tests
|
|||||||
ln -s qr %{buildroot}%{_bindir}/qrcode
|
ln -s qr %{buildroot}%{_bindir}/qrcode
|
||||||
|
|
||||||
%check
|
%check
|
||||||
%if 0%{?rhel}
|
|
||||||
# test method requires PIL
|
|
||||||
sed -i s/test_render_pil/disabled_render_pil/g qrcode/tests/test_qrcode.py
|
|
||||||
%endif
|
|
||||||
PYTHONPATH=%{buildroot}%{python3_sitelib} \
|
PYTHONPATH=%{buildroot}%{python3_sitelib} \
|
||||||
%{__python3} -m unittest -v qrcode.tests.test_qrcode.QRCodeTests
|
%{__python3} -m unittest -v qrcode.tests.test_qrcode.QRCodeTests
|
||||||
|
|
||||||
|
186
qrcode-7.3.1-image-tests.patch
Normal file
186
qrcode-7.3.1-image-tests.patch
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
diff --git a/qrcode/tests/test_qrcode.py b/qrcode/tests/test_qrcode.py
|
||||||
|
index ce9a807..9709974 100644
|
||||||
|
--- a/qrcode/tests/test_qrcode.py
|
||||||
|
+++ b/qrcode/tests/test_qrcode.py
|
||||||
|
@@ -17,9 +17,12 @@ import qrcode.image.svg
|
||||||
|
import qrcode.util
|
||||||
|
from qrcode.exceptions import DataOverflowError
|
||||||
|
from qrcode.image.base import BaseImage
|
||||||
|
-from qrcode.image.pil import Image as pil_Image
|
||||||
|
-from qrcode.image.styledpil import StyledPilImage
|
||||||
|
-from qrcode.image.styles import colormasks, moduledrawers
|
||||||
|
+try:
|
||||||
|
+ from qrcode.image.pil import Image as pil_Image
|
||||||
|
+ from qrcode.image.styledpil import StyledPilImage
|
||||||
|
+ from qrcode.image.styles import colormasks, moduledrawers
|
||||||
|
+except ImportError:
|
||||||
|
+ pil_Image = None
|
||||||
|
from qrcode.tests.svg import SvgImageWhite
|
||||||
|
from qrcode.util import MODE_8BIT_BYTE, MODE_ALPHA_NUM, MODE_NUMBER, QRData
|
||||||
|
|
||||||
|
@@ -106,6 +109,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
qr.make()
|
||||||
|
self.assertEqual(qr.data_list[0].mode, MODE_8BIT_BYTE)
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_pil(self):
|
||||||
|
qr = qrcode.QRCode()
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -113,24 +117,28 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
self.assertIsInstance(img.get_image(), pil_Image.Image)
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_pil_with_transparent_background(self):
|
||||||
|
qr = qrcode.QRCode()
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(back_color='TransParent')
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_pil_with_red_background(self):
|
||||||
|
qr = qrcode.QRCode()
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(back_color='red')
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_pil_with_rgb_color_tuples(self):
|
||||||
|
qr = qrcode.QRCode()
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(back_color=(255, 195, 235), fill_color=(55, 95, 35))
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_with_pattern(self):
|
||||||
|
qr = qrcode.QRCode(mask_pattern=3)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -230,12 +238,14 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
img.save(io.BytesIO(), kind='FISH')
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_pil_image(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_embeded_image(self):
|
||||||
|
embeded_img = pil_Image.new('RGB', (10, 10), color='red')
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
@@ -243,6 +253,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, embeded_image=embeded_img)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_embeded_image_path(self):
|
||||||
|
tmpfile = os.path.join(self.tmpdir, "test.png")
|
||||||
|
embeded_img = pil_Image.new('RGB', (10, 10), color='red')
|
||||||
|
@@ -253,42 +264,49 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
os.remove(tmpfile)
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_square_module_drawer(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, module_drawer=moduledrawers.SquareModuleDrawer())
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_gapped_module_drawer(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, module_drawer=moduledrawers.GappedSquareModuleDrawer())
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_circle_module_drawer(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, module_drawer=moduledrawers.CircleModuleDrawer())
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_rounded_module_drawer(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, module_drawer=moduledrawers.RoundedModuleDrawer())
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_vertical_bars_module_drawer(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, module_drawer=moduledrawers.VerticalBarsDrawer())
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_horizontal_bars_module_drawer(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, module_drawer=moduledrawers.HorizontalBarsDrawer())
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_default_solid_color_mask(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -296,6 +314,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, color_mask=mask)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_solid_color_mask(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -303,6 +322,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, color_mask=mask)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_color_mask_with_transparency(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -311,6 +331,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
assert img.mode == "RGBA"
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_radial_gradient_color_mask(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -318,6 +339,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, color_mask=mask)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_square_gradient_color_mask(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -325,6 +347,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, color_mask=mask)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_horizontal_gradient_color_mask(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -332,6 +355,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, color_mask=mask)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_vertical_gradient_color_mask(self):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
||||||
|
qr.add_data(UNICODE_TEXT)
|
||||||
|
@@ -339,6 +363,7 @@ class QRCodeTests(unittest.TestCase):
|
||||||
|
img = qr.make_image(image_factory=StyledPilImage, color_mask=mask)
|
||||||
|
img.save(io.BytesIO())
|
||||||
|
|
||||||
|
+ @unittest.skipIf(not pil_Image, "Requires PIL")
|
||||||
|
def test_render_styled_with_image_color_mask(self):
|
||||||
|
img_mask = pil_Image.new('RGB', (10, 10), color='red')
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
|
Loading…
Reference in New Issue
Block a user