-
Notifications
You must be signed in to change notification settings - Fork 9
/
tests.py
75 lines (62 loc) · 1.71 KB
/
tests.py
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
import unittest
from engine import SuperFormatter
class TestSuperFormatterMethods(unittest.TestCase):
"""tests."""
def test_basic(self):
sf = SuperFormatter()
self.assertEqual(
sf.format('a is {a}', a="A"),
"a is A"
)
def test_repeat_list(self):
sf = SuperFormatter()
self.assertEqual(
sf.format('''Table of contents:
{chapters:repeat:Chapter {{item}}
}''', chapters=["I", "II", "III", "IV"]),
'''Table of contents:
Chapter I
Chapter II
Chapter III
Chapter IV
'''
)
def test_repeat_dict(self):
sf = SuperFormatter()
self.assertEqual(
sf.format(
'''Books:
{books:repeat:"{{item[1]}}" by {{item[0]}}
----
}''',
books={
'Victor Hugo': 'Notre Dame de Paris',
'Joseph Conrad': 'Lord Jim',
}),
'''Books:
"Notre Dame de Paris" by Victor Hugo
----
"Lord Jim" by Joseph Conrad
----
'''
)
def test_call(self):
sf = SuperFormatter()
self.assertEqual(
sf.format('My name is {name.upper:call}', name="eric"),
'My name is ERIC'
)
def test_if_static(self):
sf = SuperFormatter()
self.assertEqual(
sf.format('Action: Back / Logout {manager:if:/ Delete}', manager=True),
'Action: Back / Logout / Delete'
)
def test_if_with_fields(self):
sf = SuperFormatter()
self.assertEqual(
sf.format('Action: Back / Logout {manager:if:/ Delete {id}}', manager=True, id=34),
'Action: Back / Logout / Delete 34'
)
if __name__ == '__main__':
unittest.main()