Fixes barcode tests not running

This commit is contained in:
Trenton Holmes 2023-04-01 17:38:18 -07:00
parent ce41ac9158
commit 1b4020b3d7
No known key found for this signature in database
GPG Key ID: 4815A6E23A56B8D1

View File

@ -1,7 +1,6 @@
import shutil import shutil
from pathlib import Path from pathlib import Path
from unittest import mock from unittest import mock
import platform
import pytest import pytest
from django.conf import settings from django.conf import settings
@ -16,10 +15,16 @@ from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import FileSystemAssertsMixin from documents.tests.utils import FileSystemAssertsMixin
from PIL import Image from PIL import Image
try:
import zxingcpp # noqa: F401
HAS_ZXING_LIB = True
except ImportError:
HAS_ZXING_LIB = False
@override_settings(CONSUMER_BARCODE_SCANNER="PYZBAR") @override_settings(CONSUMER_BARCODE_SCANNER="PYZBAR")
class TestBarcode(DirectoriesMixin, FileSystemAssertsMixin, TestCase): class TestBarcode(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
SAMPLE_DIR = Path(__file__).parent / "samples" SAMPLE_DIR = Path(__file__).parent / "samples"
BARCODE_SAMPLE_DIR = SAMPLE_DIR / "barcodes" BARCODE_SAMPLE_DIR = SAMPLE_DIR / "barcodes"
@ -859,7 +864,6 @@ class TestBarcode(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
class TestAsnBarcode(DirectoriesMixin, TestCase): class TestAsnBarcode(DirectoriesMixin, TestCase):
SAMPLE_DIR = Path(__file__).parent / "samples" SAMPLE_DIR = Path(__file__).parent / "samples"
BARCODE_SAMPLE_DIR = SAMPLE_DIR / "barcodes" BARCODE_SAMPLE_DIR = SAMPLE_DIR / "barcodes"
@ -1060,7 +1064,7 @@ class TestAsnBarcode(DirectoriesMixin, TestCase):
@pytest.mark.skipif( @pytest.mark.skipif(
platform.machine().upper() not in {"AMD64"}, not HAS_ZXING_LIB,
reason="No zxingcpp", reason="No zxingcpp",
) )
@override_settings(CONSUMER_BARCODE_SCANNER="ZXING") @override_settings(CONSUMER_BARCODE_SCANNER="ZXING")
@ -1069,7 +1073,7 @@ class TestBarcodeZxing(TestBarcode):
@pytest.mark.skipif( @pytest.mark.skipif(
platform.machine().upper() not in {"AMD64"}, not HAS_ZXING_LIB,
reason="No zxingcpp", reason="No zxingcpp",
) )
@override_settings(CONSUMER_BARCODE_SCANNER="ZXING") @override_settings(CONSUMER_BARCODE_SCANNER="ZXING")