File: test_init.py

package info (click to toggle)
python-barcode 0.15.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 684 kB
  • sloc: python: 1,661; makefile: 23; sh: 9
file content (42 lines) | stat: -rw-r--r-- 1,337 bytes parent folder | download
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
import os
from io import BytesIO

import pytest

import barcode
from barcode.writer import SVGWriter

PATH = os.path.dirname(os.path.abspath(__file__))
TESTPATH = os.path.join(PATH, "test_outputs")


def test_generate_without_output():
    with pytest.raises(TypeError, match="'output' cannot be None"):
        barcode.generate("ean13", "123455559121112")


def test_generate_with_file():
    with open(os.path.join(TESTPATH, "generate_with_file.jpeg"), "wb") as f:
        barcode.generate("ean13", "123455559121112", output=f)


def test_generate_with_filepath():
    # FIXME: extension is added to the filepath even if you include it.
    rv = barcode.generate(
        "ean13",
        "123455559121112",
        output=os.path.join(TESTPATH, "generate_with_filepath"),
    )
    assert rv == os.path.abspath(os.path.join(TESTPATH, "generate_with_filepath.svg"))


def test_generate_with_file_and_writer():
    with open(os.path.join(TESTPATH, "generate_with_file_and_writer.jpeg"), "wb") as f:
        barcode.generate("ean13", "123455559121112", output=f, writer=SVGWriter())


def test_generate_with_bytesio():
    bio = BytesIO()
    barcode.generate("ean13", "123455559121112", output=bio)
    # XXX: File is not 100% deterministic; needs to be addressed at some point.
    # assert len(bio.getvalue()) == 6127  # noqa: ERA001