def testEncoding(self): # Bug fix: Templates that are Unicode strings should expand as Unicode # strings. (This is why we use StringIO instead of cStringIO). t = jsontemplate.FromString(u'\u00FF') self.verify.Equal(t.expand({}), u'\u00FF') t = jsontemplate.FromString(u'\uFF00') self.verify.Equal(t.expand({}), u'\uFF00')
def testEmpty(self): s = """\ Format-Char: | Meta: <> """ t = jsontemplate.FromString(s, _constructor=taste.ClassDef) self.verify.Equal(t.args[0], '') self.verify.Equal(t.kwargs['meta'], '<>') self.verify.Equal(t.kwargs['format_char'], '|') # Empty template t = jsontemplate.FromString('', _constructor=taste.ClassDef) self.verify.Equal(t.args[0], '') self.verify.Equal(t.kwargs.get('meta'), None) self.verify.Equal(t.kwargs.get('format_char'), None)
def testNumberWithDefaultHtmlFormatter(self): # For now, integers can't be formatted directly as html. Just omit the # formatter. t = jsontemplate.FromString( B(""" default-formatter: html There are {num} ways to do it """)) self.verify.Equal('There are 5 ways to do it\n', t.expand({'num': 5L}))
def testTemplate(self): f = """\ format-char: : meta: <> Hello <there> """ t = jsontemplate.FromString(f, _constructor=taste.ClassDef) self.verify.Equal(t.args[0], 'Hello <there>\n') self.verify.Equal(t.kwargs['meta'], '<>') self.verify.Equal(t.kwargs['format_char'], ':')
def testNoOptions(self): # Bug fix f = """Hello {dude}""" t = jsontemplate.FromString(f) self.verify.Equal(t.expand({'dude': 'Andy'}), 'Hello Andy')