-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_replazer.py
executable file
·76 lines (67 loc) · 2.58 KB
/
test_replazer.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
76
#!/usr/bin/env python
import unittest
from replazer import (get_variables_from,
render_lines_with,
VariableNotDefinedError)
class Test(unittest.TestCase):
def testGetsNoVariablesFromListWithNone(self):
my_list = ["Hello World",
"I am a text",
"with no variables",
]
output = get_variables_from(my_list)
expected = set()
self.assertSetEqual(expected, output)
def testTextIsUnalteredWhenNoVariablesAreIncludedAfterRendering(self):
my_list = ["Hello World",
"I am a text",
"with no variables",
]
output = render_lines_with(set(), my_list)
expected = my_list
self.assertListEqual(output, expected)
def testGetsVariablesFromList(self):
my_list = ["foo bar\n",
"{{VAR}}",
"fooo {{VAR2}}",
"safa {{VAR}} {{VAR3}} {{ VAR2 }}",
]
output = get_variables_from(my_list)
expected = set(['VAR', 'VAR2', 'VAR3'])
self.assertSetEqual(output, expected)
def testInsertsVariables(self):
my_list = ["foo bar\n",
"{{VAR}}",
"fooo {{VAR2}}",
"safa {{VAR}} {{VAR3}} {{ VAR2 }}",
]
output = render_lines_with({'VAR': 'VAR',
'VAR2': 'VAR2',
'VAR3': 'VAR3',
},
my_list)
expected = ["foo bar\n",
"VAR",
"fooo VAR2",
"safa VAR VAR3 VAR2",
]
self.assertListEqual(output, expected)
def testRaisesExceptionWhenAskedToRenderButNotAllVariablesAreDefined(self):
my_list = ["foo bar\n",
"{{VAR}}",
"fooo {{VAR2}}",
"safa {{VAR}} {{VAR3}} {{ VAR2 }}",
]
try:
render_lines_with({'VAR2': 'VAR2',
'VAR3': 'VAR3'},
my_list)
except VariableNotDefinedError as e:
self.assertEqual(e.message,
'Variable {{VAR}} was found, but not defined!')
self.assertEqual(e.variable, '{{VAR}}')
return
self.fail('VariableNotDefinedError not thrown')
if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
unittest.main()