示例#1
0
 def testHTMLForm(self):
     text = "My dog ate my {bearclaw}."
     st = stories.StoryTemplate(text)
     html = st.HTMLForm(hidden='<input type=hidden name=test value=test>')
     self.assertEqual(
         html,
         ('<!DOCTYPE html>\n'
          '<title>Story</title>\n'
          '<form method=POST>\n'
          '<label>bearclaw: <input type=text name="bearclaw"></label><br>\n'
          '<input type=hidden name=test value=test>\n'
          '<button type=submit>Tell me a story!</button>\n'
          '</form>'))
示例#2
0
 def testFindFields(self):
     text = "My {rumpus} ate my {bearclaw}."
     correct = {'{rumpus}', '{bearclaw}'}
     fields = stories.StoryTemplate(text).fields
     self.assertEqual(fields, correct)
示例#3
0
 def testReplace(self):
     test = "These words {verb} no sense."
     fields = {'{verb}': 'balloon'}
     self.assertEqual("These words balloon no sense.",
                      stories.StoryTemplate(test).Populate(fields))
示例#4
0
 def testUnopenedField(self):
     test = "This has a } busted field."
     with self.assertRaises(stories.ParseError):
         stories.StoryTemplate(test)
示例#5
0
 def testUnclosedField(self):
     test = "This has an {unclosed."
     with self.assertRaises(stories.ParseError):
         stories.StoryTemplate(test)
示例#6
0
 def testEmptyField(self):
     test = "This has a {} empty field."
     with self.assertRaises(stories.ParseError):
         stories.StoryTemplate(test)
示例#7
0
 def testFindFieldAtStart(self):
     text = "{name} likes {name}'s name, which is '{name}'."
     correct = {'{name}'}
     fields = stories.StoryTemplate(text).fields
     self.assertEqual(fields, correct)