FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-escpos/test/test_function_image.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_image.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
179 lines (138 loc) · 5.39 KB
Breadcrumbs
python-escpos
/
test
/
test_function_image.py
Copy path
File metadata and controls
179 lines (138 loc) · 5.39 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python
""" Image function tests- Check that image print commands are sent correctly.
:author: `Michael Billington <michael.billington@gmail.com>`_
:organization: `python-escpos <https://github.com/python-escpos>`_
:copyright: Copyright (c) 2016 `Michael Billington <michael.billington@gmail.com>`_
:license: MIT
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
unicode_literals
import
pytest
from
PIL
import
Image
import
escpos
.
printer
as
printer
from
escpos
.
exceptions
import
ImageWidthError
# Raster format print
def
test_bit_image_black
():
"""
Test printing solid black bit image (raster)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/canvas_black.png'
,
impl
=
"bitImageRaster"
)
assert
(
instance
.
output
==
b'
\x1d
v0
\x00
\x01
\x00
\x01
\x00
\x80
'
)
# Same thing w/ object created on the fly, rather than a filename
instance
=
printer
.
Dummy
()
im
=
Image
.
new
(
"RGB"
, (
1
,
1
), (
0
,
0
,
0
))
instance
.
image
(
im
,
impl
=
"bitImageRaster"
)
assert
(
instance
.
output
==
b'
\x1d
v0
\x00
\x01
\x00
\x01
\x00
\x80
'
)
def
test_bit_image_white
():
"""
Test printing solid white bit image (raster)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/canvas_white.png'
,
impl
=
"bitImageRaster"
)
assert
(
instance
.
output
==
b'
\x1d
v0
\x00
\x01
\x00
\x01
\x00
\x00
'
)
def
test_bit_image_both
():
"""
Test printing black/white bit image (raster)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/black_white.png'
,
impl
=
"bitImageRaster"
)
assert
(
instance
.
output
==
b'
\x1d
v0
\x00
\x01
\x00
\x02
\x00
\xc0
\x00
'
)
def
test_bit_image_transparent
():
"""
Test printing black/transparent bit image (raster)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/black_transparent.png'
,
impl
=
"bitImageRaster"
)
assert
(
instance
.
output
==
b'
\x1d
v0
\x00
\x01
\x00
\x02
\x00
\xc0
\x00
'
)
# Column format print
def
test_bit_image_colfmt_black
():
"""
Test printing solid black bit image (column format)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/canvas_black.png'
,
impl
=
"bitImageColumn"
)
assert
(
instance
.
output
==
b'
\x1b
3
\x10
\x1b
*!
\x01
\x00
\x80
\x00
\x00
\x0a
\x1b
2'
)
def
test_bit_image_colfmt_white
():
"""
Test printing solid white bit image (column format)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/canvas_white.png'
,
impl
=
"bitImageColumn"
)
assert
(
instance
.
output
==
b'
\x1b
3
\x10
\x1b
*!
\x01
\x00
\x00
\x00
\x00
\x0a
\x1b
2'
)
def
test_bit_image_colfmt_both
():
"""
Test printing black/white bit image (column format)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/black_white.png'
,
impl
=
"bitImageColumn"
)
assert
(
instance
.
output
==
b'
\x1b
3
\x10
\x1b
*!
\x02
\x00
\x80
\x00
\x00
\x80
\x00
\x00
\x0a
\x1b
2'
)
def
test_bit_image_colfmt_transparent
():
"""
Test printing black/transparent bit image (column format)
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/black_transparent.png'
,
impl
=
"bitImageColumn"
)
assert
(
instance
.
output
==
b'
\x1b
3
\x10
\x1b
*!
\x02
\x00
\x80
\x00
\x00
\x80
\x00
\x00
\x0a
\x1b
2'
)
# Graphics print
def
test_graphics_black
():
"""
Test printing solid black graphics
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/canvas_black.png'
,
impl
=
"graphics"
)
assert
(
instance
.
output
==
b'
\x1d
(L
\x0b
\x00
0p0
\x01
\x01
1
\x01
\x00
\x01
\x00
\x80
\x1d
(L
\x02
\x00
02'
)
def
test_graphics_white
():
"""
Test printing solid white graphics
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/canvas_white.png'
,
impl
=
"graphics"
)
assert
(
instance
.
output
==
b'
\x1d
(L
\x0b
\x00
0p0
\x01
\x01
1
\x01
\x00
\x01
\x00
\x00
\x1d
(L
\x02
\x00
02'
)
def
test_graphics_both
():
"""
Test printing black/white graphics
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/black_white.png'
,
impl
=
"graphics"
)
assert
(
instance
.
output
==
b'
\x1d
(L
\x0c
\x00
0p0
\x01
\x01
1
\x02
\x00
\x02
\x00
\xc0
\x00
\x1d
(L
\x02
\x00
02'
)
def
test_graphics_transparent
():
"""
Test printing black/transparent graphics
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/black_transparent.png'
,
impl
=
"graphics"
)
assert
(
instance
.
output
==
b'
\x1d
(L
\x0c
\x00
0p0
\x01
\x01
1
\x02
\x00
\x02
\x00
\xc0
\x00
\x1d
(L
\x02
\x00
02'
)
def
test_large_graphics
():
"""
Test whether 'large' graphics that induce a fragmentation are handled correctly.
"""
instance
=
printer
.
Dummy
()
instance
.
image
(
'test/resources/black_white.png'
,
impl
=
"bitImageRaster"
,
fragment_height
=
1
)
assert
(
instance
.
output
==
b'
\x1d
v0
\x00
\x01
\x00
\x01
\x00
\xc0
\x1d
v0
\x00
\x01
\x00
\x01
\x00
\x00
'
)
@
pytest
.
fixture
def
dummy_with_width
():
instance
=
printer
.
Dummy
()
instance
.
profile
.
profile_data
=
{
'media'
: {
'width'
: {
'pixels'
:
384
}
}
}
return
instance
def
test_width_too_large
(
dummy_with_width
):
"""
Test printing an image that is too large in width.
"""
instance
=
dummy_with_width
with
pytest
.
raises
(
ImageWidthError
):
instance
.
image
(
Image
.
new
(
"RGB"
, (
385
,
200
)))
instance
.
image
(
Image
.
new
(
"RGB"
, (
384
,
200
)))
def
test_center_image
(
dummy_with_width
):
instance
=
dummy_with_width
with
pytest
.
raises
(
ImageWidthError
):
instance
.
image
(
Image
.
new
(
"RGB"
, (
385
,
200
)),
center
=
True
)
instance
.
image
(
Image
.
new
(
"RGB"
, (
384
,
200
)),
center
=
True
)
Back
|
FazBrowse Home
|
New Git URL