Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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}))
Ejemplo n.º 4
0
    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'], ':')
Ejemplo n.º 5
0
 def testNoOptions(self):
     # Bug fix
     f = """Hello {dude}"""
     t = jsontemplate.FromString(f)
     self.verify.Equal(t.expand({'dude': 'Andy'}), 'Hello Andy')