Changeset 3546:cd35d2265b48 in livinglogic.python.xist

Show
Ignore:
Timestamp:
07/29/08 13:40:35 (11 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Fix format() for truediv opcode. Add tests for format.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/ll/ul4c.py

    r3545 r3546  
    557557        elif self.code == "floordiv": 
    558558            return "r%r = r%r // r%r" % (self.r1, self.r2, self.r3) 
    559         elif self.code == "trueiv": 
     559        elif self.code == "truediv": 
    560560            return "r%r = r%r / r%r" % (self.r1, self.r2, self.r3) 
    561561        elif self.code == "and": 
  • test/test_ul4.py

    r3530 r3546  
    2020    # Check with template compiled from source 
    2121    t1 = ul4c.compile(source) 
     22    s1 = unicode(t1) 
    2223    assert result == t1.renders(templates, **variables) 
    2324 
    2425    # Check with template loaded again via the string interface 
    2526    t2 = ul4c.loads(t1.dumps()) 
     27    s2 = unicode(t2) 
    2628    assert result == t2.renders(templates, **variables) 
    2729 
     
    3133    stream.seek(0) 
    3234    t3 = ul4c.load(stream) 
     35    s3 = unicode(t3) 
    3336    assert result == t3.renders(templates, **variables) 
     37    assert s1 == s2 == s3 
    3438 
    3539 
     
    3741    # Check with template compiled from source 
    3842    t1 = ul4c.compile(source) 
     43    s1 = unicode(t1) 
    3944    assert result <= t1.renders(templates, **variables) 
    4045 
    4146    # Check with template loaded again via the string interface 
    4247    t2 = ul4c.loads(t1.dumps()) 
     48    s2 = unicode(t2) 
    4349    assert result <= t2.renders(templates, **variables) 
    4450 
     
    4854    stream.seek(0) 
    4955    t3 = ul4c.load(stream) 
     56    s3 = unicode(t3) 
    5057    assert result <= t3.renders(templates, **variables) 
     58    assert s1 == s2 == s3 
    5159 
    5260 
     
    6371    # Check with template compiled from source 
    6472    t1 = ul4c.compile(source) 
     73    s1 = unicode(t1) 
    6574    try: 
    6675        t1.renders(templates, **variables) 
     
    7281    # Check with template loaded again via the string interface 
    7382    t2 = ul4c.loads(t1.dumps()) 
     83    s2 = unicode(t2) 
    7484    try: 
    7585        t2.renders(templates, **variables) 
     
    8494    stream.seek(0) 
    8595    t3 = ul4c.load(stream) 
     96    s3 = unicode(t3) 
    8697    try: 
    8798        t3.renders(templates, **variables) 
     
    90101    else: 
    91102        py.test.fail("Didn't raise exception") 
    92  
    93  
    94 def test_format(): 
    95     tmpl = ul4c.compile("<?for (i, item) in enumerate(data)?><?print (i+1).format('>3d')?>. <?print item[0].format('.<10')?> <?print item[1]?>\n<?end for?>") 
    96     assert str(tmpl) == unicode(tmpl) 
     103    assert s1 == s2 == s3 
    97104 
    98105 
    99106def test_text(): 
    100     check('gurk', 'gurk') 
    101107    check(u'gurk', u'gurk') 
    102108    check(u'g\xfcrk', u'g\xfcrk') 
     
    104110 
    105111def test_none(): 
    106     check('', '<?print None?>') 
    107  
    108     check('no', '<?if None?>yes<?else?>no<?end if?>') 
     112    check('', u'<?print None?>') 
     113 
     114    check('no', u'<?if None?>yes<?else?>no<?end if?>') 
    109115 
    110116 
    111117def test_false(): 
    112     check('False', '<?print False?>') 
    113  
    114     check('no', '<?if False?>yes<?else?>no<?end if?>') 
     118    check('False', u'<?print False?>') 
     119 
     120    check('no', u'<?if False?>yes<?else?>no<?end if?>') 
    115121 
    116122 
    117123def test_true(): 
    118     check('True', '<?print True?>') 
    119  
    120     check('yes', '<?if True?>yes<?else?>no<?end if?>') 
     124    check('True', u'<?print True?>') 
     125 
     126    check('yes', u'<?if True?>yes<?else?>no<?end if?>') 
    121127 
    122128 
    123129def test_int(): 
    124     check('0', '<?print 0?>') 
    125     check('42', '<?print 42?>') 
    126     check('-42', '<?print -42?>') 
    127     check('255', '<?print 0xff?>') 
    128     check('255', '<?print 0Xff?>') 
    129     check('-255', '<?print -0xff?>') 
    130     check('-255', '<?print -0Xff?>') 
    131     check('63', '<?print 0o77?>') 
    132     check('63', '<?print 0O77?>') 
    133     check('-63', '<?print -0o77?>') 
    134     check('-63', '<?print -0O77?>') 
    135     check('7', '<?print 0b111?>') 
    136     check('7', '<?print 0B111?>') 
    137     check('-7', '<?print -0b111?>') 
    138     check('-7', '<?print -0B111?>') 
    139  
    140     check('no', '<?if 0?>yes<?else?>no<?end if?>') 
    141     check('yes', '<?if 1?>yes<?else?>no<?end if?>') 
    142     check('yes', '<?if -1?>yes<?else?>no<?end if?>') 
     130    check('0', u'<?print 0?>') 
     131    check('42', u'<?print 42?>') 
     132    check('-42', u'<?print -42?>') 
     133    check('255', u'<?print 0xff?>') 
     134    check('255', u'<?print 0Xff?>') 
     135    check('-255', u'<?print -0xff?>') 
     136    check('-255', u'<?print -0Xff?>') 
     137    check('63', u'<?print 0o77?>') 
     138    check('63', u'<?print 0O77?>') 
     139    check('-63', u'<?print -0o77?>') 
     140    check('-63', u'<?print -0O77?>') 
     141    check('7', u'<?print 0b111?>') 
     142    check('7', u'<?print 0B111?>') 
     143    check('-7', u'<?print -0b111?>') 
     144    check('-7', u'<?print -0B111?>') 
     145 
     146    check('no', u'<?if 0?>yes<?else?>no<?end if?>') 
     147    check('yes', u'<?if 1?>yes<?else?>no<?end if?>') 
     148    check('yes', u'<?if -1?>yes<?else?>no<?end if?>') 
    143149 
    144150 
    145151def test_float(): 
    146     check('0.0', '<?print 0.?>') 
    147     check('42.0', '<?print 42.?>') 
    148     check('-42.0', '<?print -42.?>') 
    149     check('1e+42', '<?print 1E42?>') 
    150     check('1e+42', '<?print 1e42?>') 
    151     check('-1e+42', '<?print -1E42?>') 
    152     check('-1e+42', '<?print -1e42?>') 
    153  
    154     check('no', '<?if 0.?>yes<?else?>no<?end if?>') 
    155     check('yes', '<?if 1.?>yes<?else?>no<?end if?>') 
    156     check('yes', '<?if -1.?>yes<?else?>no<?end if?>') 
     152    check('0.0', u'<?print 0.?>') 
     153    check('42.0', u'<?print 42.?>') 
     154    check('-42.0', u'<?print -42.?>') 
     155    check('1e+42', u'<?print 1E42?>') 
     156    check('1e+42', u'<?print 1e42?>') 
     157    check('-1e+42', u'<?print -1E42?>') 
     158    check('-1e+42', u'<?print -1e42?>') 
     159 
     160    check('no', u'<?if 0.?>yes<?else?>no<?end if?>') 
     161    check('yes', u'<?if 1.?>yes<?else?>no<?end if?>') 
     162    check('yes', u'<?if -1.?>yes<?else?>no<?end if?>') 
    157163 
    158164 
    159165def test_string(): 
    160     check('foo', '<?print "foo"?>') 
    161     check('\n', '<?print "\\n"?>') 
    162     check('\r', '<?print "\\r"?>') 
    163     check('\t', '<?print "\\t"?>') 
    164     check('\f', '<?print "\\f"?>') 
    165     check('\b', '<?print "\\b"?>') 
    166     check('\a', '<?print "\\a"?>') 
    167     check('\x1b', '<?print "\\e"?>') 
    168     check('"', '<?print "\\""?>') 
    169     check("'", '<?print "\\\'"?>') 
     166    check('foo', u'<?print "foo"?>') 
     167    check('\n', u'<?print "\\n"?>') 
     168    check('\r', u'<?print "\\r"?>') 
     169    check('\t', u'<?print "\\t"?>') 
     170    check('\f', u'<?print "\\f"?>') 
     171    check('\b', u'<?print "\\b"?>') 
     172    check('\a', u'<?print "\\a"?>') 
     173    check('\x1b', u'<?print "\\e"?>') 
     174    check('"', u'<?print "\\""?>') 
     175    check("'", u'<?print "\\\'"?>') 
    170176    check(u'\u20ac', u'<?print "\u20ac"?>') 
    171177    check(u'\xff', u'<?print "\\xff"?>') 
    172178    check(u'\u20ac', u'''<?print "\\u20ac"?>''') 
    173     checkcompileerror("Unterminated string", '<?print "?>') 
    174     check("\\xxx", '<?print "\\xxx"?>') 
    175     check("a\nb", '<?print "a\nb"?>') 
    176  
    177     check('no', '<?if ""?>yes<?else?>no<?end if?>') 
    178     check('yes', '<?if "foo"?>yes<?else?>no<?end if?>') 
     179    checkcompileerror("Unterminated string", u'<?print "?>') 
     180    check("\\xxx", u'<?print "\\xxx"?>') 
     181    check("a\nb", u'<?print "a\nb"?>') 
     182 
     183    check('no', u'<?if ""?>yes<?else?>no<?end if?>') 
     184    check('yes', u'<?if "foo"?>yes<?else?>no<?end if?>') 
    179185 
    180186 
    181187def test_date(): 
    182     check('2000-02-29T00:00:00', '<?print 2000-02-29T.isoformat()?>') 
    183     check('2000-02-29T12:34:00', '<?print 2000-02-29T12:34.isoformat()?>') 
    184     check('2000-02-29T12:34:56', '<?print 2000-02-29T12:34:56.isoformat()?>') 
    185     check('2000-02-29T12:34:56.987654', '<?print 2000-02-29T12:34:56.987654.isoformat()?>') 
    186     check('yes', '<?if 2000-02-29T12:34:56.987654?>yes<?else?>no<?end if?>') 
     188    check('2000-02-29T00:00:00', u'<?print 2000-02-29T.isoformat()?>') 
     189    check('2000-02-29T12:34:00', u'<?print 2000-02-29T12:34.isoformat()?>') 
     190    check('2000-02-29T12:34:56', u'<?print 2000-02-29T12:34:56.isoformat()?>') 
     191    check('2000-02-29T12:34:56.987654', u'<?print 2000-02-29T12:34:56.987654.isoformat()?>') 
     192    check('yes', u'<?if 2000-02-29T12:34:56.987654?>yes<?else?>no<?end if?>') 
    187193 
    188194 
    189195def test_list(): 
    190     check('', '<?for item in []?><?print item?>;<?end for?>') 
    191     check('1;', '<?for item in [1]?><?print item?>;<?end for?>') 
    192     check('1;', '<?for item in [1,]?><?print item?>;<?end for?>') 
    193     check('1;2;', '<?for item in [1, 2]?><?print item?>;<?end for?>') 
    194     check('1;2;', '<?for item in [1, 2,]?><?print item?>;<?end for?>') 
    195     check('no', '<?if []?>yes<?else?>no<?end if?>') 
    196     check('yes', '<?if [1]?>yes<?else?>no<?end if?>') 
     196    check('', u'<?for item in []?><?print item?>;<?end for?>') 
     197    check('1;', u'<?for item in [1]?><?print item?>;<?end for?>') 
     198    check('1;', u'<?for item in [1,]?><?print item?>;<?end for?>') 
     199    check('1;2;', u'<?for item in [1, 2]?><?print item?>;<?end for?>') 
     200    check('1;2;', u'<?for item in [1, 2,]?><?print item?>;<?end for?>') 
     201    check('no', u'<?if []?>yes<?else?>no<?end if?>') 
     202    check('yes', u'<?if [1]?>yes<?else?>no<?end if?>') 
    197203 
    198204 
    199205def test_dict(): 
    200     check('', '<?for (key, value) in {}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    201     check('1:2\n', '<?for (key, value) in {1:2}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    202     check('1:2\n', '<?for (key, value) in {1:2,}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     206    check('', u'<?for (key, value) in {}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     207    check('1:2\n', u'<?for (key, value) in {1:2}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     208    check('1:2\n', u'<?for (key, value) in {1:2,}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    203209    # With duplicate keys, later ones simply overwrite earlier ones 
    204     check('1:3\n', '<?for (key, value) in {1:2, 1: 3}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    205     check('no', '<?if {}?>yes<?else?>no<?end if?>') 
    206     check('yes', '<?if {1:2}?>yes<?else?>no<?end if?>') 
     210    check('1:3\n', u'<?for (key, value) in {1:2, 1: 3}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     211    check('no', u'<?if {}?>yes<?else?>no<?end if?>') 
     212    check('yes', u'<?if {1:2}?>yes<?else?>no<?end if?>') 
    207213 
    208214 
    209215def test_code_storevar(): 
    210     check('42', '<?code x = 42?><?print x?>') 
    211     check('xyzzy', '<?code x = "xyzzy"?><?print x?>') 
     216    check('42', u'<?code x = 42?><?print x?>') 
     217    check('xyzzy', u'<?code x = "xyzzy"?><?print x?>') 
    212218 
    213219 
    214220def test_code_addvar(): 
    215     check('40', '<?code x = 17?><?code x += 23?><?print x?>') 
    216     check('xyzzy', '<?code x = "xyz"?><?code x += "zy"?><?print x?>') 
     221    check('40', u'<?code x = 17?><?code x += 23?><?print x?>') 
     222    check('xyzzy', u'<?code x = "xyz"?><?code x += "zy"?><?print x?>') 
    217223 
    218224 
    219225def test_code_subvar(): 
    220     check('-6', '<?code x = 17?><?code x -= 23?><?print x?>') 
     226    check('-6', u'<?code x = 17?><?code x -= 23?><?print x?>') 
    221227 
    222228 
    223229def test_code_mulvar(): 
    224     check('391', '<?code x = 17?><?code x *= 23?><?print x?>') 
    225     check(17*'xyzzy', '<?code x = 17?><?code x *= "xyzzy"?><?print x?>') 
    226     check(17*'xyzzy', '<?code x = "xyzzy"?><?code x *= 17?><?print x?>') 
     230    check('391', u'<?code x = 17?><?code x *= 23?><?print x?>') 
     231    check(17*'xyzzy', u'<?code x = 17?><?code x *= "xyzzy"?><?print x?>') 
     232    check(17*'xyzzy', u'<?code x = "xyzzy"?><?code x *= 17?><?print x?>') 
    227233 
    228234 
    229235def test_code_floordivvar(): 
    230     check('2', '<?code x = 5?><?code x //= 2?><?print x?>') 
    231     check('-3', '<?code x = -5?><?code x //= 2?><?print x?>') 
     236    check('2', u'<?code x = 5?><?code x //= 2?><?print x?>') 
     237    check('-3', u'<?code x = -5?><?code x //= 2?><?print x?>') 
    232238 
    233239 
    234240def test_code_truedivvar(): 
    235     check('2.5', '<?code x = 5?><?code x /= 2?><?print x?>') 
    236     check('-2.5', '<?code x = -5?><?code x /= 2?><?print x?>') 
     241    check('2.5', u'<?code x = 5?><?code x /= 2?><?print x?>') 
     242    check('-2.5', u'<?code x = -5?><?code x /= 2?><?print x?>') 
    237243 
    238244 
    239245def test_code_modvar(): 
    240     check('4', '<?code x = 1729?><?code x %= 23?><?print x?>') 
     246    check('4', u'<?code x = 1729?><?code x %= 23?><?print x?>') 
    241247 
    242248 
    243249def test_code_delvar(): 
    244     checkrunerror('KeyError', '<?code x = 1729?><?code del x?><?print x?>') 
     250    checkrunerror('KeyError', u'<?code x = 1729?><?code del x?><?print x?>') 
    245251 
    246252 
    247253def test_for_string(): 
    248     check('', '<?for c in data?>(<?print c?>)<?end for?>', data="") 
    249     check('(g)(u)(r)(k)', '<?for c in data?>(<?print c?>)<?end for?>', data="gurk") 
     254    check('', u'<?for c in data?>(<?print c?>)<?end for?>', data="") 
     255    check('(g)(u)(r)(k)', u'<?for c in data?>(<?print c?>)<?end for?>', data="gurk") 
    250256 
    251257 
    252258def test_for_list(): 
    253     check('', '<?for c in data?>(<?print c?>)<?end for?>', data="") 
    254     check('(g)(u)(r)(k)', '<?for c in data?>(<?print c?>)<?end for?>', data=["g", "u", "r", "k"]) 
     259    check('', u'<?for c in data?>(<?print c?>)<?end for?>', data="") 
     260    check('(g)(u)(r)(k)', u'<?for c in data?>(<?print c?>)<?end for?>', data=["g", "u", "r", "k"]) 
    255261 
    256262 
    257263def test_for_dict(): 
    258     check('', '<?for c in data?>(<?print c?>)<?end for?>', data={}) 
    259     check('(a)(b)(c)', '<?for c in sorted(data)?>(<?print c?>)<?end for?>', data=dict(a=1, b=2, c=3)) 
     264    check('', u'<?for c in data?>(<?print c?>)<?end for?>', data={}) 
     265    check('(a)(b)(c)', u'<?for c in sorted(data)?>(<?print c?>)<?end for?>', data=dict(a=1, b=2, c=3)) 
    260266 
    261267 
    262268def test_for_nested(): 
    263     check('[(1)(2)][(3)(4)]', '<?for list in data?>[<?for n in list?>(<?print n?>)<?end for?>]<?end for?>', data=[[1, 2], [3, 4]]) 
     269    check('[(1)(2)][(3)(4)]', u'<?for list in data?>[<?for n in list?>(<?print n?>)<?end for?>]<?end for?>', data=[[1, 2], [3, 4]]) 
    264270 
    265271 
    266272def test_break(): 
    267     check('1, 2, ', '<?for i in [1,2,3]?><?print i?>, <?if i==2?><?break?><?end if?><?end for?>') 
     273    check('1, 2, ', u'<?for i in [1,2,3]?><?print i?>, <?if i==2?><?break?><?end if?><?end for?>') 
    268274 
    269275 
    270276def test_break_nested(): 
    271     check('1, 1, 2, 1, 2, 3, ', '<?for i in [1,2,3,4]?><?for j in [1,2,3,4]?><?print j?>, <?if j>=i?><?break?><?end if?><?end for?><?if i>=3?><?break?><?end if?><?end for?>') 
     277    check('1, 1, 2, 1, 2, 3, ', u'<?for i in [1,2,3,4]?><?for j in [1,2,3,4]?><?print j?>, <?if j>=i?><?break?><?end if?><?end for?><?if i>=3?><?break?><?end if?><?end for?>') 
    272278 
    273279 
    274280def test_continue(): 
    275     check('1, 3, ', '<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?print i?>, <?end for?>') 
     281    check('1, 3, ', u'<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?print i?>, <?end for?>') 
    276282 
    277283 
    278284def test_continue_nested(): 
    279     check('1, 3, \n1, 3, \n', '<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?for j in [1,2,3]?><?if j==2?><?continue?><?end if?><?print j?>, <?end for?>\n<?end for?>') 
     285    check('1, 3, \n1, 3, \n', u'<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?for j in [1,2,3]?><?if j==2?><?continue?><?end if?><?print j?>, <?end for?>\n<?end for?>') 
    280286 
    281287 
    282288def test_if(): 
    283     check('42', '<?if data?><?print data?><?end if?>', data=42) 
     289    check('42', u'<?if data?><?print data?><?end if?>', data=42) 
    284290 
    285291 
    286292def test_else(): 
    287     check('42', '<?if data?><?print data?><?else?>no<?end if?>', data=42) 
    288     check('no', '<?if data?><?print data?><?else?>no<?end if?>', data=0) 
     293    check('42', u'<?if data?><?print data?><?else?>no<?end if?>', data=42) 
     294    check('no', u'<?if data?><?print data?><?else?>no<?end if?>', data=0) 
    289295 
    290296 
    291297def test_block_errors(): 
    292     checkcompileerror("in .<.for x in data.>..*block unclosed", '<?for x in data?>') 
    293     checkcompileerror("endif doesn't match any if", '<?for x in data?><?end if?>') 
    294     checkcompileerror("not in any block", '<?end?>') 
    295     checkcompileerror("not in any block", '<?end for?>') 
    296     checkcompileerror("not in any block", '<?end if?>') 
    297     checkcompileerror("else doesn't match any if", '<?else?>') 
    298     checkcompileerror("in .<.if data.>..*block unclosed", '<?if data?>') 
    299     checkcompileerror("in .<.if data.>..*block unclosed", '<?if data?><?else?>') 
    300     checkcompileerror("duplicate else", '<?if data?><?else?><?else?>') 
    301     checkcompileerror("else already seen in elif", '<?if data?><?else?><?elif data?>') 
    302     checkcompileerror("else already seen in elif", '<?if data?><?elif data?><?elif data?><?else?><?elif data?>') 
     298    checkcompileerror("in u?.<.for x in data.>..*block unclosed", u'<?for x in data?>') 
     299    checkcompileerror("endif doesn't match any if", u'<?for x in data?><?end if?>') 
     300    checkcompileerror("not in any block", u'<?end?>') 
     301    checkcompileerror("not in any block", u'<?end for?>') 
     302    checkcompileerror("not in any block", u'<?end if?>') 
     303    checkcompileerror("else doesn't match any if", u'<?else?>') 
     304    checkcompileerror("in u?.<.if data.>..*block unclosed", u'<?if data?>') 
     305    checkcompileerror("in u?.<.if data.>..*block unclosed", u'<?if data?><?else?>') 
     306    checkcompileerror("duplicate else", u'<?if data?><?else?><?else?>') 
     307    checkcompileerror("else already seen in elif", u'<?if data?><?else?><?elif data?>') 
     308    checkcompileerror("else already seen in elif", u'<?if data?><?elif data?><?elif data?><?else?><?elif data?>') 
    303309 
    304310 
    305311def test_empty(): 
    306     checkcompileerror("expression required", '<?print?>') 
    307     checkcompileerror("expression required", '<?if?>') 
    308     checkcompileerror("expression required", '<<?if x?><?elif?><?end if?>') 
    309     checkcompileerror("loop expression required", '<?for?>') 
    310     checkcompileerror("statement required", '<?code?>') 
    311     checkcompileerror("render statement required", '<?render?>') 
     312    checkcompileerror("expression required", u'<?print?>') 
     313    checkcompileerror("expression required", u'<?if?>') 
     314    checkcompileerror("expression required", u'<<?if x?><?elif?><?end if?>') 
     315    checkcompileerror("loop expression required", u'<?for?>') 
     316    checkcompileerror("statement required", u'<?code?>') 
     317    checkcompileerror("render statement required", u'<?render?>') 
    312318 
    313319 
    314320def test_add(): 
    315     check('42', '<?print 21+21?>') 
    316     check('42', '<?code x=21?><?code y=21?><?print x+y?>') 
    317     check('foobar', '<?code x="foo"?><?code y="bar"?><?print x+y?>') 
    318     check('(f)(o)(o)(b)(a)(r)', '<?for i in data.foo+data.bar?>(<?print i?>)<?end for?>', data=dict(foo="foo", bar="bar")) 
     321    check('42', u'<?print 21+21?>') 
     322    check('42', u'<?code x=21?><?code y=21?><?print x+y?>') 
     323    check('foobar', u'<?code x="foo"?><?code y="bar"?><?print x+y?>') 
     324    check('(f)(o)(o)(b)(a)(r)', u'<?for i in data.foo+data.bar?>(<?print i?>)<?end for?>', data=dict(foo="foo", bar="bar")) 
    319325 
    320326 
    321327def test_sub(): 
    322     check('0', '<?print 21-21?>') 
    323     check('0', '<?code x=21?><?code y=21?><?print x-y?>') 
     328    check('0', u'<?print 21-21?>') 
     329    check('0', u'<?code x=21?><?code y=21?><?print x-y?>') 
    324330 
    325331 
    326332 
    327333def test_mul(): 
    328     check(str(17*23), '<?print 17*23?>') 
    329     check(str(17*23), '<?code x=17?><?code y=23?><?print x*y?>') 
    330     check(17*"foo", '<?print 17*"foo"?>') 
    331     check(17*"foo", '<?code x=17?><?code y="foo"?><?print x*y?>') 
    332     check("foo"*17, '<?code x="foo"?><?code y=17?><?print x*y?>') 
    333     check("foo"*17, '<?print "foo"*17?>') 
    334     check("(foo)(bar)(foo)(bar)(foo)(bar)", '<?for i in 3*data?>(<?print i?>)<?end for?>', data=["foo", "bar"]) 
     334    check(str(17*23), u'<?print 17*23?>') 
     335    check(str(17*23), u'<?code x=17?><?code y=23?><?print x*y?>') 
     336    check(17*"foo", u'<?print 17*"foo"?>') 
     337    check(17*"foo", u'<?code x=17?><?code y="foo"?><?print x*y?>') 
     338    check("foo"*17, u'<?code x="foo"?><?code y=17?><?print x*y?>') 
     339    check("foo"*17, u'<?print "foo"*17?>') 
     340    check("(foo)(bar)(foo)(bar)(foo)(bar)", u'<?for i in 3*data?>(<?print i?>)<?end for?>', data=["foo", "bar"]) 
    335341 
    336342 
    337343def test_truediv(): 
    338     check("0.5", '<?print 1/2?>') 
    339     check("0.5", '<?code x=1?><?code y=2?><?print x/y?>') 
     344    check("0.5", u'<?print 1/2?>') 
     345    check("0.5", u'<?code x=1?><?code y=2?><?print x/y?>') 
    340346 
    341347 
    342348def test_floordiv(): 
    343     check("0", '<?print 1//2?>') 
    344     check("0", '<?code x=1?><?code y=2?><?print x//y?>') 
     349    check("0", u'<?print 1//2?>') 
     350    check("0", u'<?code x=1?><?code y=2?><?print x//y?>') 
    345351 
    346352 
    347353def test_mod(): 
    348     check(str(42%17), '<?print 42%17?>') 
    349     check(str(42%17), '<?code x=42?><?code y=17?><?print x%y?>') 
     354    check(str(42%17), u'<?print 42%17?>') 
     355    check(str(42%17), u'<?code x=42?><?code y=17?><?print x%y?>') 
    350356 
    351357 
    352358def test_eq(): 
    353     check("False", '<?print 17==23?>') 
    354     check("True", '<?print 17==17?>') 
    355     check("False", '<?print x==23?>', x=17) 
    356     check("True", '<?print x==23?>', x=23) 
     359    check("False", u'<?print 17==23?>') 
     360    check("True", u'<?print 17==17?>') 
     361    check("False", u'<?print x==23?>', x=17) 
     362    check("True", u'<?print x==23?>', x=23) 
    357363 
    358364 
    359365def test_ne(): 
    360     check("True", '<?print 17!=23?>') 
    361     check("False", '<?print 17!=17?>') 
    362     check("True", '<?print x!=23?>', x=17) 
    363     check("False", '<?print x!=23?>', x=23) 
     366    check("True", u'<?print 17!=23?>') 
     367    check("False", u'<?print 17!=17?>') 
     368    check("True", u'<?print x!=23?>', x=17) 
     369    check("False", u'<?print x!=23?>', x=23) 
    364370 
    365371 
    366372def test_lt(): 
    367     check("True", '<?print 1<2?>') 
    368     check("False", '<?print 2<2?>') 
    369     check("False", '<?print 3<2?>') 
    370     check("True", '<?print x<2?>', x=1) 
    371     check("False", '<?print x<2?>', x=2) 
    372     check("False", '<?print x<2?>', x=3) 
     373    check("True", u'<?print 1<2?>') 
     374    check("False", u'<?print 2<2?>') 
     375    check("False", u'<?print 3<2?>') 
     376    check("True", u'<?print x<2?>', x=1) 
     377    check("False", u'<?print x<2?>', x=2) 
     378    check("False", u'<?print x<2?>', x=3) 
    373379 
    374380 
    375381def test_le(): 
    376     check("True", '<?print 1<=2?>') 
    377     check("True", '<?print 2<=2?>') 
    378     check("False", '<?print 3<=2?>') 
    379     check("True", '<?print x<=2?>', x=1) 
    380     check("True", '<?print x<=2?>', x=2) 
    381     check("False", '<?print x<=2?>', x=3) 
     382    check("True", u'<?print 1<=2?>') 
     383    check("True", u'<?print 2<=2?>') 
     384    check("False", u'<?print 3<=2?>') 
     385    check("True", u'<?print x<=2?>', x=1) 
     386    check("True", u'<?print x<=2?>', x=2) 
     387    check("False", u'<?print x<=2?>', x=3) 
    382388 
    383389 
    384390def test_gt(): 
    385     check("False", '<?print 1>2?>') 
    386     check("False", '<?print 2>2?>') 
    387     check("True", '<?print 3>2?>') 
    388     check("False", '<?print x>2?>', x=1) 
    389     check("False", '<?print x>2?>', x=2) 
    390     check("True", '<?print x>2?>', x=3) 
     391    check("False", u'<?print 1>2?>') 
     392    check("False", u'<?print 2>2?>') 
     393    check("True", u'<?print 3>2?>') 
     394    check("False", u'<?print x>2?>', x=1) 
     395    check("False", u'<?print x>2?>', x=2) 
     396    check("True", u'<?print x>2?>', x=3) 
    391397 
    392398 
    393399def test_and(): 
    394     check("False", '<?print x and y?>', x=False, y=False) 
    395     check("False", '<?print x and y?>', x=False, y=True) 
    396     check("0", '<?print x and y?>', x=0, y=True) 
     400    check("False", u'<?print x and y?>', x=False, y=False) 
     401    check("False", u'<?print x and y?>', x=False, y=True) 
     402    check("0", u'<?print x and y?>', x=0, y=True) 
    397403 
    398404 
    399405def test_or(): 
    400     check("False", '<?print x or y?>', x=False, y=False) 
    401     check("True", '<?print x or y?>', x=False, y=True) 
    402     check("42", '<?print x or y?>', x=42, y=True) 
     406    check("False", u'<?print x or y?>', x=False, y=False) 
     407    check("True", u'<?print x or y?>', x=False, y=True) 
     408    check("42", u'<?print x or y?>', x=42, y=True) 
    403409 
    404410 
    405411def test_not(): 
    406     check("True", '<?print not x?>', x=False) 
    407     check("False", '<?print not x?>', x=42) 
     412    check("True", u'<?print not x?>', x=False) 
     413    check("False", u'<?print not x?>', x=42) 
    408414 
    409415 
    410416def test_ge(): 
    411     check("False", '<?print 1>=2?>') 
    412     check("True", '<?print 2>=2?>') 
    413     check("True", '<?print 3>=2?>') 
    414     check("False", '<?print x>=2?>', x=1) 
    415     check("True", '<?print x>=2?>', x=2) 
    416     check("True", '<?print x>=2?>', x=3) 
     417    check("False", u'<?print 1>=2?>') 
     418    check("True", u'<?print 2>=2?>') 
     419    check("True", u'<?print 3>=2?>') 
     420    check("False", u'<?print x>=2?>', x=1) 
     421    check("True", u'<?print x>=2?>', x=2) 
     422    check("True", u'<?print x>=2?>', x=3) 
    417423 
    418424 
    419425def test_getitem(): 
    420     check("u", "<?print 'gurk'[1]?>") 
    421     check("u", "<?print x[1]?>", x="gurk") 
    422     check("u", "<?print 'gurk'[-3]?>") 
    423     check("u", "<?print x[-3]?>", x="gurk") 
    424     checkcompileerror("IndexError", "<?print 'gurk'[4]?>") 
    425     checkrunerror("IndexError", "<?print x[4]?>", x="gurk") 
    426     checkcompileerror("IndexError", "<?print 'gurk'[-5]?>") 
    427     checkrunerror("IndexError", "<?print x[-5]?>", x="gurk") 
     426    check("u", u"<?print 'gurk'[1]?>") 
     427    check("u", u"<?print x[1]?>", x="gurk") 
     428    check("u", u"<?print 'gurk'[-3]?>") 
     429    check("u", u"<?print x[-3]?>", x="gurk") 
     430    checkcompileerror("IndexError", u"<?print 'gurk'[4]?>") 
     431    checkrunerror("IndexError", u"<?print x[4]?>", x="gurk") 
     432    checkcompileerror("IndexError", u"<?print 'gurk'[-5]?>") 
     433    checkrunerror("IndexError", u"<?print x[-5]?>", x="gurk") 
    428434 
    429435 
    430436def test_getslice12(): 
    431     check("ur", "<?print 'gurk'[1:3]?>") 
    432     check("ur", "<?print x[1:3]?>", x="gurk") 
    433     check("ur", "<?print 'gurk'[-3:-1]?>") 
    434     check("ur", "<?print x[-3:-1]?>", x="gurk") 
    435     check("", "<?print 'gurk'[4:10]?>") 
    436     check("", "<?print x[4:10]?>", x="gurk") 
    437     check("", "<?print 'gurk'[-10:-5]?>") 
    438     check("", "<?print x[-10:-5]?>", x="gurk") 
     437    check("ur", u"<?print 'gurk'[1:3]?>") 
     438    check("ur", u"<?print x[1:3]?>", x="gurk") 
     439    check("ur", u"<?print 'gurk'[-3:-1]?>") 
     440    check("ur", u"<?print x[-3:-1]?>", x="gurk") 
     441    check("", u"<?print 'gurk'[4:10]?>") 
     442    check("", u"<?print x[4:10]?>", x="gurk") 
     443    check("", u"<?print 'gurk'[-10:-5]?>") 
     444    check("", u"<?print x[-10:-5]?>", x="gurk") 
    439445 
    440446 
    441447def test_getslice1(): 
    442     check("urk", "<?print 'gurk'[1:]?>") 
    443     check("urk", "<?print x[1:]?>", x="gurk") 
    444     check("urk", "<?print 'gurk'[-3:]?>") 
    445     check("urk", "<?print x[-3:]?>", x="gurk") 
    446     check("", "<?print 'gurk'[4:]?>") 
    447     check("", "<?print x[4:]?>", x="gurk") 
    448     check("gurk", "<?print 'gurk'[-10:]?>") 
    449     check("gurk", "<?print x[-10:]?>", x="gurk") 
     448    check("urk", u"<?print 'gurk'[1:]?>") 
     449    check("urk", u"<?print x[1:]?>", x="gurk") 
     450    check("urk", u"<?print 'gurk'[-3:]?>") 
     451    check("urk", u"<?print x[-3:]?>", x="gurk") 
     452    check("", u"<?print 'gurk'[4:]?>") 
     453    check("", u"<?print x[4:]?>", x="gurk") 
     454    check("gurk", u"<?print 'gurk'[-10:]?>") 
     455    check("gurk", u"<?print x[-10:]?>", x="gurk") 
    450456 
    451457 
    452458def test_getslice2(): 
    453     check("gur", "<?print 'gurk'[:3]?>") 
    454     check("gur", "<?print x[:3]?>", x="gurk") 
    455     check("gur", "<?print 'gurk'[:-1]?>") 
    456     check("gur", "<?print x[:-1]?>", x="gurk") 
    457     check("gurk", "<?print 'gurk'[:10]?>") 
    458     check("gurk", "<?print x[:10]?>", x="gurk") 
    459     check("", "<?print 'gurk'[:-5]?>") 
    460     check("", "<?print x[:-5]?>", x="gurk") 
     459    check("gur", u"<?print 'gurk'[:3]?>") 
     460    check("gur", u"<?print x[:3]?>", x="gurk") 
     461    check("gur", u"<?print 'gurk'[:-1]?>") 
     462    check("gur", u"<?print x[:-1]?>", x="gurk") 
     463    check("gurk", u"<?print 'gurk'[:10]?>") 
     464    check("gurk", u"<?print x[:10]?>", x="gurk") 
     465    check("", u"<?print 'gurk'[:-5]?>") 
     466    check("", u"<?print x[:-5]?>", x="gurk") 
    461467 
    462468 
    463469def test_nested(): 
    464     sc = "4" 
    465     sv = "x" 
     470    sc = u"4" 
     471    sv = u"x" 
    466472    n = 4 
    467473    for i in xrange(8): # when using 10 compiling the variable will run out of registers 
    468         sc = "(%s)+(%s)" % (sc, sc) 
    469         sv = "(%s)+(%s)" % (sv, sv) 
     474        sc = u"(%s)+(%s)" % (sc, sc) 
     475        sv = u"(%s)+(%s)" % (sv, sv) 
    470476        n = n+n 
    471     check(str(n), '<?print %s?>' % sc) 
    472     check(str(n), '<?code x=4?><?print %s?>' % sv) 
     477    check(str(n), u'<?print %s?>' % sc) 
     478    check(str(n), u'<?code x=4?><?print %s?>' % sv) 
    473479 
    474480 
    475481def test_precedence(): 
    476     check("14", '<?print 2+3*4?>') 
    477     check("20", '<?print (2+3)*4?>') 
    478     check("10", '<?print -2+-3*-4?>') 
    479     check("14", '<?print --2+--3*--4?>') 
    480     check("14", '<?print (-(-2))+(-((-3)*-(-4)))?>') 
    481     check("42", '<?print 2*data.value?>', data=dict(value=21)) 
    482     check("42", '<?print data.value[0]?>', data=dict(value=[42])) 
    483     check("42", '<?print data[0].value?>', data=[dict(value=42)]) 
    484     check("42", '<?print data[0][0][0]?>', data=[[[42]]]) 
    485     check("42", '<?print data.value.value[0]?>', data=dict(value=dict(value=[42]))) 
    486     check("42", '<?print data.value.value[0].value.value[0]?>', data=dict(value=dict(value=[dict(value=dict(value=[42]))]))) 
     482    check("14", u'<?print 2+3*4?>') 
     483    check("20", u'<?print (2+3)*4?>') 
     484    check("10", u'<?print -2+-3*-4?>') 
     485    check("14", u'<?print --2+--3*--4?>') 
     486    check("14", u'<?print (-(-2))+(-((-3)*-(-4)))?>') 
     487    check("42", u'<?print 2*data.value?>', data=dict(value=21)) 
     488    check("42", u'<?print data.value[0]?>', data=dict(value=[42])) 
     489    check("42", u'<?print data[0].value?>', data=[dict(value=42)]) 
     490    check("42", u'<?print data[0][0][0]?>', data=[[[42]]]) 
     491    check("42", u'<?print data.value.value[0]?>', data=dict(value=dict(value=[42]))) 
     492    check("42", u'<?print data.value.value[0].value.value[0]?>', data=dict(value=dict(value=[dict(value=dict(value=[42]))]))) 
    487493 
    488494 
    489495def test_bracket(): 
    490     sc = "4" 
    491     sv = "x" 
     496    sc = u"4" 
     497    sv = u"x" 
    492498    for i in xrange(10): 
    493         sc = "(%s)" % sc 
    494         sv = "(%s)" % sv 
    495  
    496     check("4", '<?print %s?>' % sc) 
    497     check("4", '<?code x=4?><?print %s?>' % sv) 
     499        sc = u"(%s)" % sc 
     500        sv = u"(%s)" % sv 
     501 
     502    check("4", u'<?print %s?>' % sc) 
     503    check("4", u'<?code x=4?><?print %s?>' % sv) 
    498504 
    499505 
    500506def test_function_now(): 
    501     checkrunerror("function u?'now' unknown", "<?print now(1)?>") 
    502     checkrunerror("function u?'now' unknown", "<?print now(1, 2)?>") 
     507    checkrunerror("function u?'now' unknown", u"<?print now(1)?>") 
     508    checkrunerror("function u?'now' unknown", u"<?print now(1, 2)?>") 
    503509    now = unicode(datetime.datetime.now()) 
    504     checkle(now, "<?print now()?>") 
     510    checkle(now, u"<?print now()?>") 
    505511 
    506512 
    507513def test_function_xmlescape(): 
    508     checkrunerror("function u?'xmlescape' unknown", "<?print xmlescape()?>") 
    509     checkrunerror("function u?'xmlescape' unknown", "<?print xmlescape(1, 2)?>") 
    510     check("&lt;&gt;&amp;&#39;&quot;gurk", "<?print xmlescape(data)?>", data='<>&\'"gurk') 
     514    checkrunerror("function u?'xmlescape' unknown", u"<?print xmlescape()?>") 
     515    checkrunerror("function u?'xmlescape' unknown", u"<?print xmlescape(1, 2)?>") 
     516    check("&lt;&gt;&amp;&#39;&quot;gurk", u"<?print xmlescape(data)?>", data='<>&\'"gurk') 
    511517 
    512518 
    513519def test_function_csvescape(): 
    514     checkrunerror("function u?'csvescape' unknown", "<?print csvescape()?>") 
    515     checkrunerror("function u?'csvescape' unknown", "<?print csvescape(1, 2)?>") 
    516     check("", "<?print csvescape(data)?>", data=None) 
    517     check("False", "<?print csvescape(data)?>", data=False) 
    518     check("True", "<?print csvescape(data)?>", data=True) 
    519     check("42", "<?print csvescape(data)?>", data=42) 
     520    checkrunerror("function u?'csvescape' unknown", u"<?print csvescape()?>") 
     521    checkrunerror("function u?'csvescape' unknown", u"<?print csvescape(1, 2)?>") 
     522    check("", u"<?print csvescape(data)?>", data=None) 
     523    check("False", u"<?print csvescape(data)?>", data=False) 
     524    check("True", u"<?print csvescape(data)?>", data=True) 
     525    check("42", u"<?print csvescape(data)?>", data=42) 
    520526    # no check for float 
    521     check("abc", "<?print csvescape(data)?>", data="abc") 
    522     check('"a,b,c"', "<?print csvescape(data)?>", data="a,b,c") 
    523     check('"a""b""c"', "<?print csvescape(data)?>", data='a"b"c') 
    524     check('"a\nb\nc"', "<?print csvescape(data)?>", data="a\nb\nc") 
     527    check("abc", u"<?print csvescape(data)?>", data="abc") 
     528    check('"a,b,c"', u"<?print csvescape(data)?>", data="a,b,c") 
     529    check('"a""b""c"', u"<?print csvescape(data)?>", data='a"b"c') 
     530    check('"a\nb\nc"', u"<?print csvescape(data)?>", data="a\nb\nc") 
    525531 
    526532 
    527533def test_function_str(): 
    528     checkrunerror("function u?'str' unknown", "<?print str()?>") 
    529     checkrunerror("function u?'str' unknown", "<?print str(1, 2)?>") 
    530     check("", "<?print str(data)?>", data=None) 
    531     check("True", "<?print str(data)?>", data=True) 
    532     check("False", "<?print str(data)?>", data=False) 
    533     check("42", "<?print str(data)?>", data=42) 
    534     check("4.2", "<?print str(data)?>", data=4.2) 
    535     check("foo", "<?print str(data)?>", data="foo") 
     534    checkrunerror("function u?'str' unknown", u"<?print str()?>") 
     535    checkrunerror("function u?'str' unknown", u"<?print str(1, 2)?>") 
     536    check("", u"<?print str(data)?>", data=None) 
     537    check("True", u"<?print str(data)?>", data=True) 
     538    check("False", u"<?print str(data)?>", data=False) 
     539    check("42", u"<?print str(data)?>", data=42) 
     540    check("4.2", u"<?print str(data)?>", data=4.2) 
     541    check("foo", u"<?print str(data)?>", data="foo") 
    536542 
    537543 
    538544def test_function_int(): 
    539     checkrunerror("function u?'int' unknown", "<?print int()?>") 
    540     checkrunerror("function u?'int' unknown", "<?print int(1, 2)?>") 
    541     checkrunerror("int\\(\\) argument must be a string or a number, not 'NoneType'", "<?print int(data)?>", data=None) 
    542     check("1", "<?print int(data)?>", data=True) 
    543     check("0", "<?print int(data)?>", data=False) 
    544     check("42", "<?print int(data)?>", data=42) 
    545     check("4", "<?print int(data)?>", data=4.2) 
    546     check("42", "<?print int(data)?>", data="42") 
    547     checkrunerror("invalid literal for int\\(\\) with base 10: 'foo'", "<?print int(data)?>", data="foo") 
     545    checkrunerror("function u?'int' unknown", u"<?print int()?>") 
     546    checkrunerror("function u?'int' unknown", u"<?print int(1, 2)?>") 
     547    checkrunerror("int\\(\\) argument must be a string or a number, not 'NoneType'", u"<?print int(data)?>", data=None) 
     548    check("1", u"<?print int(data)?>", data=True) 
     549    check("0", u"<?print int(data)?>", data=False) 
     550    check("42", u"<?print int(data)?>", data=42) 
     551    check("4", u"<?print int(data)?>", data=4.2) 
     552    check("42", u"<?print int(data)?>", data="42") 
     553    checkrunerror("invalid literal for int\\(\\) with base 10: 'foo'", u"<?print int(data)?>", data="foo") 
    548554 
    549555 
    550556def test_function_len(): 
    551     checkrunerror("function u?'len' unknown", "<?print len()?>") 
    552     checkrunerror("function u?'len' unknown", "<?print len(1, 2)?>") 
    553     checkrunerror("object of type 'NoneType' has no len", "<?print len(data)?>", data=None) 
    554     checkrunerror("object of type 'bool' has no len", "<?print len(data)?>", data=True) 
    555     checkrunerror("object of type 'bool' has no len", "<?print len(data)?>", data=False) 
    556     checkrunerror("object of type 'int' has no len", "<?print len(data)?>", data=42) 
    557     checkrunerror("object of type 'float' has no len", "<?print len(data)?>", data=4.2) 
    558     check("42", "<?print len(data)?>", data=42*"?") 
    559     check("42", "<?print len(data)?>", data=42*[None]) 
    560     check("42", "<?print len(data)?>", data=dict.fromkeys(xrange(42))) 
     557    checkrunerror("function u?'len' unknown", u"<?print len()?>") 
     558    checkrunerror("function u?'len' unknown", u"<?print len(1, 2)?>") 
     559    checkrunerror("object of type 'NoneType' has no len", u"<?print len(data)?>", data=None) 
     560    checkrunerror("object of type 'bool' has no len", u"<?print len(data)?>", data=True) 
     561    checkrunerror("object of type 'bool' has no len", u"<?print len(data)?>", data=False) 
     562    checkrunerror("object of type 'int' has no len", u"<?print len(data)?>", data=42) 
     563    checkrunerror("object of type 'float' has no len", u"<?print len(data)?>", data=4.2) 
     564    check("42", u"<?print len(data)?>", data=42*"?") 
     565    check("42", u"<?print len(data)?>", data=42*[None]) 
     566    check("42", u"<?print len(data)?>", data=dict.fromkeys(xrange(42))) 
    561567 
    562568 
    563569def test_function_enumerate(): 
    564     checkrunerror("function u?'enumerate' unknown", "<?print enumerate()?>") 
    565     checkrunerror("function u?'enumerate' unknown", "<?print enumerate(1, 2)?>") 
    566     code = "<?for (i, value) in enumerate(data)?><?print i?>:<?print value?>\n<?end for?>" 
     570    checkrunerror("function u?'enumerate' unknown", u"<?print enumerate()?>") 
     571    checkrunerror("function u?'enumerate' unknown", u"<?print enumerate(1, 2)?>") 
     572    code = u"<?for (i, value) in enumerate(data)?><?print i?>:<?print value?>\n<?end for?>" 
    567573    checkrunerror("'NoneType' object is not iterable", code, data=None) 
    568574    checkrunerror("'bool' object is not iterable", code, data=True) 
     
    576582 
    577583def test_function_isnone(): 
    578     checkrunerror("function u?'isnone' unknown", "<?print isnone()?>") 
    579     checkrunerror("function u?'isnone' unknown", "<?print isnone(1, 2)?>") 
    580     code = "<?print isnone(data)?>" 
     584    checkrunerror("function u?'isnone' unknown", u"<?print isnone()?>") 
     585    checkrunerror("function u?'isnone' unknown", u"<?print isnone(1, 2)?>") 
     586    code = u"<?print isnone(data)?>" 
    581587    check("True", code, data=None) 
    582588    check("False", code, data=True) 
     
    592598 
    593599def test_function_isbool(): 
    594     checkrunerror("function u?'isbool' unknown", "<?print isbool()?>") 
    595     checkrunerror("function u?'isbool' unknown", "<?print isbool(1, 2)?>") 
    596     code = "<?print isbool(data)?>" 
     600    checkrunerror("function u?'isbool' unknown", u"<?print isbool()?>") 
     601    checkrunerror("function u?'isbool' unknown", u"<?print isbool(1, 2)?>") 
     602    code = u"<?print isbool(data)?>" 
    597603    check("False", code, data=None) 
    598604    check("True", code, data=True) 
     
    608614 
    609615def test_function_isint(): 
    610     checkrunerror("function u?'isint' unknown", "<?print isint()?>") 
    611     checkrunerror("function u?'isint' unknown", "<?print isint(1, 2)?>") 
    612     code = "<?print isint(data)?>" 
     616    checkrunerror("function u?'isint' unknown", u"<?print isint()?>") 
     617    checkrunerror("function u?'isint' unknown", u"<?print isint(1, 2)?>") 
     618    code = u"<?print isint(data)?>" 
    613619    check("False", code, data=None) 
    614620    check("False", code, data=True) 
     
    624630 
    625631def test_function_isfloat(): 
    626     checkrunerror("function u?'isfloat' unknown", "<?print isfloat()?>") 
    627     checkrunerror("function u?'isfloat' unknown", "<?print isfloat(1, 2)?>") 
    628     code = "<?print isfloat(data)?>" 
     632    checkrunerror("function u?'isfloat' unknown", u"<?print isfloat()?>") 
     633    checkrunerror("function u?'isfloat' unknown", u"<?print isfloat(1, 2)?>") 
     634    code = u"<?print isfloat(data)?>" 
    629635    check("False", code, data=None) 
    630636    check("False", code, data=True) 
     
    640646 
    641647def test_function_isstr(): 
    642     checkrunerror("function u?'isstr' unknown", "<?print isstr()?>") 
    643     checkrunerror("function u?'isstr' unknown", "<?print isstr(1, 2)?>") 
    644     code = "<?print isstr(data)?>" 
     648    checkrunerror("function u?'isstr' unknown", u"<?print isstr()?>") 
     649    checkrunerror("function u?'isstr' unknown", u"<?print isstr(1, 2)?>") 
     650    code = u"<?print isstr(data)?>" 
    645651    check("False", code, data=None) 
    646652    check("False", code, data=True) 
     
    656662 
    657663def test_function_isdate(): 
    658     checkrunerror("function u?'isdate' unknown", "<?print isdate()?>") 
    659     checkrunerror("function u?'isdate' unknown", "<?print isdate(1, 2)?>") 
    660     code = "<?print isdate(data)?>" 
     664    checkrunerror("function u?'isdate' unknown", u"<?print isdate()?>") 
     665    checkrunerror("function u?'isdate' unknown", u"<?print isdate(1, 2)?>") 
     666    code = u"<?print isdate(data)?>" 
    661667    check("False", code, data=None) 
    662668    check("False", code, data=True) 
     
    672678 
    673679def test_function_islist(): 
    674     checkrunerror("function u?'islist' unknown", "<?print islist()?>") 
    675     checkrunerror("function u?'islist' unknown", "<?print islist(1, 2)?>") 
    676     code = "<?print islist(data)?>" 
     680    checkrunerror("function u?'islist' unknown", u"<?print islist()?>") 
     681    checkrunerror("function u?'islist' unknown", u"<?print islist(1, 2)?>") 
     682    code = u"<?print islist(data)?>" 
    677683    check("False", code, data=None) 
    678684    check("False", code, data=True) 
     
    688694 
    689695def test_function_isdict(): 
    690     checkrunerror("function u?'isdict' unknown", "<?print isdict()?>") 
    691     checkrunerror("function u?'isdict' unknown", "<?print isdict(1, 2)?>") 
    692     code = "<?print isdict(data)?>" 
     696    checkrunerror("function u?'isdict' unknown", u"<?print isdict()?>") 
     697    checkrunerror("function u?'isdict' unknown", u"<?print isdict(1, 2)?>") 
     698    code = u"<?print isdict(data)?>" 
    693699    check("False", code, data=None) 
    694700    check("False", code, data=True) 
     
    704710 
    705711def test_function_get(): 
    706     checkrunerror("function u?'get' unknown", "<?print get()?>") 
    707     check("", "<?print get('x')?>") 
    708     check("42", "<?print get('x')?>", x=42) 
    709     check("17", "<?print get('x', 17)?>") 
    710     check("42", "<?print get('x', 17)?>", x=42) 
     712    checkrunerror("function u?'get' unknown", u"<?print get()?>") 
     713    check("", u"<?print get('x')?>") 
     714    check("42", u"<?print get('x')?>", x=42) 
     715    check("17", u"<?print get('x', 17)?>") 
     716    check("42", u"<?print get('x', 17)?>", x=42) 
    711717 
    712718 
    713719def test_function_repr(): 
    714     checkrunerror("function u?'repr' unknown", "<?print repr()?>") 
    715     checkrunerror("function u?'repr' unknown", "<?print repr(1, 2)?>") 
    716     code = "<?print repr(data)?>" 
     720    checkrunerror("function u?'repr' unknown", u"<?print repr()?>") 
     721    checkrunerror("function u?'repr' unknown", u"<?print repr(1, 2)?>") 
     722    code = u"<?print repr(data)?>" 
    717723    check("None", code, data=None) 
    718724    check("True", code, data=True) 
     
    725731 
    726732def test_function_chr(): 
    727     checkrunerror("function u?'chr' unknown", "<?print chr()?>") 
    728     checkrunerror("function u?'chr' unknown", "<?print chr(1, 2)?>") 
    729     code = "<?print chr(data)?>" 
     733    checkrunerror("function u?'chr' unknown", u"<?print chr()?>") 
     734    checkrunerror("function u?'chr' unknown", u"<?print chr(1, 2)?>") 
     735    code = u"<?print chr(data)?>" 
    730736    check("\x00", code, data=0) 
    731737    check("a", code, data=ord("a")) 
     
    734740 
    735741def test_function_ord(): 
    736     checkrunerror("function u?'ord' unknown", "<?print ord()?>") 
    737     checkrunerror("function u?'ord' unknown", "<?print ord(1, 2)?>") 
    738     code = "<?print ord(data)?>" 
     742    checkrunerror("function u?'ord' unknown", u"<?print ord()?>") 
     743    checkrunerror("function u?'ord' unknown", u"<?print ord(1, 2)?>") 
     744    code = u"<?print ord(data)?>" 
    739745    check("0", code, data="\x00") 
    740746    check(str(ord("a")), code, data="a") 
     
    743749 
    744750def test_function_hex(): 
    745     checkrunerror("function u?'hex' unknown", "<?print hex()?>") 
    746     checkrunerror("function u?'hex' unknown", "<?print hex(1, 2)?>") 
    747     code = "<?print hex(data)?>" 
     751    checkrunerror("function u?'hex' unknown", u"<?print hex()?>") 
     752    checkrunerror("function u?'hex' unknown", u"<?print hex(1, 2)?>") 
     753    code = u"<?print hex(data)?>" 
    748754    check("0x0", code, data=0) 
    749755    check("0xff", code, data=0xff) 
     
    753759 
    754760def test_function_oct(): 
    755     checkrunerror("function u?'oct' unknown", "<?print oct()?>") 
    756     checkrunerror("function u?'oct' unknown", "<?print oct(1, 2)?>") 
    757     code = "<?print oct(data)?>" 
     761    checkrunerror("function u?'oct' unknown", u"<?print oct()?>") 
     762    checkrunerror("function u?'oct' unknown", u"<?print oct(1, 2)?>") 
     763    code = u"<?print oct(data)?>" 
    758764    check("0o0", code, data=0) 
    759765    check("0o77", code, data=077) 
     
    763769 
    764770def test_function_bin(): 
    765     checkrunerror("function u?'bin' unknown", "<?print bin()?>") 
    766     checkrunerror("function u?'bin' unknown", "<?print bin(1, 2)?>") 
    767     code = "<?print bin(data)?>" 
     771    checkrunerror("function u?'bin' unknown", u"<?print bin()?>") 
     772    checkrunerror("function u?'bin' unknown", u"<?print bin(1, 2)?>") 
     773    code = u"<?print bin(data)?>" 
    768774    check("0b0", code, data=0) 
    769775    check("0b11", code, data=3) 
     
    772778 
    773779def test_function_sorted(): 
    774     checkrunerror("function u?'sorted' unknown", "<?print sorted()?>") 
    775     checkrunerror("function u?'sorted' unknown", "<?print sorted(1, 2)?>") 
    776     code = "<?for i in sorted(data)?><?print i?><?end for?>" 
     780    checkrunerror("function u?'sorted' unknown", u"<?print sorted()?>") 
     781    checkrunerror("function u?'sorted' unknown", u"<?print sorted(1, 2)?>") 
     782    code = u"<?for i in sorted(data)?><?print i?><?end for?>" 
    777783    check("gkru", code, data="gurk") 
    778784    check("24679", code, data="92746") 
     
    781787 
    782788def test_function_range(): 
    783     checkrunerror("function u?'sorted' unknown", "<?print sorted()?>") 
    784     code = "<?for i in range(data)?><?print i?><?end for?>" 
     789    checkrunerror("function u?'sorted' unknown", u"<?print sorted()?>") 
     790    code = u"<?for i in range(data)?><?print i?><?end for?>" 
    785791    check("", code, data=-10) 
    786792    check("", code, data=0) 
    787793    check("0", code, data=1) 
    788794    check("01234", code, data=5) 
    789     code = "<?for i in range(data[0], data[1])?><?print i?><?end for?>" 
     795    code = u"<?for i in range(data[0], data[1])?><?print i?><?end for?>" 
    790796    check("", code, data=[0, -10]) 
    791797    check("", code, data=[0, 0]) 
    792798    check("01234", code, data=[0, 5]) 
    793799    check("-5-4-3-2-101234", code, data=[-5, 5]) 
    794     code = "<?for i in range(data[0], data[1], data[2])?><?print i?><?end for?>" 
     800    code = u"<?for i in range(data[0], data[1], data[2])?><?print i?><?end for?>" 
    795801    check("", code, data=[0, -10, 1]) 
    796802    check("", code, data=[0, 0, 1]) 
     
    802808 
    803809def test_function_zip(): 
    804     checkrunerror("function u?'zip' unknown", "<?print zip()?>") 
    805     checkrunerror("function u?'zip' unknown", "<?print zip(1)?>") 
    806     code = "<?for (ix, iy) in zip(x, y)?><?print ix?>-<?print iy?>;<?end for?>" 
     810    checkrunerror("function u?'zip' unknown", u"<?print zip()?>") 
     811    checkrunerror("function u?'zip' unknown", u"<?print zip(1)?>") 
     812    code = u"<?for (ix, iy) in zip(x, y)?><?print ix?>-<?print iy?>;<?end for?>" 
    807813    check("", code, x=[], y=[]) 
    808814    check("1-3;2-4;", code, x=[1, 2], y=[3, 4]) 
    809815    check("1-4;2-5;", code, x=[1, 2, 3], y=[4, 5]) 
    810     code = "<?for (ix, iy, iz) in zip(x, y, z)?><?print ix?>-<?print iy?>+<?print iz?>;<?end for?>" 
     816    code = u"<?for (ix, iy, iz) in zip(x, y, z)?><?print ix?>-<?print iy?>+<?print iz?>;<?end for?>" 
    811817    check("", code, x=[], y=[], z=[]) 
    812818    check("1-3+5;2-4+6;", code, x=[1, 2], y=[3, 4], z=[5, 6]) 
     
    815821 
    816822def test_method_upper(): 
    817     check("GURK", "<?print 'gurk'.upper()?>") 
     823    check("GURK", u"<?print 'gurk'.upper()?>") 
    818824 
    819825 
    820826def test_method_lower(): 
    821     check("gurk", "<?print 'GURK'.lower()?>") 
     827    check("gurk", u"<?print 'GURK'.lower()?>") 
    822828 
    823829 
    824830def test_method_capitalize(): 
    825     check("Gurk", "<?print 'gURK'.capitalize()?>") 
     831    check("Gurk", u"<?print 'gURK'.capitalize()?>") 
    826832 
    827833 
    828834def test_method_startswith(): 
    829     check("True", "<?print 'gurkhurz'.startswith('gurk')?>") 
    830     check("False", "<?print 'gurkhurz'.startswith('hurz')?>") 
     835    check("True", u"<?print 'gurkhurz'.startswith('gurk')?>") 
     836    check("False", u"<?print 'gurkhurz'.startswith('hurz')?>") 
    831837 
    832838 
    833839def test_method_endswith(): 
    834     check("True", "<?print 'gurkhurz'.endswith('hurz')?>") 
    835     check("False", "<?print 'gurkhurz'.endswith('gurk')?>") 
     840    check("True", u"<?print 'gurkhurz'.endswith('hurz')?>") 
     841    check("False", u"<?print 'gurkhurz'.endswith('gurk')?>") 
    836842 
    837843 
     
    842848 
    843849def test_method_lstrip(): 
    844     check("gurk \t\r\n", r"<?print ' \t\r\ngurk \t\r\n'.lstrip()?>") 
    845     check("gurkxyzzy", r"<?print 'xyzzygurkxyzzy'.lstrip('xyz')?>") 
     850    check("gurk \t\r\n", ur"<?print ' \t\r\ngurk \t\r\n'.lstrip()?>") 
     851    check("gurkxyzzy", ur"<?print 'xyzzygurkxyzzy'.lstrip('xyz')?>") 
    846852 
    847853 
    848854def test_method_rstrip(): 
    849     check(" \t\r\ngurk", r"<?print ' \t\r\ngurk \t\r\n'.rstrip()?>") 
    850     check("xyzzygurk", r"<?print 'xyzzygurkxyzzy'.rstrip('xyz')?>") 
     855    check(" \t\r\ngurk", ur"<?print ' \t\r\ngurk \t\r\n'.rstrip()?>") 
     856    check("xyzzygurk", ur"<?print 'xyzzygurkxyzzy'.rstrip('xyz')?>") 
    851857 
    852858 
    853859def test_method_split(): 
    854     check("(g)(u)(r)(k)", r"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split()?>(<?print item?>)<?end for?>") 
    855     check("(g)(u \t\r\nr \t\r\nk \t\r\n)", r"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split(None, 1)?>(<?print item?>)<?end for?>") 
    856     check("()(g)(u)(r)(k)()", r"<?for item in 'xxgxxuxxrxxkxx'.split('xx')?>(<?print item?>)<?end for?>") 
    857     check("()(g)(uxxrxxkxx)", r"<?for item in 'xxgxxuxxrxxkxx'.split('xx', 2)?>(<?print item?>)<?end for?>") 
     860    check("(g)(u)(r)(k)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split()?>(<?print item?>)<?end for?>") 
     861    check("(g)(u \t\r\nr \t\r\nk \t\r\n)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split(None, 1)?>(<?print item?>)<?end for?>") 
     862    check("()(g)(u)(r)(k)()", ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx')?>(<?print item?>)<?end for?>") 
     863    check("()(g)(uxxrxxkxx)", ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx', 2)?>(<?print item?>)<?end for?>") 
    858864 
    859865 
    860866def test_method_rsplit(): 
    861     check("(g)(u)(r)(k)", r"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.rsplit()?>(<?print item?>)<?end for?>") 
    862     check("( \t\r\ng \t\r\nu \t\r\nr)(k)", r"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.rsplit(None, 1)?>(<?print item?>)<?end for?>") 
    863     check("()(g)(u)(r)(k)()", r"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx')?>(<?print item?>)<?end for?>") 
    864     check("(xxgxxuxxr)(k)()", r"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx', 2)?>(<?print item?>)<?end for?>") 
     867    check("(g)(u)(r)(k)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.rsplit()?>(<?print item?>)<?end for?>") 
     868    check("( \t\r\ng \t\r\nu \t\r\nr)(k)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.rsplit(None, 1)?>(<?print item?>)<?end for?>") 
     869    check("()(g)(u)(r)(k)()", ur"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx')?>(<?print item?>)<?end for?>") 
     870    check("(xxgxxuxxr)(k)()", ur"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx', 2)?>(<?print item?>)<?end for?>") 
    865871 
    866872 
    867873def test_method_replace(): 
    868     check('goork', r"<?print 'gurk'.replace('u', 'oo')?>") 
     874    check('goork', ur"<?print 'gurk'.replace('u', 'oo')?>") 
    869875 
    870876 
     
    872878    now = datetime.datetime.now() 
    873879    format = "%Y-%m-%d %H:%M:%S" 
    874     check(now.strftime(format), r"<?print data.format('%s')?>" % format, data=now) 
     880    check(now.strftime(format), ur"<?print data.format('%s')?>" % format, data=now) 
    875881 
    876882 
    877883def test_method_isoformat(): 
    878884    now = datetime.datetime.now() 
    879     check(now.isoformat(), r"<?print data.isoformat()?>", data=now) 
     885    check(now.isoformat(), ur"<?print data.isoformat()?>", data=now) 
    880886 
    881887 
    882888def test_method_get(): 
    883     check("42", "<?print {}.get('foo', 42)?>") 
    884     check("17", "<?print {'foo': 17}.get('foo', 42)?>") 
    885     check("", "<?print {}.get('foo')?>") 
    886     check("17", "<?print {'foo': 17}.get('foo')?>") 
     889    check("42", u"<?print {}.get('foo', 42)?>") 
     890    check("17", u"<?print {'foo': 17}.get('foo', 42)?>") 
     891    check("", u"<?print {}.get('foo')?>") 
     892    check("17", u"<?print {'foo': 17}.get('foo')?>") 
    887893 
    888894 
    889895def test_render(): 
    890     t = ul4c.compile('<?print prefix?><?print data?><?print suffix?>') 
    891     check('(f)(o)(o)', '<?for c in data?><?render t(data=c, prefix="(", suffix=")")?><?end for?>', dict(t=t), data='foo') 
     896    t = ul4c.compile(u'<?print prefix?><?print data?><?print suffix?>') 
     897    check('(f)(o)(o)', u'<?for c in data?><?render t(data=c, prefix="(", suffix=")")?><?end for?>', dict(t=t), data='foo') 
    892898 
    893899 
    894900def test_render_var(): 
    895     t = ul4c.compile('<?code x += 1?><?print x?>') 
    896     check('42,43,42', '<?print x?>,<?render t(x=x)?>,<?print x?>', dict(t=t), x=42) 
     901    t = ul4c.compile(u'<?code x += 1?><?print x?>') 
     902    check('42,43,42', u'<?print x?>,<?render t(x=x)?>,<?print x?>', dict(t=t), x=42) 
    897903 
    898904 
    899905def test_parse(): 
    900     check('42', '<?print data.Noner?>', data=dict(Noner=42)) 
     906    check('42', u'<?print data.Noner?>', data=dict(Noner=42)) 
    901907 
    902908 
    903909def test_nested_exceptions(): 
    904     tmpl1 = ul4c.compile("<?print 2*x?>") 
    905     tmpl2 = ul4c.compile("<?render tmpl1(x=x)?>") 
    906     tmpl3 = ul4c.compile("<?render tmpl2(x=x)?>") 
    907  
    908     checkrunerror(r"TypeError .*render tmpl3.*render tmpl2.*render tmpl1.*print 2.*unsupported operand type", "<?render tmpl3(x=x)?>", dict(tmpl1=tmpl1, tmpl2=tmpl2, tmpl3=tmpl3), x=None) 
     910    tmpl1 = ul4c.compile(u"<?print 2*x?>") 
     911    tmpl2 = ul4c.compile(u"<?render tmpl1(x=x)?>") 
     912    tmpl3 = ul4c.compile(u"<?render tmpl2(x=x)?>") 
     913 
     914    checkrunerror(r"TypeError .*render tmpl3.*render tmpl2.*render tmpl1.*print 2.*unsupported operand type", u"<?render tmpl3(x=x)?>", dict(tmpl1=tmpl1, tmpl2=tmpl2, tmpl3=tmpl3), x=None)