FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-escpos/test/test_function_set.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_set.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
280 lines (215 loc) · 8.73 KB
Breadcrumbs
python-escpos
/
test
/
test_function_set.py
Copy path
File metadata and controls
280 lines (215 loc) · 8.73 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
unicode_literals
import
six
import
escpos
.
printer
as
printer
from
escpos
.
constants
import
TXT_NORMAL
,
TXT_STYLE
,
SET_FONT
from
escpos
.
constants
import
TXT_SIZE
# Default test, please copy and paste this block to test set method calls
def
test_default_values
():
instance
=
printer
.
Dummy
()
instance
.
set
()
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
# Size tests
def
test_set_size_2h
():
instance
=
printer
.
Dummy
()
instance
.
set
(
double_height
=
True
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'2h'
],
# Double height text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
def
test_set_size_2w
():
instance
=
printer
.
Dummy
()
instance
.
set
(
double_width
=
True
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'2w'
],
# Double width text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
def
test_set_size_2x
():
instance
=
printer
.
Dummy
()
instance
.
set
(
double_height
=
True
,
double_width
=
True
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'2x'
],
# Double text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
def
test_set_size_custom
():
instance
=
printer
.
Dummy
()
instance
.
set
(
custom_size
=
True
,
width
=
8
,
height
=
7
)
expected_sequence
=
(
TXT_SIZE
,
# Custom text size, no normal reset
six
.
int2byte
(
TXT_STYLE
[
'width'
][
8
]
+
TXT_STYLE
[
'height'
][
7
]),
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
# Flip
def
test_set_flip
():
instance
=
printer
.
Dummy
()
instance
.
set
(
flip
=
True
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
True
],
# Flip ON
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
# Smooth
def
test_smooth
():
instance
=
printer
.
Dummy
()
instance
.
set
(
smooth
=
True
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
True
],
# Smooth ON
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
# Type
def
test_set_bold
():
instance
=
printer
.
Dummy
()
instance
.
set
(
bold
=
True
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
True
],
# Bold ON
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
def
test_set_underline
():
instance
=
printer
.
Dummy
()
instance
.
set
(
underline
=
1
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
1
],
# Underline ON, type 1
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
def
test_set_underline2
():
instance
=
printer
.
Dummy
()
instance
.
set
(
underline
=
2
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
2
],
# Underline ON, type 2
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
# Align
def
test_align_center
():
instance
=
printer
.
Dummy
()
instance
.
set
(
align
=
'center'
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'center'
],
# Align center
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
def
test_align_right
():
instance
=
printer
.
Dummy
()
instance
.
set
(
align
=
'right'
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'right'
],
# Align right
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
# Densities
def
test_densities
():
for
density
in
range
(
8
):
instance
=
printer
.
Dummy
()
instance
.
set
(
density
=
density
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'density'
][
density
],
# Custom density from 0 to 8
TXT_STYLE
[
'invert'
][
False
]
# Inverted OFF
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
# Invert
def
test_invert
():
instance
=
printer
.
Dummy
()
instance
.
set
(
invert
=
True
)
expected_sequence
=
(
TXT_NORMAL
,
TXT_STYLE
[
'size'
][
'normal'
],
# Normal text size
TXT_STYLE
[
'flip'
][
False
],
# Flip OFF
TXT_STYLE
[
'smooth'
][
False
],
# Smooth OFF
TXT_STYLE
[
'bold'
][
False
],
# Bold OFF
TXT_STYLE
[
'underline'
][
0
],
# Underline OFF
SET_FONT
(
b'
\x00
'
),
# Default font
TXT_STYLE
[
'align'
][
'left'
],
# Align left
TXT_STYLE
[
'invert'
][
True
]
# Inverted ON
)
assert
(
instance
.
output
==
b''
.
join
(
expected_sequence
))
Back
|
FazBrowse Home
|
New Git URL