/
TemplateStringTest.py
37 lines (30 loc) · 1.85 KB
/
TemplateStringTest.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
import UnitTest
from string import Template
import sys
class TemplateStringTest(UnitTest.UnitTest):
def test_substitute(self):
try:
self.assertEqual(Template('This is a test of the $first method of the $second class'
).substitute(first='substitute',second='Template'),
'This is a test of the substitute method of the Template class')
self.assertEqual(Template('This is a test of the ${first} method of the ${second} class'
).substitute(first='substitute',second='Template'),
'This is a test of the substitute method of the Template class')
except:
self.fail('__metaclass__ problem, issue #658')
def test_safe_substitute(self):
try:
self.assertEqual(Template('This is a test of the $first method of the $second class'
).safe_substitute(first='safe_substitute'),
'This is a test of the safe_substitute method of the $second class')
self.assertEqual(Template('This is a test of the ${first} method of the ${second} class'
).safe_substitute(first='safe_substitute'),
'This is a test of the safe_substitute method of the ${second} class')
except:
self.fail('__metaclass__ problem, issue #658')
def test__invalid1(self):
kwargs = {'first':'substitute','second':'Template'}
self.assertRaises(ValueError, Template('This is a test of the $0irst method of the $second class').substitute,**kwargs)
def test__invalid2(self):
kwargs = {'first':'substitute','second':'Template'}
self.assertRaises(KeyError, Template('This is a test of the $first method of the $se~cond class').substitute,**kwargs)