Skip to content

Commit c38fb6f

Browse files
committed
Add a global constant whether PIL is available or not.
1 parent eb73ec6 commit c38fb6f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

qrcode/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
from importlib.util import find_spec
2+
13
# QR error correct levels
24
ERROR_CORRECT_L = 1
35
ERROR_CORRECT_M = 0
46
ERROR_CORRECT_Q = 3
57
ERROR_CORRECT_H = 2
8+
9+
# Constant whether the PIL library is installed.
10+
PIL_AVAILABLE = find_spec("PIL") is not None

qrcode/tests/test_module.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import subprocess
22
import sys
33
import tempfile
4-
from importlib.util import find_spec
54
from pathlib import Path
65

76
import pytest
87

9-
PIL_NOT_AVAILABLE = find_spec("PIL") is None
8+
from qrcode.constants import PIL_AVAILABLE
109

1110

1211
def test_module_help():
@@ -27,7 +26,7 @@ def test_module_help():
2726
assert "--factory" in result.stdout
2827

2928

30-
@pytest.mark.skipif(PIL_NOT_AVAILABLE, reason="PIL is not installed")
29+
@pytest.mark.skipif(not PIL_AVAILABLE, reason="PIL is not installed")
3130
def test_module_generate_qrcode():
3231
"""Test that the module can generate a QR code image."""
3332
with tempfile.TemporaryDirectory() as temp_dir:

0 commit comments

Comments
 (0)