File: test_release.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 (43 lines) | stat: -rw-r--r-- 1,341 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
43
import builtins
import datetime
import re
from unittest import mock

from qrcode.release import update_manpage

OPEN = f"{builtins.__name__}.open"
DATA = 'test\n.TH "date" "version" "description"\nthis'


@mock.patch(OPEN, new_callable=mock.mock_open, read_data=".TH invalid")
def test_invalid_data(mock_file):
    update_manpage({"name": "qrcode", "new_version": "1.23"})
    mock_file.assert_called()
    mock_file().write.assert_not_called()


@mock.patch(OPEN, new_callable=mock.mock_open, read_data=DATA)
def test_not_qrcode(mock_file):
    update_manpage({"name": "not-qrcode"})
    mock_file.assert_not_called()


@mock.patch(OPEN, new_callable=mock.mock_open, read_data=DATA)
def test_no_change(mock_file):
    update_manpage({"name": "qrcode", "new_version": "version"})
    mock_file.assert_called()
    mock_file().write.assert_not_called()


@mock.patch(OPEN, new_callable=mock.mock_open, read_data=DATA)
def test_change(mock_file):
    update_manpage({"name": "qrcode", "new_version": "3.11"})
    expected = re.split(r"([^\n]*(?:\n|$))", DATA)[1::2]
    expected[1] = (
        expected[1]
        .replace("version", "3.11")
        .replace("date", datetime.datetime.now().strftime("%-d %b %Y"))
    )
    mock_file().write.assert_has_calls(
        [mock.call(line) for line in expected if line != ""], any_order=True
    )