Ejemplo n.º 1
0
 def testPerformance():
     """[Parser] Basic performance test for 2 template replacements"""
     template = 'This [obj:foo] is just a quick [bar]'
     for _template in range(100):
         tmpl = templateparser.Template(template)
         for _parse in range(100):
             tmpl.Parse(obj={'foo': 'template'}, bar='hack')
Ejemplo n.º 2
0
 def setUp(self):
     """Creates a template file and a similar instance attribute."""
     self.name = 'tmp_template'
     self.raw = 'This is a basic [noun]'
     self.template = templateparser.Template(self.raw)
     with open(self.name, 'w') as template:
         template.write('This is a basic [noun]')
         template.flush()
Ejemplo n.º 3
0
 def testOverWriteTemplate(self):
     """[Parser] AddTemplate overrides previously loaded template"""
     custom_raw = 'My very own [adj] template'
     custom_tmpl = templateparser.Template(custom_raw)
     parser = templateparser.Parser()
     parser.AddTemplate(self.name)
     # Create a new template in place of the existing one, and reload it.
     with open(self.name, 'w') as tmpl:
         tmpl.write(custom_raw)
         tmpl.flush()
     # Assert the template has not yet changed, load it, assert that is has.
     self.assertNotEqual(custom_tmpl, parser[self.name])
     parser.AddTemplate(self.name)
     self.assertEqual(parser[self.name], custom_tmpl)