def test_substitution_with_spaces(self): template = NetworkTemplate("a: <% a%>, b: <%b %>, " "c: <% c %>, d: <% d%>") substituted_string = template.safe_substitute(a='aaa', b='bbb', c='ccc', d='ddd') self.assertEqual(substituted_string, "a: aaa, b: bbb, c: ccc, d: ddd")
def test_substitution_with_missed_key(self): template = NetworkTemplate("a: <%a%>") substituted_string = template.safe_substitute(b='bbb') self.assertEqual(substituted_string, "a: <%a%>") self.assertRaises(KeyError, template.substitute, b='bbb')
def test_substitution_with_extra_keys(self): template = NetworkTemplate("a: <%a%>") substituted_string = template.safe_substitute(a='aaa', b='bbb') self.assertEqual(substituted_string, "a: aaa") substituted_string = template.substitute(a='aaa', b='bbb') self.assertEqual(substituted_string, "a: aaa")
def test_substitution_with_no_match(self): template = NetworkTemplate("a: <%a b: <% b % >") substituted_string = template.safe_substitute(a='aaa', b='bbb') self.assertEqual(substituted_string, "a: <%a b: <% b % >")
def test_simple_substitution(self): template = NetworkTemplate("a: <%a%>, b: <%b%>") substituted_string = template.safe_substitute(a='aaa', b='bbb') self.assertEqual(substituted_string, "a: aaa, b: bbb")