Ejemplo n.º 1
0
    def testMultipleFormatters(self):
        # TODO: This could have a version in the external test too, just not with
        # 'url-params', which is not the same across platforms because of dictionary
        # iteration order

        # Single formatter
        t = taste.ClassDef('http://example.com?{params:url-params}',
                           format_char=':')
        self.verify.Expansion(
            t, {
                'params': {
                    'foo': 1,
                    'bar': 'String with spaces',
                    'baz': '!@#$%^&*('
                }
            },
            'http://example.com?baz=%21%40%23%24%25%5E%26%2A%28&foo=1&bar=String+with+spaces'
        )

        # Multiple
        t = taste.ClassDef('http://example.com?{params | url-params | html}',
                           format_char='|')
        self.verify.Expansion(
            t, {
                'params': {
                    'foo': 1,
                    'bar': 'String with spaces',
                    'baz': '!@#$%^&*('
                }
            },
            'http://example.com?baz=%21%40%23%24%25%5E%26%2A%28&foo=1&bar=String+with+spaces'
        )
Ejemplo n.º 2
0
    def testExpandingDictionary(self):
        # This isn't strictly necessary, but it should make it easier for people to
        # develop templates iteratively.  They can see what the context is without
        # writing the whole template.

        def _More(format_str):
            if format_str == 'str':
                return lambda x: json.dumps(x, indent=2)
            else:
                return None

        t = taste.ClassDef('{@}', more_formatters=_More)
        d = {
            u'url': u'http://example.com',
            u'person': {
                u'name': u'Andy',
                u'age': 30,
            }
        }

        expected = """\
{
  "url": "http://example.com",
  "person": {
    "age": 30,
    "name": "Andy"
  }
}
"""
        # simplejson emits some extra whitespace
        self.verify.Expansion(t, d, expected, ignore_whitespace=True)
Ejemplo n.º 3
0
 def CompilationError(self, exception, *args, **kwargs):
     template_def = taste.ClassDef(*args, **kwargs)
     template_str = self._MakeTemplateStr(template_def)
     result = self._RunScript(template_str, {})
     self.Equal(result.exit_code, 1)
     print exception.__name__
     self.In(exception.__name__, result.stderr)
Ejemplo n.º 4
0
 def CompilationError(self, exception, *args, **kwargs):
     template_def = taste.ClassDef(*args, **kwargs)
     result = self._RunScript(template_def, {})
     self.In('EXCEPTION: ' + exception.__name__,
             'stderr: %r\nstdout: %s' % (result.stderr, result.stdout))
Ejemplo n.º 5
0
 def CompilationError(self, exception, *args, **kwargs):
     template_def = taste.ClassDef(*args, **kwargs)
     result = self._RunScript(template_def, {})
     if result.exception is None:
         self.fail('No exception found in output')
     self.In(exception.__name__, result.exception)