Beispiel #1
0
 def test_binary_template_with_unicode_data(self):
     t = tenjin.Template()
     input = "**あ**\n#{u'あ'}\n"
     script = "_buf.extend(('''**\xe3\x81\x82**\n''', to_str(u'\xe3\x81\x82'), '''\\n''', ));\n"
     self.assertTextEqual(script, t.convert(input))
     ## do nothing in to_str()
     self._test_render(
         template        = t,
         to_str          = tenjin.generate_tostrfunc(encode=None, decode=None),
         #expected_buf    = ['**\xe3\x81\x82**\n', u'\u3042', '\n'],
         expected_buf    = ['**\xe3\x81\x82**\n', u'\xe3\x81\x82', '\n'],
         expected_errcls = UnicodeDecodeError,
         expected_errmsg = "'ascii' codec can't decode byte 0xe3 in position 2: ordinal not in range(128)"
      )
     ## encode unicode in binary in to_str()
     self._test_render(
         template        = t,
         to_str          = tenjin.generate_tostrfunc(encode='utf-8', decode=None),
         expected_buf    = ['**\xe3\x81\x82**\n', '\xc3\xa3\xc2\x81\xc2\x82', '\n'],
         expected_output = "**あ**\n\xc3\xa3\xc2\x81\xc2\x82\n"    ## GARGLED!!
      )
     ## decode binary into unicode in to_str()
     self._test_render(
         template        = t,
         to_str          = tenjin.generate_tostrfunc(encode=None, decode='utf-8'),
         expected_buf    = ['**\xe3\x81\x82**\n', u'\xe3\x81\x82', '\n'],
         expected_errcls = UnicodeDecodeError,
         expected_errmsg = "'ascii' codec can't decode byte 0xe3 in position 2: ordinal not in range(128)"
     )
Beispiel #2
0
 def test_with_unicode_template_and_binary_data(self):
     t = tenjin.Template(encoding='utf-8')
     input = "**あ**\n#{'あ'}\n"
     script = lvars + u"_extend((u'''**\u3042**\n''', _to_str('\u3042'), u'''\\n''', ));\n"
     ok (t.convert(input)) == script
     ## do nothing in to_str()
     self._test_render(
         template        = t,
         to_str          = tenjin.generate_tostrfunc(encode=None, decode=None),
         expected_buf    = [u'**\u3042**\n', '\xe3\x81\x82', u'\n'],
         expected_errcls = UnicodeDecodeError,
         expected_errmsg = "'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128)"
      )
     ## encode unicode in binary in to_str()
     self._test_render(
         template        = t,
         to_str          = tenjin.generate_tostrfunc(encode='utf-8', decode=None),
         expected_buf    = [u'**\u3042**\n', '\xe3\x81\x82', u'\n'],
         expected_errcls = UnicodeDecodeError,
         expected_errmsg = "'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128)"
      )
     ## decode binary into unicode in to_str()
     self._test_render(
         template        = t,
         to_str          = tenjin.generate_tostrfunc(encode=None, decode='utf-8'),
         expected_buf    = [u'**\u3042**\n', u'\u3042', u'\n'],
         expected_output = u"**あ**\nあ\n"
     )