mirror of
https://github.com/python-escpos/python-escpos
synced 2025-09-13 09:09:58 +00:00
Feature/check barcodes (#255)
* add a method to check barcode code format ensure that the code to print is compatible with the ESC/POS formats and also automatically check this format before printing (barcode() method). * rewrite test using pytest's parametrize functionality * add test for the 'check' argument * update authors list
This commit is contained in:

committed by
Patrick Kanzler

parent
d78a6f1699
commit
456f5b7aa6
@@ -7,7 +7,7 @@ from __future__ import unicode_literals
|
||||
import escpos.printer as printer
|
||||
from escpos.constants import BARCODE_TYPE_A, BARCODE_TYPE_B
|
||||
from escpos.capabilities import Profile, BARCODE_B
|
||||
from escpos.exceptions import BarcodeTypeError
|
||||
from escpos.exceptions import BarcodeTypeError, BarcodeCodeError
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -36,3 +36,17 @@ def test_lacks_support(bctype, supports_b):
|
||||
instance.barcode('test', bctype)
|
||||
|
||||
assert instance.output == b''
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bctype,data", [
|
||||
('EAN13', 'AA'),
|
||||
('CODE128', '{D2354AA'),
|
||||
])
|
||||
def test_code_check(bctype, data):
|
||||
"""should raise an error if the barcode code is invalid.
|
||||
"""
|
||||
instance = printer.Dummy()
|
||||
with pytest.raises(BarcodeCodeError):
|
||||
instance.barcode(data, bctype)
|
||||
|
||||
assert instance.output == b''
|
||||
|
Reference in New Issue
Block a user