Esempio n. 1
0
 def test_begin_ends_with_vars(self):
     template = templates.compile('{a}{b}{c}', ['a', 'b', 'c'])
     self.assertEqual(3, len(template._parts))
     self.assertIsInstance(template._parts[0], VariablePart)
     self.assertEqual('a', template._parts[0]._expression)
     self.assertIsInstance(template._parts[1], VariablePart)
     self.assertEqual('b', template._parts[1]._expression)
     self.assertIsInstance(template._parts[2], VariablePart)
     self.assertEqual('c', template._parts[2]._expression)
Esempio n. 2
0
 def test_begin_ends_with_vars(self):
     template = templates.compile('{a}{b}{c}', ['a', 'b', 'c'])
     self.assertEqual(3, len(template._parts))
     self.assertIsInstance(template._parts[0], VariablePart)
     self.assertEqual('a', template._parts[0]._expression)
     self.assertIsInstance(template._parts[1], VariablePart)
     self.assertEqual('b', template._parts[1]._expression)
     self.assertIsInstance(template._parts[2], VariablePart)
     self.assertEqual('c', template._parts[2]._expression)
Esempio n. 3
0
 def test_normal(self):
     template = templates.compile('Calculating {a} + {b} ...', ['a', 'b', 'c'])
     self.assertEqual(5, len(template._parts))
     self.assertIsInstance(template._parts[0], StringPart)
     self.assertEqual('Calculating ', template._parts[0]._expression)
     self.assertIsInstance(template._parts[1], VariablePart)
     self.assertEqual('a', template._parts[1]._expression)
     self.assertIsInstance(template._parts[2], StringPart)
     self.assertEqual(' + ', template._parts[2]._expression)
     self.assertIsInstance(template._parts[3], VariablePart)
     self.assertEqual('b', template._parts[3]._expression)
     self.assertIsInstance(template._parts[4], StringPart)
     self.assertEqual(' ...', template._parts[4]._expression)
Esempio n. 4
0
 def test_normal(self):
     template = templates.compile('Calculating {a} + {b} ...',
                                  ['a', 'b', 'c'])
     self.assertEqual(5, len(template._parts))
     self.assertIsInstance(template._parts[0], StringPart)
     self.assertEqual('Calculating ', template._parts[0]._expression)
     self.assertIsInstance(template._parts[1], VariablePart)
     self.assertEqual('a', template._parts[1]._expression)
     self.assertIsInstance(template._parts[2], StringPart)
     self.assertEqual(' + ', template._parts[2]._expression)
     self.assertIsInstance(template._parts[3], VariablePart)
     self.assertEqual('b', template._parts[3]._expression)
     self.assertIsInstance(template._parts[4], StringPart)
     self.assertEqual(' ...', template._parts[4]._expression)
Esempio n. 5
0
 def test_attr(self):
     template = templates.compile('{user.id}', ['user'])
     self.assertEqual('user.id', template._parts[0]._expression)
Esempio n. 6
0
 def test_pure_string(self):
     template = templates.compile('Calculation succeeded.', ['a', 'b', 'c'])
     self.assertEqual(1, len(template._parts))
     self.assertIsInstance(template._parts[0], StringPart)
     self.assertEqual('Calculation succeeded.',
                      template._parts[0]._expression)
Esempio n. 7
0
 def _compile_template(self, template):
     return templates.compile(template, self.params)
Esempio n. 8
0
 def test_item_not_found(self):
     template = templates.compile('{user["name"]}', ['user'])
     with self.assertRaises(TemplateError):
         template.eval({'user': {'id': 1}})
Esempio n. 9
0
 def test_succeed(self):
     template = templates.compile('Calculating {a} + {b} ...',
                                  ['a', 'b', 'c'])
     result = template.eval({'a': 1, 'b': 2, 'c': 3})
     self.assertEqual('Calculating 1 + 2 ...', result)
Esempio n. 10
0
 def test_item_not_found(self):
     template = templates.compile('{user["name"]}', ['user'])
     with self.assertRaises(TemplateError):
         template.eval({'user': {'id': 1}})
         
Esempio n. 11
0
 def test_attr_not_found(self):
     template = templates.compile('{user.name}', ['user'])
     with self.assertRaises(TemplateError):
         template.eval({'user': Dict(id=1)})
Esempio n. 12
0
 def test_succeed(self):
     template = templates.compile('Calculating {a} + {b} ...', ['a', 'b', 'c'])
     result = template.eval({'a': 1, 'b': 2, 'c': 3})
     self.assertEqual('Calculating 1 + 2 ...', result)
Esempio n. 13
0
 def test_missing_var(self):
     with self.assertRaises(TemplateError):
         templates.compile('{d}', ['a', 'b', 'c'])
Esempio n. 14
0
 def test_item(self):
     template = templates.compile('{user["id"]}', ['user'])
     self.assertEqual('user["id"]', template._parts[0]._expression)
Esempio n. 15
0
 def test_attr(self):
     template = templates.compile('{user.id}', ['user'])
     self.assertEqual('user.id', template._parts[0]._expression)
Esempio n. 16
0
 def test_item(self):
     template = templates.compile('{user["id"]}', ['user'])
     self.assertEqual('user["id"]', template._parts[0]._expression)
Esempio n. 17
0
 def test_missing_var(self):
     with self.assertRaises(TemplateError):
         templates.compile('{d}', ['a', 'b', 'c'])
Esempio n. 18
0
 def _decorate(self, func):
     super(CacheDecorator, self)._decorate(func)
     var_names = self.params + tuple(self._vars.keys())
     self._key_template = templates.compile(self._key, var_names)
     return self
Esempio n. 19
0
 def test_attr_not_found(self):
     template = templates.compile('{user.name}', ['user'])
     with self.assertRaises(TemplateError):
         template.eval({'user': Dict(id=1)})
Esempio n. 20
0
 def _decorate(self, func):
     super(CacheDecorator, self)._decorate(func)
     var_names = self.params + tuple(self._extra_vars.keys())
     self._key_template = templates.compile(self._key, var_names)
     return self
Esempio n. 21
0
 def _compile_template(self, template):
     return templates.compile(template, self.params)
Esempio n. 22
0
 def test_pure_string(self):
     template = templates.compile('Calculation succeeded.', ['a', 'b', 'c'])
     self.assertEqual(1, len(template._parts))
     self.assertIsInstance(template._parts[0], StringPart)
     self.assertEqual('Calculation succeeded.', template._parts[0]._expression)