File: test_qrcode_pypng.py

package info (click to toggle)
python-qrcode 8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 924 kB
  • sloc: python: 2,761; sh: 16; makefile: 11
file content (35 lines) | stat: -rw-r--r-- 944 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
import io
from unittest import mock

import pytest


import qrcode
import qrcode.util
from qrcode.image.pure import PyPNGImage
from qrcode.tests.consts import UNICODE_TEXT

png = pytest.importorskip("png", reason="png is not installed")


def test_render_pypng():
    qr = qrcode.QRCode()
    qr.add_data(UNICODE_TEXT)
    img = qr.make_image(image_factory=PyPNGImage)
    assert isinstance(img.get_image(), png.Writer)

    print(img.width, img.box_size, img.border)
    img.save(io.BytesIO())


def test_render_pypng_to_str():
    qr = qrcode.QRCode()
    qr.add_data(UNICODE_TEXT)
    img = qr.make_image(image_factory=PyPNGImage)
    assert isinstance(img.get_image(), png.Writer)

    mock_open = mock.mock_open()
    with mock.patch("qrcode.image.pure.open", mock_open, create=True):
        img.save("test_file.png")
    mock_open.assert_called_once_with("test_file.png", "wb")
    mock_open("test_file.png", "wb").write.assert_called()