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
|
import pytest
from pytest_mock import MockerFixture
from typing import Optional, Tuple
from asciidoc import utils
@pytest.mark.parametrize(
"input,expected",
(
('/home/user', '/home/user'),
('~', None),
)
)
def test_userdir(mocker: MockerFixture, input: str, expected: Optional[str]) -> None:
mocker.patch('os.path.expanduser', return_value=input)
assert utils.userdir() == expected
@pytest.mark.parametrize(
"input,expected",
(
(' a ', 'a'),
('"a"', 'a'),
(' "b ', '"b'),
(' b" ', 'b"'),
('""', '""'),
),
)
def test_strip_quotes(input: str, expected: str) -> None:
assert utils.strip_quotes(input) == expected
@pytest.mark.parametrize(
"input,expected",
(
(('a', 'b'), ('a', 'b')),
(('', 'a', 'b'), ('a', 'b')),
(('a', 'b', ''), ('a', 'b', '')),
(('', 'a', 'b', ''), ('a', 'b', '')),
),
)
def test_lstrip_list(input: Tuple[str, ...], expected: Tuple[str, ...]) -> None:
assert utils.lstrip_list(input) == expected
@pytest.mark.parametrize(
"input,expected",
(
(('a', 'b'), ('a', 'b')),
(('', 'a', 'b'), ('', 'a', 'b')),
(('a', 'b', ''), ('a', 'b')),
(('', 'a', 'b', ''), ('', 'a', 'b')),
),
)
def test_rstrip_list(input: Tuple[str, ...], expected: Tuple[str, ...]) -> None:
assert utils.rstrip_list(input) == expected
@pytest.mark.parametrize(
"input,expected",
(
(('a', 'b'), ('a', 'b')),
(('', 'a', 'b'), ('a', 'b')),
(('a', 'b', ''), ('a', 'b')),
(('', 'a', 'b', ''), ('a', 'b')),
),
)
def test_strip_list(input: Tuple[str, ...], expected: Tuple[str, ...]) -> None:
assert utils.strip_list(input) == expected
@pytest.mark.parametrize(
"input,expected",
(
((1,), True),
([1], True),
('a', False),
),
)
def test_is_array(input, expected):
assert utils.is_array(input) == expected
@pytest.mark.parametrize(
"n,d,expected",
(
(42.0, 0, 42),
(42.4, 0, 42),
(42.5, 0, 43),
(42.6, 0, 43),
(42.9, 0, 43),
(42.0, 2, 42),
(42.5, 2, 42.5),
(42.550, 2, 42.55),
(42.554, 2, 42.55),
(42.555, 2, 42.56),
(42.556, 2, 42.56),
(42.559, 2, 42.56),
),
)
def test_py2round(n: float, d: int, expected: float) -> None:
assert utils.py2round(n, d) == expected
|