blob: b55c2306c90e1afdcbb1a8c69f9d37b45296fd2d (
plain)
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
|
import pytest
from snakeoil.strings import doc_dedent, pluralism
class TestPluralism:
def test_none(self):
# default
assert pluralism([]) == 's'
# different suffix for nonexistence
assert pluralism([], none='') == ''
def test_singular(self):
# default
assert pluralism([1]) == ''
# different suffix for singular existence
assert pluralism([1], singular='o') == 'o'
def test_plural(self):
# default
assert pluralism([1, 2]) == 's'
# different suffix for plural existence
assert pluralism([1, 2], plural='ies') == 'ies'
def test_int(self):
assert pluralism(0) == 's'
assert pluralism(1) == ''
assert pluralism(2) == 's'
class TestDocDedent:
def test_empty(self):
s = ''
assert s == doc_dedent(s)
def test_non_string(self):
with pytest.raises(TypeError):
doc_dedent(None)
def test_line(self):
s = 'line'
assert s == doc_dedent(s)
def test_indented_line(self):
for indent in ('\t', ' '):
s = f'{indent}line'
assert 'line' == doc_dedent(s)
def test_docstring(self):
s = """Docstring to test.
foo bar
"""
assert 'Docstring to test.\n\nfoo bar\n' == doc_dedent(s)
def test_all_indented(self):
s = """\
Docstring to test.
foo bar
"""
assert 'Docstring to test.\n\nfoo bar\n' == doc_dedent(s)
|