Example #1
0
 def testRead(self):
     f = SimpleStringFactFormatter()
     fact = f.read("%s is a big tree.| (big, tree)")
     assert fact.__class__ is Fact
     assert fact.template.format == "%s is a big tree."
     assert fact.actorPlaceholders[0].rule == AndRule(
         [TagRule("big"), TagRule("tree")])
Example #2
0
 def testParse(self):
     f = SimpleStringFactFormatter().read(
         "%s is a [big, beautiful] [tree, bird, fish].")
     s = f.template.substitutions
     assert len(s) == 2
     assert s[0].subst == "[big, beautiful]"
     assert s[1].subst == "[tree, bird, fish]"
Example #3
0
 def __load_plain(self):
     self.actors = readList("../data/actors.txt", ActorFormatter())
     self.facts = readList("../data/facts.txt", SimpleStringFactFormatter())
Example #4
0
 def testDefaultFactIsApplicableToAll(self):
     fact = SimpleStringFactFormatter().read("%s is a word.")
     assert fact.isApplicableTo("Anything")
Example #5
0
 def testReadWithNoRules(self):
     f = SimpleStringFactFormatter()
     fact = f.read("%s is a word.")
     assert fact.actorPlaceholders[0].rule == TrueRule()
Example #6
0
 def testFactWithNoActorsIsReady(self):
     fact = SimpleStringFactFormatter().read("Word is a word.")
     assert fact.ready()
Example #7
0
 def testGetFactAbout(self):
     fact = SimpleStringFactFormatter().read("%s is a word.")
     factString = fact.getFactAbout(Actor("Book"))
     assert factString == "Book is a word."
Example #8
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."]