示例#1
0
 def test_missingTargetWithSpecifier(self):
     """
     A missing target is expanded to a warning about a bad template.
     """
     template = ConceptTemplate(u"{c:pronoun} wins.")
     self.assertEqual(u"<missing target 'c' for 'pronoun' expansion> wins.",
                      self.expandToText(template, dict()))
示例#2
0
 def test_intermixed(self):
     """
     Literals and subsitution markers may be combined in a single template.
     """
     template = ConceptTemplate(u"{c:pronoun} wins.")
     self.assertEqual(u"she wins.",
                      self.expandToText(template, dict(c=self.thing)))
示例#3
0
 def test_unexpandedLiteral(self):
     """
     A template string containing no substitution markers expands to itself.
     """
     self.assertEqual(
         u"hello world",
         self.expandToText(ConceptTemplate(u"hello world"), {}))
示例#4
0
 def test_expandedPronoun(self):
     """
     I{field:pronoun} can be used to substitute the personal pronoun of the
     value given by C{"field"}.
     """
     template = ConceptTemplate(u"{b:pronoun}")
     self.assertEqual(u"she", self.expandToText(template,
                                                dict(b=self.thing)))
示例#5
0
 def test_expandedName(self):
     """
     I{field:name} can be used to substitute the name of the value given by
     C{"field"}.
     """
     template = ConceptTemplate(u"{a:name}")
     self.assertEqual(u"alice",
                      self.expandToText(template, dict(a=self.thing)))
示例#6
0
 def test_unsupportedSpecifier(self):
     """
     A specifier not supported on the identified target is expanded to a
     warning about a bad template.
     """
     template = ConceptTemplate(u"{c:glorbex} wins.")
     self.assertEqual(u"<'glorbex' unsupported by target 'c'> wins.",
                      self.expandToText(template, dict(c=self.thing)))
示例#7
0
 def test_multiples(self):
     """
     Multiple substitution markers may be used in a single template.
     """
     another = Thing(name=u"bob", gender=Gender.FEMALE)
     template = ConceptTemplate(u"{a:name} hits {b:name}.")
     self.assertEqual(
         u"alice hits bob.",
         self.expandToText(template, dict(a=self.thing, b=another)))
示例#8
0
 def test_adjacent(self):
     """
     Adjacent substitution markers are expanded without introducing
     extraneous intervening characters.
     """
     another = Thing(name=u"bob", gender=Gender.FEMALE)
     template = ConceptTemplate(u"{a:name}{b:name}")
     self.assertEqual(
         u"alicebob",
         self.expandToText(template, dict(a=self.thing, b=another)))