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."
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!"
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
def testNoneFactListRendersNone(self): actor = Actor("The truth") chooser = RandomFactChooser(None, [actor]) c = chooser.choose() assert c is None
def testGetFactAbout(self): fact = SimpleStringFactFormatter().read("%s is a word.") factString = fact.getFactAbout(Actor("Book")) assert factString == "Book is a word."
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."]