コード例 #1
0
	def testSingleFactIsChosen(self):
		template = SimpleStringFactTemplate("%s is out there.")
		actor = Actor("The truth")
		chooser = RandomFactChooser([template], [actor])
		c = chooser.choose()
		assert c is not None
		assert c == "The truth is out there."
コード例 #2
0
 def test(self):
     s = """
         {% actor "author", "(old, beard)" %}
         {{ author.name }} was old and had a huge beard, but still he's a genius!
     """
     t = JinjaFactTemplate(s)
     f = t.buildup()
     a = Actor("Ernest Hemingway", ["old", "beard"])
     r = f.getFactAbout(a)
     print r
     assert r.strip() == "Ernest Hemingway was old and had a huge beard, but still he's a genius!"
コード例 #3
0
	def testNonFittingActorRendersNone(self):
		template = SimpleStringFactTemplate("%s is out there.|truth")
		actor = Actor("The truth")
		chooser = RandomFactChooser([template], [actor])
		c = chooser.choose()
		assert c is None
コード例 #4
0
	def testNoneFactListRendersNone(self):
		actor = Actor("The truth")
		chooser = RandomFactChooser(None, [actor])
		c = chooser.choose()
		assert c is None
コード例 #5
0
 def testGetFactAbout(self):
     fact = SimpleStringFactFormatter().read("%s is a word.")
     factString = fact.getFactAbout(Actor("Book"))
     assert factString == "Book is a word."
コード例 #6
0
 def testSingleSubstitution(self):
     f = SimpleStringFactFormatter().read("%s is a [big, beautiful] tree.")
     s = f.getFactAbout(Actor("Oak"))
     assert s in ["Oak is a beautiful tree.", "Oak is a big tree."]