FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-escpos/test/test_function_barcode.py at development · python-escpos/python-escpos · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python-escpos
/
python-escpos
Public
Notifications
You must be signed in to change notification settings
Fork
316
Star
1.3k
Code
Issues
60
Pull requests
12
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-escpos
/
test
/
test_function_barcode.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (43 loc) · 1.52 KB
Breadcrumbs
python-escpos
/
test
/
test_function_barcode.py
Copy path
File metadata and controls
52 lines (43 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
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
,
BarcodeCodeError
import
pytest
@
pytest
.
mark
.
parametrize
(
"bctype,data,expected"
, [
(
'EAN13'
,
'4006381333931'
,
b'
\x1b
a
\x01
\x1d
h@
\x1d
w
\x03
\x1d
f
\x00
\x1d
H
\x02
\x1d
k
\x02
4006381333931
\x00
'
)
])
def
test_barcode
(
bctype
,
data
,
expected
):
"""should generate different barcode types correctly.
"""
instance
=
printer
.
Dummy
()
instance
.
barcode
(
data
,
bctype
)
assert
instance
.
output
==
expected
@
pytest
.
mark
.
parametrize
(
"bctype,supports_b"
, [
(
'invalid'
,
True
),
(
'CODE128'
,
False
),
])
def
test_lacks_support
(
bctype
,
supports_b
):
"""should raise an error if the barcode type is not supported.
"""
profile
=
Profile
(
features
=
{
BARCODE_B
:
supports_b
})
instance
=
printer
.
Dummy
(
profile
=
profile
)
with
pytest
.
raises
(
BarcodeTypeError
):
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''
Back
|
FazBrowse Home
|
New Git URL