Beispiel #1
0
 def test_single_subst_end(self):
     s = 'I like ' + _var('favcolour')
     tv = Value(s, SETTINGS, '')
     self.assertTrue(tv.has_references)
     self.assertEqual(
         tv.render(CONTEXT, None),
         _poor_mans_template(s, 'favcolour', CONTEXT['favcolour']))
Beispiel #2
0
 def test_single_subst_bothends(self):
     s = 'I like ' + _var('favcolour') + ' and I like it'
     tv = Value(s)
     self.assertTrue(tv.has_references())
     self.assertEqual(
         tv.render(CONTEXT, None),
         _poor_mans_template(s, 'favcolour', CONTEXT['favcolour']))
Beispiel #3
0
 def test_single_subst_start(self):
     s = _var('favcolour') + ' is my favourite colour'
     tv = Value(s, SETTINGS, '')
     self.assertTrue(tv.has_references)
     self.assertEqual(
         tv.render(CONTEXT, None),
         _poor_mans_template(s, 'favcolour', CONTEXT['favcolour']))
Beispiel #4
0
 def test_deep_subst_solo(self):
     motd = SETTINGS.delimiter.join(('motd', 'greeting'))
     s = _var(motd)
     tv = Value(s, SETTINGS, '')
     self.assertTrue(tv.has_references)
     self.assertEqual(
         tv.render(CONTEXT, None),
         _poor_mans_template(s, motd, CONTEXT['motd']['greeting']))
Beispiel #5
0
 def test_multiple_subst_flush(self):
     greet = SETTINGS.delimiter.join(('motd', 'greeting'))
     s = _var(greet) + ' I like ' + _var('favcolour')
     tv = Value(s, SETTINGS, '')
     self.assertTrue(tv.has_references)
     want = _poor_mans_template(s, greet, CONTEXT['motd']['greeting'])
     want = _poor_mans_template(want, 'favcolour', CONTEXT['favcolour'])
     self.assertEqual(tv.render(CONTEXT, None), want)
Beispiel #6
0
 def test_deep_subst_solo(self):
     var = PARAMETER_INTERPOLATION_DELIMITER.join(('motd', 'greeting'))
     s = _var(var)
     tv = Value(s)
     self.assertTrue(tv.has_references())
     self.assertEqual(
         tv.render(CONTEXT, None),
         _poor_mans_template(s, var, CONTEXT['motd']['greeting']))
Beispiel #7
0
 def test_multiple_subst_flush(self):
     greet = PARAMETER_INTERPOLATION_DELIMITER.join(('motd', 'greeting'))
     s = _var(greet) + ' I like ' + _var('favcolour')
     tv = Value(s)
     self.assertTrue(tv.has_references())
     want = _poor_mans_template(s, greet, CONTEXT['motd']['greeting'])
     want = _poor_mans_template(want, 'favcolour', CONTEXT['favcolour'])
     self.assertEqual(tv.render(CONTEXT, None), want)
Beispiel #8
0
 def _test_solo_ref(self, key):
     s = _var(key)
     tv = Value(s, SETTINGS, '')
     res = tv.render(CONTEXT, None)
     self.assertTrue(tv.has_references)
     self.assertEqual(res, CONTEXT[key])
Beispiel #9
0
 def test_simple_string(self):
     s = 'my cat likes to hide in boxes'
     tv = Value(s, SETTINGS, '')
     self.assertFalse(tv.has_references)
     self.assertEquals(tv.render(CONTEXT, None), s)
Beispiel #10
0
 def test_undefined_variable(self):
     s = _var('no_such_variable')
     tv = Value(s, SETTINGS, '')
     with self.assertRaises(ResolveError):
         tv.render(CONTEXT, None)
Beispiel #11
0
 def test_undefined_variable(self):
     s = _var('no_such_variable')
     tv = Value(s)
     with self.assertRaises(UndefinedVariableError):
         tv.render(CONTEXT, None)