forked from WhyNotHugo/python-barcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_writers.py
More file actions
51 lines (34 loc) · 1.56 KB
/
test_writers.py
File metadata and controls
51 lines (34 loc) · 1.56 KB
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
from __future__ import annotations
import os
from io import BytesIO
from barcode import EAN13
from barcode.writer import ImageWriter
from barcode.writer import SVGWriter
PATH = os.path.dirname(os.path.abspath(__file__))
TESTPATH = os.path.join(PATH, "test_outputs")
if ImageWriter is not None:
def test_saving_image_to_byteio() -> None:
assert ImageWriter is not None # workaround for mypy
rv = BytesIO()
EAN13(str(100000902922), writer=ImageWriter()).write(rv)
with open(f"{TESTPATH}/somefile.jpeg", "wb") as f:
EAN13("100000011111", writer=ImageWriter()).write(f)
def test_saving_rgba_image() -> None:
assert ImageWriter is not None # workaround for mypy
rv = BytesIO()
EAN13(str(100000902922), writer=ImageWriter()).write(rv)
with open(f"{TESTPATH}/ean13-with-transparent-bg.png", "wb") as f:
writer = ImageWriter(mode="RGBA")
EAN13("100000011111", writer=writer).write(
f, options={"background": "rgba(255,0,0,0)"}
)
def test_saving_svg_to_byteio() -> None:
rv = BytesIO()
EAN13(str(100000902922), writer=SVGWriter()).write(rv)
with open(f"{TESTPATH}/somefile.svg", "wb") as f:
EAN13("100000011111", writer=SVGWriter()).write(f)
def test_saving_svg_to_byteio_with_guardbar() -> None:
rv = BytesIO()
EAN13(str(100000902922), writer=SVGWriter(), guardbar=True).write(rv)
with open(f"{TESTPATH}/somefile_guardbar.svg", "wb") as f:
EAN13("100000011111", writer=SVGWriter(), guardbar=True).write(f)