Changeset 4326:c4a31d8bc7d4 in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/10/11 15:23:18 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Make test generative at the lowest level.

In this way the captured output only includes the faulty template.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • test/test_ul4.py

    r4324 r4326  
    4242 
    4343 
    44 @contextlib.contextmanager 
    45 def raises(msg): 
    46     # Check that the ``with`` block raises an exception that matches a regexp 
    47     try: 
    48         yield 
    49     except Exception, exc: 
    50         assert re.search(msg, "{0.__class__.__module__}.{0.__class__.__name__}: {0}".format(exc)) is not None 
    51     else: 
    52         py.test.fail("failed to raise exception") 
    53  
    54  
    55 def render(__, **variables): 
    56     __ = ul4c.compile(__) 
    57     print "Testing Python template:" 
    58     print __.pythonsource() 
    59     return __.renders(**variables) 
    60  
    61  
    62 def renderdumps(__, **variables): 
    63     __ = ul4c.compile(__) 
    64     __ = ul4c.loads(__.dumps()) # Recreate the template from the binary dump 
    65     print "Testing Python template loaded from string:" 
    66     print __.pythonsource() 
    67     return __.renders(**variables) 
    68  
    69  
    70 def renderdump(__, **variables): 
    71     __ = ul4c.compile(__) 
    72     stream = StringIO.StringIO() 
    73     __.dump(stream) 
    74     stream.seek(0) 
    75     __ = ul4c.load(stream) # Recreate the template from the stream 
    76     print "Testing Python template loaded from stream:" 
    77     print __.pythonsource() 
    78     return __.renders(**variables) 
    79  
    80  
    81 @py.test.mark.js 
    82 def renderjs(__, **variables): 
    83     # Check the Javascript version (this requires an installed ``d8`` shell from V8 (http://code.google.com/p/v8/)) 
    84     __ = ul4c.compile(__) 
    85     js = __.jssource() 
    86     print "Testing Javascript template:" 
    87     print js.encode("utf-8") 
    88     js = u"template = {};\ndata = {};\nprint(template.renders(data));\n".format(js, ul4c._json(variables)) 
    89     with tempfile.NamedTemporaryFile(mode="wb", suffix=".js") as f: 
    90         f.write(js.encode("utf-8")) 
    91         f.flush() 
    92         result = os.popen("d8 src/ll/data/js/ul4.js {}".format(f.name), "rb").read() 
    93     result = result.decode("utf-8")[:-1] # Drop the "\n" 
    94     # Check if we have an exception 
    95     if result.endswith("^"): 
    96         raise RuntimeError(result.splitlines()[0]) 
    97     return result 
     44class Render(object): 
     45    def __init__(self, __, **variables): 
     46        self.source = __ 
     47        self.variables = variables 
     48        f = sys._getframe(1) 
     49        self.filename = f.f_code.co_filename 
     50        self.lineno = f.f_lineno 
     51 
     52    def __repr__(self): 
     53        return "{0.__class__.__name__}({0.source!r}, {0.variables!r})".format(self) 
     54 
     55 
     56class RenderPython(Render): 
     57    def renders(self): 
     58        template = ul4c.compile(self.source) 
     59        print "Testing Python template:".format(self.filename, self.lineno) 
     60        print template.pythonsource() 
     61        return template.renders(**self.variables) 
     62 
     63 
     64class RenderPythonDumpS(Render): 
     65    def renders(self): 
     66        template = ul4c.compile(self.source) 
     67        template = ul4c.loads(template.dumps()) # Recreate the template from the binary dump 
     68        print "Testing Python template loaded from string ({}, line {}):".format(self.filename, self.lineno) 
     69        print template.pythonsource() 
     70        return template.renders(**self.variables) 
     71 
     72 
     73class RenderPythonDump(Render): 
     74    def renders(self): 
     75        template = ul4c.compile(self.source) 
     76        stream = StringIO.StringIO() 
     77        template.dump(stream) 
     78        stream.seek(0) 
     79        template = ul4c.load(stream) # Recreate the template from the stream 
     80        print "Testing Python template loaded from stream ({}, line {}):".format(self.filename, self.lineno) 
     81        print template.pythonsource() 
     82        return template.renders(**self.variables) 
     83 
     84 
     85class RenderJS(Render): 
     86    def renders(self): 
     87        # Check the Javascript version (this requires an installed ``d8`` shell from V8 (http://code.google.com/p/v8/)) 
     88        template = ul4c.compile(self.source) 
     89        js = template.jssource() 
     90        js = u"template = {};\ndata = {};\nprint(template.renders(data));\n".format(js, ul4c._json(self.variables)) 
     91        print "Testing Javascript code ({}, line {}):".format(self.filename, self.lineno) 
     92        print js.encode("utf-8") 
     93        with tempfile.NamedTemporaryFile(mode="wb", suffix=".js") as f: 
     94            f.write(js.encode("utf-8")) 
     95            f.flush() 
     96            result = os.popen("d8 src/ll/data/js/ul4.js {}".format(f.name), "rb").read() 
     97        result = result.decode("utf-8")[:-1] # Drop the "\n" 
     98        # Check if we have an exception 
     99        if result.endswith("^"): 
     100            raise RuntimeError(result.splitlines()[0]) 
     101        return result 
    98102 
    99103 
     
    121125 
    122126 
    123 @py.test.mark.java 
    124 def renderjava(__, **variables): 
    125     # Check the Java version 
    126     __ = ul4c.compile(__) 
    127     java = __.javasource(indent=4) 
    128     tempdir = tempfile.mkdtemp() 
     127class RenderJava(Render): 
     128    def renders(self): 
     129        # Check the Java version 
     130        template = ul4c.compile(self.source) 
     131        java = template.javasource(indent=4) 
     132        tempdir = tempfile.mkdtemp() 
     133        try: 
     134            print "Testing Java code ({}, line {}):".format(self.filename, self.lineno) 
     135            java = javacodetemplate.format(variables=misc.javaexpr(self.variables), template=java) 
     136            print java.encode("utf-8") 
     137            with open(os.path.join(tempdir, "UL4Test.java"), "wb") as f: 
     138                f.write(java.encode("utf-8")) 
     139            os.system("cd {}; javac -encoding utf-8 UL4Test.java".format(tempdir)) 
     140            result = os.popen("cd {}; java UL4Test 2>&1".format(tempdir), "rb").read() 
     141        finally: 
     142            shutil.rmtree(tempdir) 
     143        result = result.decode("utf-8") 
     144        # Check if we have an exception 
     145        resultlines = result.splitlines() 
     146        for line in resultlines: 
     147            prefix = 'Exception in thread "main"' 
     148            if line.startswith(prefix): 
     149                raise RuntimeError(line[len(prefix):].strip()) 
     150        return result 
     151 
     152 
     153all_python_renderers = (RenderPython, RenderPythonDumpS, RenderPythonDump) 
     154all_renderers = (RenderPython, RenderPythonDumpS, RenderPythonDump, RenderJS, RenderJava) 
     155 
     156 
     157def eq(expected, render): 
     158    got = render.renders() # Put this on an extra line, so that py.test executes it only once 
     159    assert expected == got 
     160 
     161 
     162def evaleq(expected, render): 
     163    got = eval(render.renders()) 
     164    assert expected == got 
     165 
     166 
     167def evalcontains(expected, render): 
     168    got = eval(render.renders()) 
     169    assert got in expected 
     170 
     171 
     172def le(expected, render): 
     173    got = render.renders() 
     174    assert expected <= got 
     175 
     176 
     177def raises(msg, render): 
     178    # Check that executing ``render`` raises an exception that matches a regexp 
    129179    try: 
    130         print "Testing Java template:" 
    131         java = javacodetemplate.format(variables=misc.javaexpr(variables), template=java) 
    132         print java.encode("utf-8") 
    133         with open(os.path.join(tempdir, "UL4Test.java"), "wb") as f: 
    134             f.write(java.encode("utf-8")) 
    135         os.system("cd {}; javac -encoding utf-8 UL4Test.java".format(tempdir)) 
    136         result = os.popen("cd {}; java UL4Test 2>&1".format(tempdir), "rb").read() 
    137     finally: 
    138         shutil.rmtree(tempdir) 
    139     result = result.decode("utf-8") 
    140     # Check if we have an exception 
    141     resultlines = result.splitlines() 
    142     for line in resultlines: 
    143         prefix = 'Exception in thread "main"' 
    144         if line.startswith(prefix): 
    145             raise RuntimeError(line[len(prefix):].strip()) 
    146     return result 
    147  
    148  
    149 def with_all_renderers(func): 
    150     # Decorator that turns a test into a generative test testing the function ``func`` with all ``render*`` functions. 
    151     def decorated(): 
    152         yield func, render 
    153         yield func, renderdumps 
    154         yield func, renderdump 
    155         yield func, renderjs 
    156         yield func, renderjava 
    157     return decorated 
    158  
    159  
    160 @with_all_renderers 
    161 def test_text(r): 
    162     assert u'gurk' == r(u'gurk') 
    163     assert u'g\xfcrk' == r(u'g\xfcrk') 
    164  
    165  
    166 @with_all_renderers 
    167 def test_none(r): 
    168     assert '' == r(u'<?print None?>') 
    169     assert 'no' == r(u'<?if None?>yes<?else?>no<?end if?>') 
    170  
    171  
    172 @with_all_renderers 
    173 def test_false(r): 
    174     assert 'False' == r(u'<?print False?>') 
    175     assert 'no' == r(u'<?if False?>yes<?else?>no<?end if?>') 
    176  
    177  
    178 @with_all_renderers 
    179 def test_true(r): 
    180     assert 'True' == r(u'<?print True?>') 
    181     assert 'yes' == r(u'<?if True?>yes<?else?>no<?end if?>') 
    182  
    183  
    184 @with_all_renderers 
    185 def test_int(r): 
    186     assert '0' == r(u'<?print 0?>') 
    187     assert '42' == r(u'<?print 42?>') 
    188     assert '-42' == r(u'<?print -42?>') 
    189     assert '255' == r(u'<?print 0xff?>') 
    190     assert '255' == r(u'<?print 0Xff?>') 
    191     assert '-255' == r(u'<?print -0xff?>') 
    192     assert '-255' == r(u'<?print -0Xff?>') 
    193     assert '63' == r(u'<?print 0o77?>') 
    194     assert '63' == r(u'<?print 0O77?>') 
    195     assert '-63' == r(u'<?print -0o77?>') 
    196     assert '-63' == r(u'<?print -0O77?>') 
    197     assert '7' == r(u'<?print 0b111?>') 
    198     assert '7' == r(u'<?print 0B111?>') 
    199     assert '-7' == r(u'<?print -0b111?>') 
    200     assert '-7' == r(u'<?print -0B111?>') 
    201  
    202     assert 'no' == r(u'<?if 0?>yes<?else?>no<?end if?>') 
    203     assert 'yes' == r(u'<?if 1?>yes<?else?>no<?end if?>') 
    204     assert 'yes' == r(u'<?if -1?>yes<?else?>no<?end if?>') 
    205  
    206  
    207 @with_all_renderers 
    208 def test_float(r): 
    209     # str() output might differ slightly between Python and JS, so eval the output again for tests 
    210     assert 0.0 == eval(r(u'<?print 0.?>')) 
    211     assert 42.0 == eval(r(u'<?print 42.?>')) 
    212     assert -42.0 == eval(r(u'<?print -42.?>')) 
    213     assert -42.5 == eval(r(u'<?print -42.5?>')) 
    214     assert 1e42 == eval(r(u'<?print 1E42?>')) 
    215     assert 1e42 == eval(r(u'<?print 1e42?>')) 
    216     assert -1e42 == eval(r(u'<?print -1E42?>')) 
    217     assert -1e42 == eval(r(u'<?print -1e42?>')) 
    218  
    219     assert 'no' == r(u'<?if 0.?>yes<?else?>no<?end if?>') 
    220     assert 'yes' == r(u'<?if 1.?>yes<?else?>no<?end if?>') 
    221     assert 'yes' == r(u'<?if -1.?>yes<?else?>no<?end if?>') 
    222  
    223  
    224 @with_all_renderers 
    225 def test_string(r): 
    226     with raises("Unterminated string"): 
    227         r(u'<?print "?>') 
    228     assert 'foo' == r(u'<?print "foo"?>') 
    229     assert '\n' == r(u'<?print "\\n"?>') 
    230     assert '\r' == r(u'<?print "\\r"?>') 
    231     assert '\t' == r(u'<?print "\\t"?>') 
    232     assert '\f' == r(u'<?print "\\f"?>') 
    233     assert '\b' == r(u'<?print "\\b"?>') 
    234     assert '\a' == r(u'<?print "\\a"?>') 
    235     assert '\x1b' == r(u'<?print "\\e"?>') 
    236     assert '"' == r(u'<?print "\\""?>') 
    237     assert "'" == r(u'<?print "\\\'"?>') 
    238     assert u'\u20ac' == r(u'<?print "\u20ac"?>') 
    239     assert u'\xff' == r(u'<?print "\\xff"?>') 
    240     assert u'\u20ac' == r(u'''<?print "\\u20ac"?>''') 
    241     assert "a\nb" == r(u'<?print "a\nb"?>') 
    242  
    243     assert 'no' == r(u'<?if ""?>yes<?else?>no<?end if?>') 
    244     assert 'yes' == r(u'<?if "foo"?>yes<?else?>no<?end if?>') 
    245  
    246  
    247 @with_all_renderers 
    248 def test_date(r): 
    249     assert '2000-02-29' == r(u'<?print @2000-02-29T.isoformat()?>') 
    250     assert '2000-02-29T12:34:00' == r(u'<?print @2000-02-29T12:34.isoformat()?>') 
    251     assert '2000-02-29T12:34:56' == r(u'<?print @2000-02-29T12:34:56.isoformat()?>') 
    252     assert '2000-02-29T12:34:56.987000' == r(u'<?print @2000-02-29T12:34:56.987000.isoformat()?>') # JS and Java only supports milliseconds 
    253     assert 'yes' == r(u'<?if @2000-02-29T12:34:56.987654?>yes<?else?>no<?end if?>') 
    254  
    255  
    256 @with_all_renderers 
    257 def test_color(r): 
    258     assert '255,255,255,255' == r(u'<?code c = #fff?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
    259     assert '255,255,255,255' == r(u'<?code c = #ffffff?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
    260     assert '18,52,86,255' == r(u'<?code c = #123456?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
    261     assert '17,34,51,68' == r(u'<?code c = #1234?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
    262     assert '18,52,86,120' == r(u'<?code c = #12345678?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
    263     assert 'yes' == r(u'<?if #fff?>yes<?else?>no<?end if?>') 
    264  
    265  
    266 @with_all_renderers 
    267 def test_list(r): 
    268     assert '' == r(u'<?for item in []?><?print item?>;<?end for?>') 
    269     assert '1;' == r(u'<?for item in [1]?><?print item?>;<?end for?>') 
    270     assert '1;' == r(u'<?for item in [1,]?><?print item?>;<?end for?>') 
    271     assert '1;2;' == r(u'<?for item in [1, 2]?><?print item?>;<?end for?>') 
    272     assert '1;2;' == r(u'<?for item in [1, 2,]?><?print item?>;<?end for?>') 
    273     assert 'no' == r(u'<?if []?>yes<?else?>no<?end if?>') 
    274     assert 'yes' == r(u'<?if [1]?>yes<?else?>no<?end if?>') 
    275  
    276  
    277 @with_all_renderers 
    278 def test_dict(r): 
    279     assert '' == r(u'<?for (key, value) in {}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    280     assert '1:2\n' == r(u'<?for (key, value) in {1:2}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    281     assert '1:2\n' == r(u'<?for (key, value) in {1:2,}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    282     # With duplicate keys, later ones simply overwrite earlier ones 
    283     assert '1:3\n' == r(u'<?for (key, value) in {1:2, 1: 3}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    284     # Test ** 
    285     assert '1:2\n' == r(u'<?for (key, value) in {**{1:2}}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    286     assert '1:4\n' == r(u'<?for (key, value) in {1:1, **{1:2}, 1:3, **{1:4}}.items()?><?print key?>:<?print value?>\n<?end for?>') 
    287     assert 'no' == r(u'<?if {}?>yes<?else?>no<?end if?>') 
    288     assert 'yes' == r(u'<?if {1:2}?>yes<?else?>no<?end if?>') 
    289  
    290  
    291 @with_all_renderers 
    292 def test_code_storevar(r): 
    293     assert '42' == r(u'<?code x = 42?><?print x?>') 
    294     assert 'xyzzy' == r(u'<?code x = "xyzzy"?><?print x?>') 
    295  
    296  
    297 @with_all_renderers 
    298 def test_code_addvar(r): 
    299     assert '40' == r(u'<?code x = 17?><?code x += 23?><?print x?>') 
    300     assert 'xyzzy' == r(u'<?code x = "xyz"?><?code x += "zy"?><?print x?>') 
    301  
    302  
    303 @with_all_renderers 
    304 def test_code_subvar(r): 
    305     assert '-6' == r(u'<?code x = 17?><?code x -= 23?><?print x?>') 
    306  
    307  
    308 @with_all_renderers 
    309 def test_code_mulvar(r): 
    310     assert '391' == r(u'<?code x = 17?><?code x *= 23?><?print x?>') 
    311     assert 17*'xyzzy' == r(u'<?code x = 17?><?code x *= "xyzzy"?><?print x?>') 
    312     assert 17*'xyzzy' == r(u'<?code x = "xyzzy"?><?code x *= 17?><?print x?>') 
    313  
    314  
    315 @with_all_renderers 
    316 def test_code_floordivvar(r): 
    317     assert '2' == r(u'<?code x = 5?><?code x //= 2?><?print x?>') 
    318     assert '-3' == r(u'<?code x = -5?><?code x //= 2?><?print x?>') 
    319  
    320  
    321 @with_all_renderers 
    322 def test_code_truedivvar(r): 
    323     assert '2.5' == r(u'<?code x = 5?><?code x /= 2?><?print x?>') 
    324     assert '-2.5' == r(u'<?code x = -5?><?code x /= 2?><?print x?>') 
    325  
    326  
    327 @with_all_renderers 
    328 def test_code_modvar(r): 
    329     assert '4' == r(u'<?code x = 1729?><?code x %= 23?><?print x?>') 
    330  
    331  
    332 @with_all_renderers 
    333 def test_code_delvar(r): 
    334     with raises("(KeyError|not found)"): 
    335         r(u'<?code x = 1729?><?code del x?><?print x?>') 
    336  
    337  
    338 @with_all_renderers 
    339 def test_for_string(r): 
    340     assert '' == r(u'<?for c in data?>(<?print c?>)<?end for?>', data="") 
    341     assert '(g)(u)(r)(k)' == r(u'<?for c in data?>(<?print c?>)<?end for?>', data="gurk") 
    342  
    343  
    344 @with_all_renderers 
    345 def test_for_list(r): 
    346     assert '' == r(u'<?for c in data?>(<?print c?>)<?end for?>', data="") 
    347     assert '(g)(u)(r)(k)' == r(u'<?for c in data?>(<?print c?>)<?end for?>', data=["g", "u", "r", "k"]) 
    348  
    349  
    350 @with_all_renderers 
    351 def test_for_dict(r): 
    352     assert '' == r(u'<?for c in data?>(<?print c?>)<?end for?>', data={}) 
    353     assert '(a)(b)(c)' == r(u'<?for c in sorted(data)?>(<?print c?>)<?end for?>', data=dict(a=1, b=2, c=3)) 
    354  
    355  
    356 @with_all_renderers 
    357 def test_for_nested(r): 
    358     assert '[(1)(2)][(3)(4)]' == r(u'<?for list in data?>[<?for n in list?>(<?print n?>)<?end for?>]<?end for?>', data=[[1, 2], [3, 4]]) 
    359  
    360  
    361 @with_all_renderers 
    362 def test_for_unpacking(r): 
     180        render.renders() 
     181    except Exception, exc: 
     182        assert re.search(msg, "{0.__class__.__module__}.{0.__class__.__name__}: {0}".format(exc)) is not None 
     183    else: 
     184        py.test.fail("failed to raise exception") 
     185 
     186 
     187def test_text(): 
     188    for r in all_renderers: 
     189        yield eq, u'gurk', r(u'gurk') 
     190        yield eq, u'g\xfcrk', r(u'g\xfcrk') 
     191 
     192 
     193def test_none(): 
     194    for r in all_renderers: 
     195        yield eq, '', r(u'<?print None?>') 
     196        yield eq, 'no', r(u'<?if None?>yes<?else?>no<?end if?>') 
     197 
     198 
     199def test_false(): 
     200    for r in all_renderers: 
     201        yield eq, 'False', r(u'<?print False?>') 
     202        yield eq, 'no', r(u'<?if False?>yes<?else?>no<?end if?>') 
     203 
     204 
     205def test_true(): 
     206    for r in all_renderers: 
     207        yield eq, 'True', r(u'<?print True?>') 
     208        yield eq, 'yes', r(u'<?if True?>yes<?else?>no<?end if?>') 
     209 
     210 
     211def test_int(): 
     212    for r in all_renderers: 
     213        yield eq, '0', r(u'<?print 0?>') 
     214        yield eq, '42', r(u'<?print 42?>') 
     215        yield eq, '-42', r(u'<?print -42?>') 
     216        yield eq, '255', r(u'<?print 0xff?>') 
     217        yield eq, '255', r(u'<?print 0Xff?>') 
     218        yield eq, '-255', r(u'<?print -0xff?>') 
     219        yield eq, '-255', r(u'<?print -0Xff?>') 
     220        yield eq, '63', r(u'<?print 0o77?>') 
     221        yield eq, '63', r(u'<?print 0O77?>') 
     222        yield eq, '-63', r(u'<?print -0o77?>') 
     223        yield eq, '-63', r(u'<?print -0O77?>') 
     224        yield eq, '7', r(u'<?print 0b111?>') 
     225        yield eq, '7', r(u'<?print 0B111?>') 
     226        yield eq, '-7', r(u'<?print -0b111?>') 
     227        yield eq, '-7', r(u'<?print -0B111?>') 
     228 
     229        yield eq, 'no', r(u'<?if 0?>yes<?else?>no<?end if?>') 
     230        yield eq, 'yes', r(u'<?if 1?>yes<?else?>no<?end if?>') 
     231        yield eq, 'yes', r(u'<?if -1?>yes<?else?>no<?end if?>') 
     232 
     233 
     234def test_float(): 
     235    for r in all_renderers: 
     236        # str() output might differ slightly between Python and JS, so eval the output again for tests 
     237        yield evaleq, 0.0, r(u'<?print 0.?>') 
     238        yield evaleq, 42.0, r(u'<?print 42.?>') 
     239        yield evaleq, -42.0, r(u'<?print -42.?>') 
     240        yield evaleq, -42.5, r(u'<?print -42.5?>') 
     241        yield evaleq, 1e42, r(u'<?print 1E42?>') 
     242        yield evaleq, 1e42, r(u'<?print 1e42?>') 
     243        yield evaleq, -1e42, r(u'<?print -1E42?>') 
     244        yield evaleq, -1e42, r(u'<?print -1e42?>') 
     245 
     246        yield eq, 'no', r(u'<?if 0.?>yes<?else?>no<?end if?>') 
     247        yield eq, 'yes', r(u'<?if 1.?>yes<?else?>no<?end if?>') 
     248        yield eq, 'yes', r(u'<?if -1.?>yes<?else?>no<?end if?>') 
     249 
     250 
     251def test_string(): 
     252    for r in all_renderers: 
     253        with raises("Unterminated string"): 
     254            r(u'<?print "?>').renders() 
     255        yield eq, 'foo', r(u'<?print "foo"?>') 
     256        yield eq, '\n', r(u'<?print "\\n"?>') 
     257        yield eq, '\r', r(u'<?print "\\r"?>') 
     258        yield eq, '\t', r(u'<?print "\\t"?>') 
     259        yield eq, '\f', r(u'<?print "\\f"?>') 
     260        yield eq, '\b', r(u'<?print "\\b"?>') 
     261        yield eq, '\a', r(u'<?print "\\a"?>') 
     262        yield eq, '\x1b', r(u'<?print "\\e"?>') 
     263        yield eq, '"', r(u'<?print "\\""?>') 
     264        yield eq, "'", r(u'<?print "\\\'"?>') 
     265        yield eq, u'\u20ac', r(u'<?print "\u20ac"?>') 
     266        yield eq, u'\xff', r(u'<?print "\\xff"?>') 
     267        yield eq, u'\u20ac', r(u'''<?print "\\u20ac"?>''') 
     268        yield eq, "a\nb", r(u'<?print "a\nb"?>') 
     269 
     270        yield eq, 'no', r(u'<?if ""?>yes<?else?>no<?end if?>') 
     271        yield eq, 'yes', r(u'<?if "foo"?>yes<?else?>no<?end if?>') 
     272 
     273 
     274def test_date(): 
     275    for r in all_renderers: 
     276        yield eq, '2000-02-29', r(u'<?print @2000-02-29T.isoformat()?>') 
     277        yield eq, '2000-02-29T12:34:00', r(u'<?print @2000-02-29T12:34.isoformat()?>') 
     278        yield eq, '2000-02-29T12:34:56', r(u'<?print @2000-02-29T12:34:56.isoformat()?>') 
     279        yield eq, '2000-02-29T12:34:56.987000', r(u'<?print @2000-02-29T12:34:56.987000.isoformat()?>') # JS and Java only supports milliseconds 
     280        yield eq, 'yes', r(u'<?if @2000-02-29T12:34:56.987654?>yes<?else?>no<?end if?>') 
     281 
     282 
     283def test_color(): 
     284    for r in all_renderers: 
     285        yield eq, '255,255,255,255', r(u'<?code c = #fff?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
     286        yield eq, '255,255,255,255', r(u'<?code c = #ffffff?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
     287        yield eq, '18,52,86,255', r(u'<?code c = #123456?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
     288        yield eq, '17,34,51,68', r(u'<?code c = #1234?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
     289        yield eq, '18,52,86,120', r(u'<?code c = #12345678?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>') 
     290        yield eq, 'yes', r(u'<?if #fff?>yes<?else?>no<?end if?>') 
     291 
     292 
     293def test_list(): 
     294    for r in all_renderers: 
     295        yield eq, '', r(u'<?for item in []?><?print item?>;<?end for?>') 
     296        yield eq, '1;', r(u'<?for item in [1]?><?print item?>;<?end for?>') 
     297        yield eq, '1;', r(u'<?for item in [1,]?><?print item?>;<?end for?>') 
     298        yield eq, '1;2;', r(u'<?for item in [1, 2]?><?print item?>;<?end for?>') 
     299        yield eq, '1;2;', r(u'<?for item in [1, 2,]?><?print item?>;<?end for?>') 
     300        yield eq, 'no', r(u'<?if []?>yes<?else?>no<?end if?>') 
     301        yield eq, 'yes', r(u'<?if [1]?>yes<?else?>no<?end if?>') 
     302 
     303 
     304def test_dict(): 
     305    for r in all_renderers: 
     306        yield eq, '', r(u'<?for (key, value) in {}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     307        yield eq, '1:2\n', r(u'<?for (key, value) in {1:2}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     308        yield eq, '1:2\n', r(u'<?for (key, value) in {1:2,}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     309        # With duplicate keys, later ones simply overwrite earlier ones 
     310        yield eq, '1:3\n', r(u'<?for (key, value) in {1:2, 1: 3}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     311        # Test ** 
     312        yield eq, '1:2\n', r(u'<?for (key, value) in {**{1:2}}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     313        yield eq, '1:4\n', r(u'<?for (key, value) in {1:1, **{1:2}, 1:3, **{1:4}}.items()?><?print key?>:<?print value?>\n<?end for?>') 
     314        yield eq, 'no', r(u'<?if {}?>yes<?else?>no<?end if?>') 
     315        yield eq, 'yes', r(u'<?if {1:2}?>yes<?else?>no<?end if?>') 
     316 
     317 
     318def test_code_storevar(): 
     319    for r in all_renderers: 
     320        yield eq, '42', r(u'<?code x = 42?><?print x?>') 
     321        yield eq, 'xyzzy', r(u'<?code x = "xyzzy"?><?print x?>') 
     322 
     323 
     324def test_code_addvar(): 
     325    for r in all_renderers: 
     326        yield eq, '40', r(u'<?code x = 17?><?code x += 23?><?print x?>') 
     327        yield eq, 'xyzzy', r(u'<?code x = "xyz"?><?code x += "zy"?><?print x?>') 
     328 
     329 
     330def test_code_subvar(): 
     331    for r in all_renderers: 
     332        yield eq, '-6', r(u'<?code x = 17?><?code x -= 23?><?print x?>') 
     333 
     334 
     335def test_code_mulvar(): 
     336    for r in all_renderers: 
     337        yield eq, '391', r(u'<?code x = 17?><?code x *= 23?><?print x?>') 
     338        yield eq, 17*'xyzzy', r(u'<?code x = 17?><?code x *= "xyzzy"?><?print x?>') 
     339        yield eq, 17*'xyzzy', r(u'<?code x = "xyzzy"?><?code x *= 17?><?print x?>') 
     340 
     341 
     342def test_code_floordivvar(): 
     343    for r in all_renderers: 
     344        yield eq, '2', r(u'<?code x = 5?><?code x //= 2?><?print x?>') 
     345        yield eq, '-3', r(u'<?code x = -5?><?code x //= 2?><?print x?>') 
     346 
     347 
     348def test_code_truedivvar(): 
     349    for r in all_renderers: 
     350        yield eq, '2.5', r(u'<?code x = 5?><?code x /= 2?><?print x?>') 
     351        yield eq, '-2.5', r(u'<?code x = -5?><?code x /= 2?><?print x?>') 
     352 
     353 
     354def test_code_modvar(): 
     355    for r in all_renderers: 
     356        yield eq, '4', r(u'<?code x = 1729?><?code x %= 23?><?print x?>') 
     357 
     358 
     359def test_code_delvar(): 
     360    for r in all_renderers: 
     361        yield raises, "(KeyError|not found)", r(u'<?code x = 1729?><?code del x?><?print x?>') 
     362 
     363 
     364def test_for_string(): 
     365    for r in all_renderers: 
     366        yield eq, '', r(u'<?for c in data?>(<?print c?>)<?end for?>', data="") 
     367        yield eq, '(g)(u)(r)(k)', r(u'<?for c in data?>(<?print c?>)<?end for?>', data="gurk") 
     368 
     369 
     370def test_for_list(): 
     371    for r in all_renderers: 
     372        yield eq, '', r(u'<?for c in data?>(<?print c?>)<?end for?>', data="") 
     373        yield eq, '(g)(u)(r)(k)', r(u'<?for c in data?>(<?print c?>)<?end for?>', data=["g", "u", "r", "k"]) 
     374 
     375 
     376def test_for_dict(): 
     377    for r in all_renderers: 
     378        yield eq, '', r(u'<?for c in data?>(<?print c?>)<?end for?>', data={}) 
     379        yield eq, '(a)(b)(c)', r(u'<?for c in sorted(data)?>(<?print c?>)<?end for?>', data=dict(a=1, b=2, c=3)) 
     380 
     381 
     382def test_for_nested(): 
     383    for r in all_renderers: 
     384        yield eq, '[(1)(2)][(3)(4)]', r(u'<?for list in data?>[<?for n in list?>(<?print n?>)<?end for?>]<?end for?>', data=[[1, 2], [3, 4]]) 
     385 
     386 
     387def test_for_unpacking(): 
    363388    data = [ 
    364389        ("spam", "eggs", 17), 
     
    367392    ] 
    368393 
    369     assert '(spam)(gurk)(hinz)' == r(u'<?for (a,) in data?>(<?print a?>)<?end for?>', data=data) 
    370     assert '(spam,eggs)(gurk,hurz)(hinz,kunz)' == r(u'<?for (a, b) in data?>(<?print a?>,<?print b?>)<?end for?>', data=data) 
    371     assert '(spam,eggs,17)(gurk,hurz,23)(hinz,kunz,42)' == r(u'<?for (a, b, c) in data?>(<?print a?>,<?print b?>,<?print c?>)<?end for?>', data=data) 
    372  
    373  
    374 @with_all_renderers 
    375 def test_break(r): 
    376     assert '1, 2, ' == r(u'<?for i in [1,2,3]?><?print i?>, <?if i==2?><?break?><?end if?><?end for?>') 
    377  
    378  
    379 @with_all_renderers 
    380 def test_break_nested(r): 
    381     assert '1, 1, 2, 1, 2, 3, ' == r(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?>') 
    382  
    383  
    384 @with_all_renderers 
    385 def test_continue(r): 
    386     assert '1, 3, ' == r(u'<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?print i?>, <?end for?>') 
    387  
    388  
    389 @with_all_renderers 
    390 def test_continue_nested(r): 
    391     assert '1, 3, \n1, 3, \n' == r(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?>') 
    392  
    393  
    394 @with_all_renderers 
    395 def test_if(r): 
    396     assert '42' == r(u'<?if data?><?print data?><?end if?>', data=42) 
    397  
    398  
    399 @with_all_renderers 
    400 def test_else(r): 
    401     assert '42' == r(u'<?if data?><?print data?><?else?>no<?end if?>', data=42) 
    402     assert 'no' == r(u'<?if data?><?print data?><?else?>no<?end if?>', data=0) 
     394    for r in all_renderers: 
     395        yield eq, '(spam)(gurk)(hinz)', r(u'<?for (a,) in data?>(<?print a?>)<?end for?>', data=data) 
     396        yield eq, '(spam,eggs)(gurk,hurz)(hinz,kunz)', r(u'<?for (a, b) in data?>(<?print a?>,<?print b?>)<?end for?>', data=data) 
     397        yield eq, '(spam,eggs,17)(gurk,hurz,23)(hinz,kunz,42)', r(u'<?for (a, b, c) in data?>(<?print a?>,<?print b?>,<?print c?>)<?end for?>', data=data) 
     398 
     399 
     400def test_break(): 
     401    for r in all_renderers: 
     402        yield eq, '1, 2, ', r(u'<?for i in [1,2,3]?><?print i?>, <?if i==2?><?break?><?end if?><?end for?>') 
     403 
     404 
     405def test_break_nested(): 
     406    for r in all_renderers: 
     407        yield eq, '1, 1, 2, 1, 2, 3, ', r(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?>') 
     408 
     409 
     410def test_continue(): 
     411    for r in all_renderers: 
     412        yield eq, '1, 3, ', r(u'<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?print i?>, <?end for?>') 
     413 
     414 
     415def test_continue_nested(): 
     416    for r in all_renderers: 
     417        yield eq, '1, 3, \n1, 3, \n', r(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?>') 
     418 
     419 
     420def test_if(): 
     421    for r in all_renderers: 
     422        yield eq, '42', r(u'<?if data?><?print data?><?end if?>', data=42) 
     423 
     424 
     425def test_else(): 
     426    for r in all_renderers: 
     427        yield eq, '42', r(u'<?if data?><?print data?><?else?>no<?end if?>', data=42) 
     428        yield eq, 'no', r(u'<?if data?><?print data?><?else?>no<?end if?>', data=0) 
    403429 
    404430 
    405431def test_block_errors(): 
    406     with raises("in u?.<.for x in data.>..*block unclosed"): 
    407         render(u'<?for x in data?>') 
    408     with raises("endif doesn't match any if"): 
    409         render(u'<?for x in data?><?end if?>') 
    410     with raises("not in any block"): 
    411         render(u'<?end?>') 
    412     with raises("not in any block"): 
    413         render(u'<?end for?>') 
    414     with raises("not in any block"): 
    415         render(u'<?end if?>') 
    416     with raises("else doesn't match any if"): 
    417         render(u'<?else?>') 
    418     with raises("in u?.<.if data.>..*block unclosed"): 
    419         render(u'<?if data?>') 
    420     with raises("in u?.<.if data.>..*block unclosed"): 
    421         render(u'<?if data?><?else?>') 
    422     with raises("duplicate else"): 
    423         render(u'<?if data?><?else?><?else?>') 
    424     with raises("else already seen in elif"): 
    425         render(u'<?if data?><?else?><?elif data?>') 
    426     with raises("else already seen in elif"): 
    427         render(u'<?if data?><?elif data?><?elif data?><?else?><?elif data?>') 
     432    yield raises, "in u?.<.for x in data.>..*block unclosed", RenderPython(u'<?for x in data?>') 
     433    yield raises, "endif doesn't match any if", RenderPython(u'<?for x in data?><?end if?>') 
     434    yield raises, "not in any block", RenderPython(u'<?end?>') 
     435    yield raises, "not in any block", RenderPython(u'<?end for?>') 
     436    yield raises, "not in any block", RenderPython(u'<?end if?>') 
     437    yield raises, "else doesn't match any if", RenderPython(u'<?else?>') 
     438    yield raises, "in u?.<.if data.>..*block unclosed", RenderPython(u'<?if data?>') 
     439    yield raises, "in u?.<.if data.>..*block unclosed", RenderPython(u'<?if data?><?else?>') 
     440    yield raises, "duplicate else", RenderPython(u'<?if data?><?else?><?else?>') 
     441    yield raises, "else already seen in elif", RenderPython(u'<?if data?><?else?><?elif data?>') 
     442    yield raises, "else already seen in elif", RenderPython(u'<?if data?><?elif data?><?elif data?><?else?><?elif data?>') 
    428443 
    429444 
    430445def test_empty(): 
    431     with raises("expression required"): 
    432         render(u'<?print?>') 
    433     with raises("expression required"): 
    434         render(u'<?if?>') 
    435     with raises("expression required"): 
    436         render(u'<<?if x?><?elif?><?end if?>') 
    437     with raises("loop expression required"): 
    438         render(u'<?for?>') 
    439     with raises("statement required"): 
    440         render(u'<?code?>') 
    441     with raises("render statement required"): 
    442         render(u'<?render?>') 
    443  
    444  
    445 @with_all_renderers 
    446 def test_add(r): 
     446    yield raises, "expression required", RenderPython(u'<?print?>') 
     447    yield raises, "expression required", RenderPython(u'<?if?>') 
     448    yield raises, "expression required", RenderPython(u'<<?if x?><?elif?><?end if?>') 
     449    yield raises, "loop expression required", RenderPython(u'<?for?>') 
     450    yield raises, "statement required", RenderPython(u'<?code?>') 
     451    yield raises, "render statement required", RenderPython(u'<?render?>') 
     452 
     453 
     454def test_add(): 
    447455    values = (17, 23, 1., -1.) 
    448     for x in values: 
    449         for y in values: 
    450             assert x + y == eval(r(u'<?print x + y?>', x=x, y=y)) # Using ``eval`` avoid problem with the nonexistant int/float distinction in JS 
    451     assert 'foobar' == r(u'<?code x="foo"?><?code y="bar"?><?print x+y?>') 
    452     assert '(f)(o)(o)(b)(a)(r)' == r(u'<?for i in data.foo+data.bar?>(<?print i?>)<?end for?>', data=dict(foo="foo", bar="bar")) 
    453  
    454  
    455 @with_all_renderers 
    456 def test_sub(r): 
     456    for r in all_renderers: 
     457        for x in values: 
     458            for y in values: 
     459                yield evaleq, x + y, r(u'<?print x + y?>', x=x, y=y) # Using ``evaleq`` avoids problem with the nonexistant int/float distinction in JS 
     460        yield eq, 'foobar', r(u'<?code x="foo"?><?code y="bar"?><?print x+y?>') 
     461        yield eq, '(f)(o)(o)(b)(a)(r)', r(u'<?for i in data.foo+data.bar?>(<?print i?>)<?end for?>', data=dict(foo="foo", bar="bar")) 
     462 
     463 
     464def test_sub(): 
    457465    values = (17, 23, 1., -1.) 
    458     for x in values: 
    459         for y in values: 
    460             assert x - y == eval(r(u'<?print x - y?>', x=x, y=y)) 
    461  
    462  
    463 @with_all_renderers 
    464 def test_mul(r): 
     466    for r in all_renderers: 
     467        for x in values: 
     468            for y in values: 
     469                yield evaleq, x - y, r(u'<?print x - y?>', x=x, y=y) 
     470 
     471 
     472def test_mul(): 
    465473    values = (17, 23, 1., -1.) 
    466     for x in values: 
    467         for y in values: 
    468             assert x * y == eval(r(u'<?print x * y?>', x=x, y=y)) 
    469     assert 17*"foo" == r(u'<?print 17*"foo"?>') 
    470     assert 17*"foo" == r(u'<?code x=17?><?code y="foo"?><?print x*y?>') 
    471     assert "foo"*17 == r(u'<?code x="foo"?><?code y=17?><?print x*y?>') 
    472     assert "foo"*17 == r(u'<?print "foo"*17?>') 
    473     assert "(foo)(bar)(foo)(bar)(foo)(bar)" == r(u'<?for i in 3*data?>(<?print i?>)<?end for?>', data=["foo", "bar"]) 
    474  
    475  
    476 @with_all_renderers 
    477 def test_truediv(r): 
    478     assert "0.5" == r(u'<?print 1/2?>') 
    479     assert "0.5" == r(u'<?code x=1?><?code y=2?><?print x/y?>') 
    480  
    481  
    482 @with_all_renderers 
    483 def test_floordiv(r): 
    484     assert "0" == r(u'<?print 1//2?>') 
    485     assert "0" == r(u'<?code x=1?><?code y=2?><?print x//y?>') 
    486  
    487  
    488 @with_all_renderers 
    489 def test_mod(r): 
     474    for r in all_renderers: 
     475        for x in values: 
     476            for y in values: 
     477                yield evaleq, x * y, r(u'<?print x * y?>', x=x, y=y) 
     478        yield eq, 17*"foo", r(u'<?print 17*"foo"?>') 
     479        yield eq, 17*"foo", r(u'<?code x=17?><?code y="foo"?><?print x*y?>') 
     480        yield eq, "foo"*17, r(u'<?code x="foo"?><?code y=17?><?print x*y?>') 
     481        yield eq, "foo"*17, r(u'<?print "foo"*17?>') 
     482        yield eq, "(foo)(bar)(foo)(bar)(foo)(bar)", r(u'<?for i in 3*data?>(<?print i?>)<?end for?>', data=["foo", "bar"]) 
     483 
     484 
     485def test_truediv(): 
     486    for r in all_renderers: 
     487        yield eq, "0.5", r(u'<?print 1/2?>') 
     488        yield eq, "0.5", r(u'<?code x=1?><?code y=2?><?print x/y?>') 
     489 
     490 
     491def test_floordiv(): 
     492    for r in all_renderers: 
     493        yield eq, "0", r(u'<?print 1//2?>') 
     494        yield eq, "0", r(u'<?code x=1?><?code y=2?><?print x//y?>') 
     495 
     496 
     497def test_mod(): 
    490498    values = (17, 23, 17., 23.) 
    491     for x in values: 
    492         for y in values: 
    493             assert x % y == eval(r(u'<?print {} % {}?>'.format(x, y))) 
    494             assert x % y == eval(r(u'<?print x % y?>', x=x, y=y)) 
    495  
    496  
    497 @with_all_renderers 
    498 def test_eq(r): 
     499    for r in all_renderers: 
     500        for x in values: 
     501            for y in values: 
     502                yield evaleq, x % y, r(u'<?print {} % {}?>'.format(x, y)) 
     503                yield evaleq, x % y, r(u'<?print x % y?>', x=x, y=y) 
     504 
     505 
     506def test_eq(): 
    499507    values = (17, 23, 17., 23.) 
    500     for x in values: 
    501         for y in values: 
    502             assert str(x == y) == r(u'<?print {} == {}?>'.format(x, y)) 
    503             assert str(x == y) == r(u'<?print x == y?>', x=x, y=y) 
    504  
    505  
    506 @with_all_renderers 
    507 def test_ne(r): 
     508    for r in all_renderers: 
     509        for x in values: 
     510            for y in values: 
     511                yield eq, str(x == y), r(u'<?print {} == {}?>'.format(x, y)) 
     512                yield eq, str(x == y), r(u'<?print x == y?>', x=x, y=y) 
     513 
     514 
     515def test_ne(): 
    508516    values = (17, 23, 17., 23.) 
    509     for x in values: 
    510         for y in values: 
    511             assert str(x != y) == r(u'<?print {} != {}?>'.format(x, y)) 
    512             assert str(x != y) == r(u'<?print x != y?>', x=x, y=y) 
    513  
    514  
    515 @with_all_renderers 
    516 def test_lt(r): 
     517    for r in all_renderers: 
     518        for x in values: 
     519            for y in values: 
     520                yield eq, str(x != y), r(u'<?print {} != {}?>'.format(x, y)) 
     521                yield eq, str(x != y), r(u'<?print x != y?>', x=x, y=y) 
     522 
     523 
     524def test_lt(): 
    517525    values = (17, 23, 17., 23.) 
    518     for x in values: 
    519         for y in values: 
    520             assert str(x < y) == r(u'<?print {} < {}?>'.format(x, y)) 
    521             assert str(x < y) == r(u'<?print x < y?>', x=x, y=y) 
    522  
    523  
    524 @with_all_renderers 
    525 def test_le(r): 
     526    for r in all_renderers: 
     527        for x in values: 
     528            for y in values: 
     529                yield eq, str(x < y), r(u'<?print {} < {}?>'.format(x, y)) 
     530                yield eq, str(x < y), r(u'<?print x < y?>', x=x, y=y) 
     531 
     532 
     533def test_le(): 
    526534    values = (17, 23, 17., 23.) 
    527     for x in values: 
    528         for y in values: 
    529             assert str(x <= y) == r(u'<?print {} <= {}?>'.format(x, y)) 
    530             assert str(x <= y) == r(u'<?print x <= y?>', x=x, y=y) 
    531  
    532  
    533 @with_all_renderers 
    534 def test_gt(r): 
     535    for r in all_renderers: 
     536        for x in values: 
     537            for y in values: 
     538                yield eq, str(x <= y), r(u'<?print {} <= {}?>'.format(x, y)) 
     539                yield eq, str(x <= y), r(u'<?print x <= y?>', x=x, y=y) 
     540 
     541 
     542def test_gt(): 
    535543    values = (17, 23, 17., 23.) 
    536     for x in values: 
    537         for y in values: 
    538             assert str(x > y) == r(u'<?print {} > {}?>'.format(x, y)) 
    539             assert str(x > y) == r(u'<?print x > y?>', x=x, y=y) 
    540  
    541  
    542 @with_all_renderers 
    543 def test_ge(r): 
     544    for r in all_renderers: 
     545        for x in values: 
     546            for y in values: 
     547                yield eq, str(x > y), r(u'<?print {} > {}?>'.format(x, y)) 
     548                yield eq, str(x > y), r(u'<?print x > y?>', x=x, y=y) 
     549 
     550 
     551def test_ge(): 
    544552    values = (17, 23, 17., 23.) 
    545     for x in values: 
    546         for y in values: 
    547             assert str(x >= y) == r(u'<?print {} >= {}?>'.format(x, y)) 
    548             assert str(x >= y) == r(u'<?print x >= y?>', x=x, y=y) 
    549  
    550  
    551 @with_all_renderers 
    552 def test_contains(r): 
     553    for r in all_renderers: 
     554        for x in values: 
     555            for y in values: 
     556                yield eq, str(x >= y), r(u'<?print {} >= {}?>'.format(x, y)) 
     557                yield eq, str(x >= y), r(u'<?print x >= y?>', x=x, y=y) 
     558 
     559 
     560def test_contains(): 
    553561    code = u'<?print x in y?>' 
    554562 
    555     assert "True" == r(code, x=2, y=[1, 2, 3]) 
    556     assert "False" == r(code, x=4, y=[1, 2, 3]) 
    557     assert "True" == r(code, x="ur", y="gurk") 
    558     assert "False" == r(code, x="un", y="gurk") 
    559     assert "True" == r(code, x="a", y={"a": 1, "b": 2}) 
    560     assert "False" == r(code, x="c", y={"a": 1, "b": 2}) 
    561     assert "True" == r(code, x=0xff, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
    562     assert "False" == r(code, x=0x23, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
    563  
    564  
    565 @with_all_renderers 
    566 def test_notcontains(r): 
     563    for r in all_renderers: 
     564        yield eq, "True", r(code, x=2, y=[1, 2, 3]) 
     565        yield eq, "False", r(code, x=4, y=[1, 2, 3]) 
     566        yield eq, "True", r(code, x="ur", y="gurk") 
     567        yield eq, "False", r(code, x="un", y="gurk") 
     568        yield eq, "True", r(code, x="a", y={"a": 1, "b": 2}) 
     569        yield eq, "False", r(code, x="c", y={"a": 1, "b": 2}) 
     570        yield eq, "True", r(code, x=0xff, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
     571        yield eq, "False", r(code, x=0x23, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
     572 
     573 
     574def test_notcontains(): 
    567575    code = u'<?print x not in y?>' 
    568576 
    569     assert "False" == r(code, x=2, y=[1, 2, 3]) 
    570     assert "True" == r(code, x=4, y=[1, 2, 3]) 
    571     assert "False" == r(code, x="ur", y="gurk") 
    572     assert "True" == r(code, x="un", y="gurk") 
    573     assert "False" == r(code, x="a", y={"a": 1, "b": 2}) 
    574     assert "True" == r(code, x="c", y={"a": 1, "b": 2}) 
    575     assert "False" == r(code, x=0xff, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
    576     assert "True" == r(code, x=0x23, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
    577  
    578  
    579 @with_all_renderers 
    580 def test_and(r): 
    581     assert "False" == r(u'<?print x and y?>', x=False, y=False) 
    582     assert "False" == r(u'<?print x and y?>', x=False, y=True) 
    583     assert "0" == r(u'<?print x and y?>', x=0, y=True) 
    584  
    585  
    586 @with_all_renderers 
    587 def test_or(r): 
    588     assert "False" == r(u'<?print x or y?>', x=False, y=False) 
    589     assert "True" == r(u'<?print x or y?>', x=False, y=True) 
    590     assert "42" == r(u'<?print x or y?>', x=42, y=True) 
    591  
    592  
    593 @with_all_renderers 
    594 def test_not(r): 
    595     assert "True" == r(u'<?print not x?>', x=False) 
    596     assert "False" == r(u'<?print not x?>', x=42) 
    597  
    598  
    599 @with_all_renderers 
    600 def test_getitem(r): 
    601     assert "u" == r(u"<?print 'gurk'[1]?>") 
    602     assert "u" == r(u"<?print x[1]?>", x="gurk") 
    603     assert "u" == r(u"<?print 'gurk'[-3]?>") 
    604     assert "u" == r(u"<?print x[-3]?>", x="gurk") 
    605     with raises("IndexError"): 
    606         r(u"<?print 'gurk'[4]?>") 
    607     with raises("index (4 )?out of range"): 
    608         r(u"<?print x[4]?>", x="gurk") 
    609     with raises("IndexError"): 
    610         r(u"<?print 'gurk'[-5]?>") 
    611     with raises("index (-5 )?out of range"): 
    612         r(u"<?print x[-5]?>", x="gurk") 
    613  
    614  
    615 @with_all_renderers 
    616 def test_getslice12(r): 
    617     assert "ur" == r(u"<?print 'gurk'[1:3]?>") 
    618     assert "ur" == r(u"<?print x[1:3]?>", x="gurk") 
    619     assert "ur" == r(u"<?print 'gurk'[-3:-1]?>") 
    620     assert "ur" == r(u"<?print x[-3:-1]?>", x="gurk") 
    621     assert "" == r(u"<?print 'gurk'[4:10]?>") 
    622     assert "" == r(u"<?print x[4:10]?>", x="gurk") 
    623     assert "" == r(u"<?print 'gurk'[-10:-5]?>") 
    624     assert "" == r(u"<?print x[-10:-5]?>", x="gurk") 
    625  
    626  
    627 @with_all_renderers 
    628 def test_getslice1(r): 
    629     assert "urk" == r(u"<?print 'gurk'[1:]?>") 
    630     assert "urk" == r(u"<?print x[1:]?>", x="gurk") 
    631     assert "urk" == r(u"<?print 'gurk'[-3:]?>") 
    632     assert "urk" == r(u"<?print x[-3:]?>", x="gurk") 
    633     assert "" == r(u"<?print 'gurk'[4:]?>") 
    634     assert "" == r(u"<?print x[4:]?>", x="gurk") 
    635     assert "gurk" == r(u"<?print 'gurk'[-10:]?>") 
    636     assert "gurk" == r(u"<?print x[-10:]?>", x="gurk") 
    637  
    638  
    639 @with_all_renderers 
    640 def test_getslice2(r): 
    641     assert "gur" == r(u"<?print 'gurk'[:3]?>") 
    642     assert "gur" == r(u"<?print x[:3]?>", x="gurk") 
    643     assert "gur" == r(u"<?print 'gurk'[:-1]?>") 
    644     assert "gur" == r(u"<?print x[:-1]?>", x="gurk") 
    645     assert "gurk" == r(u"<?print 'gurk'[:10]?>") 
    646     assert "gurk" == r(u"<?print x[:10]?>", x="gurk") 
    647     assert "" == r(u"<?print 'gurk'[:-5]?>") 
    648     assert "" == r(u"<?print x[:-5]?>", x="gurk") 
    649  
    650  
    651 @with_all_renderers 
    652 def test_nested(r): 
     577    for r in all_renderers: 
     578        yield eq, "False", r(code, x=2, y=[1, 2, 3]) 
     579        yield eq, "True", r(code, x=4, y=[1, 2, 3]) 
     580        yield eq, "False", r(code, x="ur", y="gurk") 
     581        yield eq, "True", r(code, x="un", y="gurk") 
     582        yield eq, "False", r(code, x="a", y={"a": 1, "b": 2}) 
     583        yield eq, "True", r(code, x="c", y={"a": 1, "b": 2}) 
     584        yield eq, "False", r(code, x=0xff, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
     585        yield eq, "True", r(code, x=0x23, y=color.Color(0x00, 0x80, 0xff, 0x42)) 
     586 
     587 
     588def test_and(): 
     589    for r in all_renderers: 
     590        yield eq, "False", r(u'<?print x and y?>', x=False, y=False) 
     591        yield eq, "False", r(u'<?print x and y?>', x=False, y=True) 
     592        yield eq, "0", r(u'<?print x and y?>', x=0, y=True) 
     593 
     594 
     595def test_or(): 
     596    for r in all_renderers: 
     597        yield eq, "False", r(u'<?print x or y?>', x=False, y=False) 
     598        yield eq, "True", r(u'<?print x or y?>', x=False, y=True) 
     599        yield eq, "42", r(u'<?print x or y?>', x=42, y=True) 
     600 
     601 
     602def test_not(): 
     603    for r in all_renderers: 
     604        yield eq, "True", r(u'<?print not x?>', x=False) 
     605        yield eq, "False", r(u'<?print not x?>', x=42) 
     606 
     607 
     608def test_getitem(): 
     609    for r in all_renderers: 
     610        yield eq, "u", r(u"<?print 'gurk'[1]?>") 
     611        yield eq, "u", r(u"<?print x[1]?>", x="gurk") 
     612        yield eq, "u", r(u"<?print 'gurk'[-3]?>") 
     613        yield eq, "u", r(u"<?print x[-3]?>", x="gurk") 
     614        yield raises, "IndexError", r(u"<?print 'gurk'[4]?>") 
     615        yield raises, "index (4 )?out of range", r(u"<?print x[4]?>", x="gurk") 
     616        yield raises, "IndexError", r(u"<?print 'gurk'[-5]?>") 
     617        yield raises, "index (-5 )?out of range", r(u"<?print x[-5]?>", x="gurk") 
     618 
     619 
     620def test_getslice12(): 
     621    for r in all_renderers: 
     622        yield eq, "ur", r(u"<?print 'gurk'[1:3]?>") 
     623        yield eq, "ur", r(u"<?print x[1:3]?>", x="gurk") 
     624        yield eq, "ur", r(u"<?print 'gurk'[-3:-1]?>") 
     625        yield eq, "ur", r(u"<?print x[-3:-1]?>", x="gurk") 
     626        yield eq, "", r(u"<?print 'gurk'[4:10]?>") 
     627        yield eq, "", r(u"<?print x[4:10]?>", x="gurk") 
     628        yield eq, "", r(u"<?print 'gurk'[-10:-5]?>") 
     629        yield eq, "", r(u"<?print x[-10:-5]?>", x="gurk") 
     630 
     631 
     632def test_getslice1(): 
     633    for r in all_renderers: 
     634        yield eq, "urk", r(u"<?print 'gurk'[1:]?>") 
     635        yield eq, "urk", r(u"<?print x[1:]?>", x="gurk") 
     636        yield eq, "urk", r(u"<?print 'gurk'[-3:]?>") 
     637        yield eq, "urk", r(u"<?print x[-3:]?>", x="gurk") 
     638        yield eq, "", r(u"<?print 'gurk'[4:]?>") 
     639        yield eq, "", r(u"<?print x[4:]?>", x="gurk") 
     640        yield eq, "gurk", r(u"<?print 'gurk'[-10:]?>") 
     641        yield eq, "gurk", r(u"<?print x[-10:]?>", x="gurk") 
     642 
     643 
     644def test_getslice2(): 
     645    for r in all_renderers: 
     646        yield eq, "gur", r(u"<?print 'gurk'[:3]?>") 
     647        yield eq, "gur", r(u"<?print x[:3]?>", x="gurk") 
     648        yield eq, "gur", r(u"<?print 'gurk'[:-1]?>") 
     649        yield eq, "gur", r(u"<?print x[:-1]?>", x="gurk") 
     650        yield eq, "gurk", r(u"<?print 'gurk'[:10]?>") 
     651        yield eq, "gurk", r(u"<?print x[:10]?>", x="gurk") 
     652        yield eq, "", r(u"<?print 'gurk'[:-5]?>") 
     653        yield eq, "", r(u"<?print x[:-5]?>", x="gurk") 
     654 
     655 
     656def test_nested(): 
    653657    sc = u"4" 
    654658    sv = u"x" 
     
    659663        n = n + n 
    660664 
    661     assert str(n) == r(u'<?print {}?>'.format(sc)) 
    662     assert str(n) == r(u'<?code x=4?><?print {}?>'.format(sv)) 
    663  
    664  
    665 @with_all_renderers 
    666 def test_precedence(r): 
    667     assert "14" == r(u'<?print 2+3*4?>') 
    668     assert "20" == r(u'<?print (2+3)*4?>') 
    669     assert "10" == r(u'<?print -2+-3*-4?>') 
    670     assert "14" == r(u'<?print --2+--3*--4?>') 
    671     assert "14" == r(u'<?print (-(-2))+(-((-3)*-(-4)))?>') 
    672     assert "42" == r(u'<?print 2*data.value?>', data=dict(value=21)) 
    673     assert "42" == r(u'<?print data.value[0]?>', data=dict(value=[42])) 
    674     assert "42" == r(u'<?print data[0].value?>', data=[dict(value=42)]) 
    675     assert "42" == r(u'<?print data[0][0][0]?>', data=[[[42]]]) 
    676     assert "42" == r(u'<?print data.value.value[0]?>', data=dict(value=dict(value=[42]))) 
    677     assert "42" == r(u'<?print data.value.value[0].value.value[0]?>', data=dict(value=dict(value=[dict(value=dict(value=[42]))]))) 
    678  
    679  
    680 @with_all_renderers 
    681 def test_bracket(r): 
     665    for r in all_renderers: 
     666        yield eq, str(n), r(u'<?print {}?>'.format(sc)) 
     667        yield eq, str(n), r(u'<?code x=4?><?print {}?>'.format(sv)) 
     668 
     669 
     670def test_precedence(): 
     671    for r in all_renderers: 
     672        yield eq, "14", r(u'<?print 2+3*4?>') 
     673        yield eq, "20", r(u'<?print (2+3)*4?>') 
     674        yield eq, "10", r(u'<?print -2+-3*-4?>') 
     675        yield eq, "14", r(u'<?print --2+--3*--4?>') 
     676        yield eq, "14", r(u'<?print (-(-2))+(-((-3)*-(-4)))?>') 
     677        yield eq, "42", r(u'<?print 2*data.value?>', data=dict(value=21)) 
     678        yield eq, "42", r(u'<?print data.value[0]?>', data=dict(value=[42])) 
     679        yield eq, "42", r(u'<?print data[0].value?>', data=[dict(value=42)]) 
     680        yield eq, "42", r(u'<?print data[0][0][0]?>', data=[[[42]]]) 
     681        yield eq, "42", r(u'<?print data.value.value[0]?>', data=dict(value=dict(value=[42]))) 
     682        yield eq, "42", r(u'<?print data.value.value[0].value.value[0]?>', data=dict(value=dict(value=[dict(value=dict(value=[42]))]))) 
     683 
     684 
     685def test_bracket(): 
    682686    sc = u"4" 
    683687    sv = u"x" 
     
    686690        sv = u"({})".format(sv) 
    687691 
    688     assert "4" == r(u'<?print {}?>'.format(sc)) 
    689     assert "4" == r(u'<?code x=4?><?print {}?>'.format(sv)) 
    690  
    691  
    692 @with_all_renderers 
    693 def test_function_now(r): 
     692    for r in all_renderers: 
     693        yield eq, "4", r(u'<?print {}?>'.format(sc)) 
     694        yield eq, "4", r(u'<?code x=4?><?print {}?>'.format(sv)) 
     695 
     696 
     697def test_function_now(): 
    694698    now = unicode(datetime.datetime.now()) 
    695699 
    696     with raises("now.*unknown"): 
    697         r(u"<?print now(1)?>") 
    698     with raises("now.*unknown"): 
    699         r(u"<?print now(1, 2)?>") 
    700     assert now <= r(u"<?print now()?>") 
    701  
    702  
    703 @with_all_renderers 
    704 def test_function_utcnow(r): 
     700    for r in all_renderers: 
     701        yield raises, "now.*unknown", r(u"<?print now(1)?>") 
     702        yield raises, "now.*unknown", r(u"<?print now(1, 2)?>") 
     703        yield le, now, r(u"<?print now()?>") 
     704 
     705 
     706def test_function_utcnow(): 
    705707    utcnow = unicode(datetime.datetime.utcnow()) 
    706708 
    707     with raises("utcnow.*unknown"): 
    708         r(u"<?print utcnow(1)?>") 
    709     with raises("utcnow.*unknown"): 
    710         r(u"<?print utcnow(1, 2)?>") 
    711     utcnowfromtemplate = r(u"<?print utcnow()?>") 
    712     # JS and Java only have milliseconds precision, but this shouldn't lead to problems here, as rendering the template takes longer than a millisecond 
    713     assert utcnow <= utcnowfromtemplate 
    714  
    715  
    716 @with_all_renderers 
    717 def test_function_vars(r): 
     709    for r in all_renderers: 
     710        yield raises, "utcnow.*unknown", r(u"<?print utcnow(1)?>") 
     711        yield raises, "utcnow.*unknown", r(u"<?print utcnow(1, 2)?>") 
     712        utcnowfromtemplate = r(u"<?print utcnow()?>") 
     713        # JS and Java only have milliseconds precision, but this shouldn't lead to problems here, as rendering the template takes longer than a millisecond 
     714        yield le, utcnow, utcnowfromtemplate 
     715 
     716 
     717def test_function_vars(): 
    718718    code = u"<?if var in vars()?>yes<?else?>no<?end if?>" 
    719719 
    720     with raises("vars.*unknown"): 
    721         r("<?print vars(1)?>") 
    722     with raises("vars.*unknown"): 
    723         r("<?print vars(1, 2)?>") 
    724     assert "yes" == r(code, var="spam", spam="eggs") 
    725     assert "no" == r(code, var="nospam", spam="eggs") 
    726  
    727  
    728 @with_all_renderers 
    729 def test_function_random(r): 
    730     with raises("random.*unknown"): 
    731         r("<?print random(1)?>") 
    732     with raises("random.*unknown"): 
    733         r("<?print random(1, 2)?>") 
    734     assert "ok" == r(u"<?code r = random()?><?if r>=0 and r<1?>ok<?else?>fail<?end if?>") 
    735  
    736  
    737 @with_all_renderers 
    738 def test_function_randrange(r): 
    739     with raises("randrange.*unknown"): 
    740         r("<?print randrange()?>") 
    741     assert "ok" == r(u"<?code r = randrange(4)?><?if r>=0 and r<4?>ok<?else?>fail<?end if?>") 
    742     assert "ok" == r(u"<?code r = randrange(17, 23)?><?if r>=17 and r<23?>ok<?else?>fail<?end if?>") 
    743     assert "ok" == r(u"<?code r = randrange(17, 23, 2)?><?if r>=17 and r<23 and r%2?>ok<?else?>fail<?end if?>") 
    744  
    745  
    746 @with_all_renderers 
    747 def test_function_randchoice(r): 
    748     with raises("randchoice.*unknown"): 
    749         r("<?print randchoice()?>") 
    750     assert "ok" == r(u"<?code r = randchoice('abc')?><?if r in 'abc'?>ok<?else?>fail<?end if?>") 
    751     assert "ok" == r(u"<?code s = [17, 23, 42]?><?code r = randchoice(s)?><?if r in s?>ok<?else?>fail<?end if?>") 
    752     assert "ok" == r(u"<?code s = #12345678?><?code sl = [0x12, 0x34, 0x56, 0x78]?><?code r = randchoice(s)?><?if r in sl?>ok<?else?>fail<?end if?>") 
    753  
    754  
    755 @with_all_renderers 
    756 def test_function_xmlescape(r): 
    757     with raises("xmlescape.*unknown"): 
    758         r(u"<?print xmlescape()?>") 
    759     with raises("xmlescape.*unknown"): 
    760         r(u"<?print xmlescape(1, 2)?>") 
    761     assert "&lt;&lt;&gt;&gt;&amp;&#39;&quot;gurk" == r(u"<?print xmlescape(data)?>", data='<<>>&\'"gurk') 
    762  
    763  
    764 @with_all_renderers 
    765 def test_function_csv(r): 
    766     with raises("csv.*unknown"): 
    767         r(u"<?print csv()?>") 
    768     with raises("csv.*unknown"): 
    769         r(u"<?print csv(1, 2)?>") 
    770     assert "" == r(u"<?print csv(data)?>", data=None) 
    771     assert "False" == r(u"<?print csv(data)?>", data=False) 
    772     assert "True" == r(u"<?print csv(data)?>", data=True) 
    773     assert "42" == r(u"<?print csv(data)?>", data=42) 
    774     # no check for float 
    775     assert "abc" == r(u"<?print csv(data)?>", data="abc") 
    776     assert '"a,b,c"' == r(u"<?print csv(data)?>", data="a,b,c") 
    777     assert '"a""b""c"' == r(u"<?print csv(data)?>", data='a"b"c') 
    778     assert '"a\nb\nc"' == r(u"<?print csv(data)?>", data="a\nb\nc") 
    779  
    780  
    781 @with_all_renderers 
    782 def test_function_json(r): 
    783     with raises("json.*unknown"): 
    784         r(u"<?print json()?>") 
    785     with raises("json.*unknown"): 
    786         r(u"<?print json(1, 2)?>") 
    787     assert "null" == r(u"<?print json(data)?>", data=None) 
    788     assert "false" == r(u"<?print json(data)?>", data=False) 
    789     assert "true" == r(u"<?print json(data)?>", data=True) 
    790     assert "42" == r(u"<?print json(data)?>", data=42) 
    791     # no check for float 
    792     assert '"abc"' == r(u"<?print json(data)?>", data="abc") 
    793     assert '[1, 2, 3]', r(u"<?print json(data)?>", data=[1, 2, 3]) 
    794     assert '[1, 2, 3]', r(u"<?print json(data)?>", data=PseudoList([1, 2, 3])) 
    795     assert '{"one": 1}' == r(u"<?print json(data)?>", data={"one": 1}) 
    796     assert '{"one": 1}' == r(u"<?print json(data)?>", data=PseudoDict({"one": 1})) 
    797  
    798  
    799 @with_all_renderers 
    800 def test_function_str(r): 
    801     with raises("str.*unknown"): 
    802         r(u"<?print str()?>") 
    803     with raises("str.*unknown"): 
    804         r(u"<?print str(1, 2)?>") 
     720    for r in all_renderers: 
     721        yield raises, "vars.*unknown", r("<?print vars(1)?>") 
     722        yield raises, "vars.*unknown", r("<?print vars(1, 2)?>") 
     723        yield eq, "yes", r(code, var="spam", spam="eggs") 
     724        yield eq, "no", r(code, var="nospam", spam="eggs") 
     725 
     726 
     727def test_function_random(): 
     728    for r in all_renderers: 
     729        yield raises, "random.*unknown", r("<?print random(1)?>") 
     730        yield raises, "random.*unknown", r("<?print random(1, 2)?>") 
     731        yield eq, "ok", r(u"<?code r = random()?><?if r>=0 and r<1?>ok<?else?>fail<?end if?>") 
     732 
     733 
     734def test_function_randrange(): 
     735    for r in all_renderers: 
     736        yield raises, "randrange.*unknown", r("<?print randrange()?>") 
     737        yield eq, "ok", r(u"<?code r = randrange(4)?><?if r>=0 and r<4?>ok<?else?>fail<?end if?>") 
     738        yield eq, "ok", r(u"<?code r = randrange(17, 23)?><?if r>=17 and r<23?>ok<?else?>fail<?end if?>") 
     739        yield eq, "ok", r(u"<?code r = randrange(17, 23, 2)?><?if r>=17 and r<23 and r%2?>ok<?else?>fail<?end if?>") 
     740 
     741 
     742def test_function_randchoice(): 
     743    for r in all_renderers: 
     744        yield raises, "randchoice.*unknown", r("<?print randchoice()?>") 
     745        yield eq, "ok", r(u"<?code r = randchoice('abc')?><?if r in 'abc'?>ok<?else?>fail<?end if?>") 
     746        yield eq, "ok", r(u"<?code s = [17, 23, 42]?><?code r = randchoice(s)?><?if r in s?>ok<?else?>fail<?end if?>") 
     747        yield eq, "ok", r(u"<?code s = #12345678?><?code sl = [0x12, 0x34, 0x56, 0x78]?><?code r = randchoice(s)?><?if r in sl?>ok<?else?>fail<?end if?>") 
     748 
     749 
     750def test_function_xmlescape(): 
     751    for r in all_renderers: 
     752        yield raises, "xmlescape.*unknown", r(u"<?print xmlescape()?>") 
     753        yield raises, "xmlescape.*unknown", r(u"<?print xmlescape(1, 2)?>") 
     754        yield eq, "&lt;&lt;&gt;&gt;&amp;&#39;&quot;gurk", r(u"<?print xmlescape(data)?>", data='<<>>&\'"gurk') 
     755 
     756 
     757def test_function_csv(): 
     758    for r in all_renderers: 
     759        yield raises, "csv.*unknown", r(u"<?print csv()?>") 
     760        yield raises, "csv.*unknown", r(u"<?print csv(1, 2)?>") 
     761        yield eq, "", r(u"<?print csv(data)?>", data=None) 
     762        yield eq, "False", r(u"<?print csv(data)?>", data=False) 
     763        yield eq, "True", r(u"<?print csv(data)?>", data=True) 
     764        yield eq, "42", r(u"<?print csv(data)?>", data=42) 
     765        # no check for float 
     766        yield eq, "abc", r(u"<?print csv(data)?>", data="abc") 
     767        yield eq, '"a,b,c"', r(u"<?print csv(data)?>", data="a,b,c") 
     768        yield eq, '"a""b""c"', r(u"<?print csv(data)?>", data='a"b"c') 
     769        yield eq, '"a\nb\nc"', r(u"<?print csv(data)?>", data="a\nb\nc") 
     770 
     771 
     772def test_function_json(): 
     773    for r in all_renderers: 
     774        yield raises, "json.*unknown", r(u"<?print json()?>") 
     775        yield raises, "json.*unknown", r(u"<?print json(1, 2)?>") 
     776        yield eq, "null", r(u"<?print json(data)?>", data=None) 
     777        yield eq, "false", r(u"<?print json(data)?>", data=False) 
     778        yield eq, "true", r(u"<?print json(data)?>", data=True) 
     779        yield eq, "42", r(u"<?print json(data)?>", data=42) 
     780        # no check for float 
     781        yield eq, '"abc"', r(u"<?print json(data)?>", data="abc") 
     782        yield eq, '[1, 2, 3]', r(u"<?print json(data)?>", data=[1, 2, 3]) 
     783        yield eq, '[1, 2, 3]', r(u"<?print json(data)?>", data=PseudoList([1, 2, 3])) 
     784        yield eq, '{"one": 1}', r(u"<?print json(data)?>", data={"one": 1}) 
     785        yield eq, '{"one": 1}', r(u"<?print json(data)?>", data=PseudoDict({"one": 1})) 
     786 
     787 
     788def test_function_str(): 
    805789    code = u"<?print str(data)?>" 
    806     assert "" == r(code, data=None) 
    807     assert "True" == r(code, data=True) 
    808     assert "False" == r(code, data=False) 
    809     assert "42" == r(code, data=42) 
    810     assert "4.2" == r(code, data=4.2) 
    811     assert "foo" == r(code, data="foo") 
    812     assert "2011-02-09" == r(code, data=datetime.date(2011, 2, 9)) 
    813     assert "2011-02-09 12:34:56" == r(code, data=datetime.datetime(2011, 2, 9, 12, 34, 56)) 
    814     assert "2011-02-09 12:34:56.987000" == r(code, data=datetime.datetime(2011, 2, 9, 12, 34, 56, 987000)) 
    815  
    816  
    817 @with_all_renderers 
    818 def test_function_int(r): 
    819     with raises("int.*unknown"): 
    820         r(u"<?print int()?>") 
    821     with raises("int.*unknown"): 
    822         r(u"<?print int(1, 2, 3)?>") 
    823     with raises("int\\(\\) argument must be a string or a number|int\\(null\\) not supported"): 
    824         r(u"<?print int(data)?>", data=None) 
    825     with raises("invalid literal for int|NumberFormatException"): 
    826         r(u"<?print int(data)?>", data="foo") 
    827     assert "1" == r(u"<?print int(data)?>", data=True) 
    828     assert "0" == r(u"<?print int(data)?>", data=False) 
    829     assert "42" == r(u"<?print int(data)?>", data=42) 
    830     assert "4" == r(u"<?print int(data)?>", data=4.2) 
    831     assert "42" == r(u"<?print int(data)?>", data="42") 
    832     assert "66" == r(u"<?print int(data, 16)?>", data="42") 
    833  
    834  
    835 @with_all_renderers 
    836 def test_function_float(r): 
     790    for r in all_renderers: 
     791        yield raises, "str.*unknown", r(u"<?print str()?>") 
     792        yield raises, "str.*unknown", r(u"<?print str(1, 2)?>") 
     793        yield eq, "", r(code, data=None) 
     794        yield eq, "True", r(code, data=True) 
     795        yield eq, "False", r(code, data=False) 
     796        yield eq, "42", r(code, data=42) 
     797        yield eq, "4.2", r(code, data=4.2) 
     798        yield eq, "foo", r(code, data="foo") 
     799        yield eq, "2011-02-09", r(code, data=datetime.date(2011, 2, 9)) 
     800        yield eq, "2011-02-09 12:34:56", r(code, data=datetime.datetime(2011, 2, 9, 12, 34, 56)) 
     801        yield eq, "2011-02-09 12:34:56.987000", r(code, data=datetime.datetime(2011, 2, 9, 12, 34, 56, 987000)) 
     802 
     803 
     804def test_function_int(): 
     805    for r in all_renderers: 
     806        yield raises, "int.*unknown", RenderPython(u"<?print int()?>") 
     807        yield raises, "int.*unknown", RenderPython(u"<?print int(1, 2, 3)?>") 
     808        yield raises, "int\\(\\) argument must be a string or a number|int\\(null\\) not supported", RenderPython(u"<?print int(data)?>", data=None) 
     809        yield raises, "invalid literal for int|NumberFormatException", RenderPython(u"<?print int(data)?>", data="foo") 
     810        yield eq, "1", r(u"<?print int(data)?>", data=True) 
     811        yield eq, "0", r(u"<?print int(data)?>", data=False) 
     812        yield eq, "42", r(u"<?print int(data)?>", data=42) 
     813        yield eq, "4", r(u"<?print int(data)?>", data=4.2) 
     814        yield eq, "42", r(u"<?print int(data)?>", data="42") 
     815        yield eq, "66", r(u"<?print int(data, 16)?>", data="42") 
     816 
     817 
     818def test_function_float(): 
    837819    code = u"<?print float(data)?>" 
    838820 
    839     with raises("float.*unknown"): 
    840         r(u"<?print float()?>") 
    841     with raises("float.*unknown"): 
    842         r(u"<?print float(1, 2, 3)?>") 
    843     with raises("float\\(\\) argument must be a string or a number|float\\(null\\) not supported"): 
    844         r(code, data=None) 
    845     assert "4.2" == r(code, data=4.2) 
    846     if r is not renderjs: 
    847         assert "1.0" == r(code, data=True) 
    848         assert "0.0" == r(code, data=False) 
    849         assert "42.0" == r(code, data=42) 
    850         assert "42.0" == r(code, data="42") 
    851     else: 
    852         assert 1.0 == eval(r(code, data=True)) 
    853         assert 0.0 == eval(r(code, data=False)) 
    854         assert 42.0 == eval(r(code, data=42)) 
    855         assert 42.0 == eval(r(code, data="42")) 
    856  
    857  
    858 @with_all_renderers 
    859 def test_function_len(r): 
     821    for r in all_renderers: 
     822        yield raises, "float.*unknown", r(u"<?print float()?>") 
     823        yield raises, "float.*unknown", r(u"<?print float(1, 2, 3)?>") 
     824        yield raises, "float\\(\\) argument must be a string or a number|float\\(null\\) not supported", r(code, data=None) 
     825        yield eq, "4.2", r(code, data=4.2) 
     826        if r is not RenderJS: 
     827            yield eq, "1.0", r(code, data=True) 
     828            yield eq, "0.0", r(code, data=False) 
     829            yield eq, "42.0", r(code, data=42) 
     830            yield eq, "42.0", r(code, data="42") 
     831        else: 
     832            yield evaleq, 1.0, eval(r(code, data=True)) 
     833            yield evaleq, 0.0, eval(r(code, data=False)) 
     834            yield evaleq, 42.0, eval(r(code, data=42)) 
     835            yield evaleq, 42.0, eval(r(code, data="42")) 
     836 
     837 
     838def test_function_len(): 
    860839    code = u"<?print len(data)?>" 
    861     with raises("len.*unknown"): 
    862         r(u"<?print len()?>") 
    863     with raises("len.*unknown"): 
    864         r(u"<?print len(1, 2)?>") 
    865     with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    866         r(code, data=None) 
    867     with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    868         r(code, data=True) 
    869     with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    870         r(code, data=False) 
    871     with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    872         r(code, data=42) 
    873     with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    874         r(code, data=4.2) 
    875     assert "42" == r(code, data=42*"?") 
    876     assert "42" == r(code, data=42*[None]) 
    877     assert "42" == r(code, data=dict.fromkeys(xrange(42))) 
    878  
    879  
    880 @with_all_renderers 
    881 def test_function_enumerate(r): 
     840    for r in all_renderers: 
     841        yield raises, "len.*unknown", r(u"<?print len()?>") 
     842        yield raises, "len.*unknown", r(u"<?print len(1, 2)?>") 
     843        yield raises, "has no len\\(\\)|len\\(.*\\) not supported", r(code, data=None) 
     844        yield raises, "has no len\\(\\)|len\\(.*\\) not supported", r(code, data=True) 
     845        yield raises, "has no len\\(\\)|len\\(.*\\) not supported", r(code, data=False) 
     846        yield raises, "has no len\\(\\)|len\\(.*\\) not supported", r(code, data=42) 
     847        yield raises, "has no len\\(\\)|len\\(.*\\) not supported", r(code, data=4.2) 
     848        yield eq, "42", r(code, data=42*"?") 
     849        yield eq, "42", r(code, data=42*[None]) 
     850        yield eq, "42", r(code, data=dict.fromkeys(xrange(42))) 
     851 
     852 
     853def test_function_enumerate(): 
    882854    code = u"<?for (i, value) in enumerate(data)?><?print i?>:<?print value?>\n<?end for?>" 
    883     with raises("enumerate.*unknown"): 
    884         r(u"<?print enumerate()?>") 
    885     with raises("enumerate.*unknown"): 
    886         r(u"<?print enumerate(1, 2)?>") 
    887     with raises("is not iterable|iter\\(.*\\) not supported"): 
    888         r(code, data=None) 
    889     with raises("is not iterable|iter\\(.*\\) not supported"): 
    890         r(code, data=True) 
    891     with raises("is not iterable|iter\\(.*\\) not supported"): 
    892         r(code, data=False) 
    893     with raises("is not iterable|iter\\(.*\\) not supported"): 
    894         r(code, data=42) 
    895     with raises("is not iterable|iter\\(.*\\) not supported"): 
    896         r(code, data=4.2) 
    897     assert "0:f\n1:o\n2:o\n" == r(code, data="foo") 
    898     assert "0:foo\n1:bar\n" == r(code, data=["foo", "bar"]) 
    899     assert "0:foo\n" == r(code, data=dict(foo=True)) 
    900  
    901  
    902 @with_all_renderers 
    903 def test_function_isnone(r): 
     855    for r in all_renderers: 
     856        yield raises, "enumerate.*unknown", r(u"<?print enumerate()?>") 
     857        yield raises, "enumerate.*unknown", r(u"<?print enumerate(1, 2)?>") 
     858        yield raises, "is not iterable|iter\\(.*\\) not supported", r(code, data=None) 
     859        yield raises, "is not iterable|iter\\(.*\\) not supported", r(code, data=True) 
     860        yield raises, "is not iterable|iter\\(.*\\) not supported", r(code, data=False) 
     861        yield raises, "is not iterable|iter\\(.*\\) not supported", r(code, data=42) 
     862        yield raises, "is not iterable|iter\\(.*\\) not supported", r(code, data=4.2) 
     863        yield eq, "0:f\n1:o\n2:o\n", r(code, data="foo") 
     864        yield eq, "0:foo\n1:bar\n", r(code, data=["foo", "bar"]) 
     865        yield eq, "0:foo\n", r(code, data=dict(foo=True)) 
     866 
     867 
     868def test_function_isnone(): 
    904869    code = u"<?print isnone(data)?>" 
    905     with raises("isnone.*unknown"): 
    906         r(u"<?print isnone()?>") 
    907     with raises("isnone.*unknown"): 
    908         r(u"<?print isnone(1, 2)?>") 
    909     assert "True" == r(code, data=None) 
    910     assert "False" == r(code, data=True) 
    911     assert "False" == r(code, data=False) 
    912     assert "False" == r(code, data=42) 
    913     assert "False" == r(code, data=4.2) 
    914     assert "False" == r(code, data="foo") 
    915     assert "False" == r(code, data=datetime.datetime.now()) 
    916     assert "False" == r(code, data=()) 
    917     assert "False" == r(code, data=[]) 
    918     assert "False" == r(code, data={}) 
    919     assert "False" == r(code, data=ul4c.compile(u"")) 
    920     assert "False" == r(code, data=color.red) 
    921  
    922  
    923 @with_all_renderers 
    924 def test_function_isbool(r): 
     870    for r in all_renderers: 
     871        yield raises, "isnone.*unknown", r(u"<?print isnone()?>") 
     872        yield raises, "isnone.*unknown", r(u"<?print isnone(1, 2)?>") 
     873        yield eq, "True", r(code, data=None) 
     874        yield eq, "False", r(code, data=True) 
     875        yield eq, "False", r(code, data=False) 
     876        yield eq, "False", r(code, data=42) 
     877        yield eq, "False", r(code, data=4.2) 
     878        yield eq, "False", r(code, data="foo") 
     879        yield eq, "False", r(code, data=datetime.datetime.now()) 
     880        yield eq, "False", r(code, data=()) 
     881        yield eq, "False", r(code, data=[]) 
     882        yield eq, "False", r(code, data={}) 
     883        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     884        yield eq, "False", r(code, data=color.red) 
     885 
     886 
     887def test_function_isbool(): 
    925888    code = u"<?print isbool(data)?>" 
    926889 
    927     with raises("isbool.*unknown"): 
    928         r(u"<?print isbool()?>") 
    929     with raises("isbool.*unknown"): 
    930         r(u"<?print isbool(1, 2)?>") 
    931     assert "False" == r(code, data=None) 
    932     assert "True" == r(code, data=True) 
    933     assert "True" == r(code, data=False) 
    934     assert "False" == r(code, data=42) 
    935     assert "False" == r(code, data=4.2) 
    936     assert "False" == r(code, data="foo") 
    937     assert "False" == r(code, data=datetime.datetime.now()) 
    938     assert "False" == r(code, data=()) 
    939     assert "False" == r(code, data=[]) 
    940     assert "False" == r(code, data={}) 
    941     assert "False" == r(code, data=ul4c.compile(u"")) 
    942     assert "False" == r(code, data=color.red) 
    943  
    944  
    945 @with_all_renderers 
    946 def test_function_isint(r): 
     890    for r in all_renderers: 
     891        yield raises, "isbool.*unknown", r(u"<?print isbool()?>") 
     892        yield raises, "isbool.*unknown", r(u"<?print isbool(1, 2)?>") 
     893        yield eq, "False", r(code, data=None) 
     894        yield eq, "True", r(code, data=True) 
     895        yield eq, "True", r(code, data=False) 
     896        yield eq, "False", r(code, data=42) 
     897        yield eq, "False", r(code, data=4.2) 
     898        yield eq, "False", r(code, data="foo") 
     899        yield eq, "False", r(code, data=datetime.datetime.now()) 
     900        yield eq, "False", r(code, data=()) 
     901        yield eq, "False", r(code, data=[]) 
     902        yield eq, "False", r(code, data={}) 
     903        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     904        yield eq, "False", r(code, data=color.red) 
     905 
     906 
     907def test_function_isint(): 
    947908    code = u"<?print isint(data)?>" 
    948909 
    949     with raises("isint.*unknown"): 
    950         r(u"<?print isint()?>") 
    951     with raises("isint.*unknown"): 
    952         r(u"<?print isint(1, 2)?>") 
    953     assert "False" == r(code, data=None) 
    954     assert "False" == r(code, data=True) 
    955     assert "False" == r(code, data=False) 
    956     assert "True" == r(code, data=42) 
    957     assert "False" == r(code, data=4.2) 
    958     assert "False" == r(code, data="foo") 
    959     assert "False" == r(code, data=datetime.datetime.now()) 
    960     assert "False" == r(code, data=()) 
    961     assert "False" == r(code, data=[]) 
    962     assert "False" == r(code, data={}) 
    963     assert "False" == r(code, data=ul4c.compile(u"")) 
    964     assert "False" == r(code, data=color.red) 
    965  
    966  
    967 @with_all_renderers 
    968 def test_function_isfloat(r): 
     910    for r in all_renderers: 
     911        yield raises, "isint.*unknown", r(u"<?print isint()?>") 
     912        yield raises, "isint.*unknown", r(u"<?print isint(1, 2)?>") 
     913        yield eq, "False", r(code, data=None) 
     914        yield eq, "False", r(code, data=True) 
     915        yield eq, "False", r(code, data=False) 
     916        yield eq, "True", r(code, data=42) 
     917        yield eq, "False", r(code, data=4.2) 
     918        yield eq, "False", r(code, data="foo") 
     919        yield eq, "False", r(code, data=datetime.datetime.now()) 
     920        yield eq, "False", r(code, data=()) 
     921        yield eq, "False", r(code, data=[]) 
     922        yield eq, "False", r(code, data={}) 
     923        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     924        yield eq, "False", r(code, data=color.red) 
     925 
     926 
     927def test_function_isfloat(): 
    969928    code = u"<?print isfloat(data)?>" 
    970929 
    971     with raises("isfloat.*unknown"): 
    972         r(u"<?print isfloat()?>") 
    973     with raises("isfloat.*unknown"): 
    974         r(u"<?print isfloat(1, 2)?>") 
    975     assert "False" == r(code, data=None) 
    976     assert "False" == r(code, data=True) 
    977     assert "False" == r(code, data=False) 
    978     assert "False" == r(code, data=42) 
    979     assert "True" == r(code, data=4.2) 
    980     assert "False" == r(code, data="foo") 
    981     assert "False" == r(code, data=datetime.datetime.now()) 
    982     assert "False" == r(code, data=()) 
    983     assert "False" == r(code, data=[]) 
    984     assert "False" == r(code, data={}) 
    985     assert "False" == r(code, data=ul4c.compile(u"")) 
    986     assert "False" == r(code, data=color.red) 
    987  
    988  
    989 @with_all_renderers 
    990 def test_function_isstr(r): 
     930    for r in all_renderers: 
     931        yield raises, "isfloat.*unknown", r(u"<?print isfloat()?>") 
     932        yield raises, "isfloat.*unknown", r(u"<?print isfloat(1, 2)?>") 
     933        yield eq, "False", r(code, data=None) 
     934        yield eq, "False", r(code, data=True) 
     935        yield eq, "False", r(code, data=False) 
     936        yield eq, "False", r(code, data=42) 
     937        yield eq, "True", r(code, data=4.2) 
     938        yield eq, "False", r(code, data="foo") 
     939        yield eq, "False", r(code, data=datetime.datetime.now()) 
     940        yield eq, "False", r(code, data=()) 
     941        yield eq, "False", r(code, data=[]) 
     942        yield eq, "False", r(code, data={}) 
     943        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     944        yield eq, "False", r(code, data=color.red) 
     945 
     946 
     947def test_function_isstr(): 
    991948    code = u"<?print isstr(data)?>" 
    992949 
    993     with raises("isstr.*unknown"): 
    994         r(u"<?print isstr()?>") 
    995     with raises("isstr.*unknown"): 
    996         r(u"<?print isstr(1, 2)?>") 
    997     assert "False" == r(code, data=None) 
    998     assert "False" == r(code, data=True) 
    999     assert "False" == r(code, data=False) 
    1000     assert "False" == r(code, data=42) 
    1001     assert "False" == r(code, data=4.2) 
    1002     assert "True" == r(code, data="foo") 
    1003     assert "False" == r(code, data=datetime.datetime.now()) 
    1004     assert "False" == r(code, data=()) 
    1005     assert "False" == r(code, data=[]) 
    1006     assert "False" == r(code, data={}) 
    1007     assert "False" == r(code, data=ul4c.compile(u"")) 
    1008     assert "False" == r(code, data=color.red) 
    1009  
    1010  
    1011 @with_all_renderers 
    1012 def test_function_isdate(r): 
     950    for r in all_renderers: 
     951        yield raises, "isstr.*unknown", r(u"<?print isstr()?>") 
     952        yield raises, "isstr.*unknown", r(u"<?print isstr(1, 2)?>") 
     953        yield eq, "False", r(code, data=None) 
     954        yield eq, "False", r(code, data=True) 
     955        yield eq, "False", r(code, data=False) 
     956        yield eq, "False", r(code, data=42) 
     957        yield eq, "False", r(code, data=4.2) 
     958        yield eq, "True", r(code, data="foo") 
     959        yield eq, "False", r(code, data=datetime.datetime.now()) 
     960        yield eq, "False", r(code, data=()) 
     961        yield eq, "False", r(code, data=[]) 
     962        yield eq, "False", r(code, data={}) 
     963        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     964        yield eq, "False", r(code, data=color.red) 
     965 
     966 
     967def test_function_isdate(): 
    1013968    code = u"<?print isdate(data)?>" 
    1014969 
    1015     with raises("isdate.*unknown"): 
    1016         r(u"<?print isdate()?>") 
    1017     with raises("isdate.*unknown"): 
    1018         r(u"<?print isdate(1, 2)?>") 
    1019     assert "False" == r(code, data=None) 
    1020     assert "False" == r(code, data=True) 
    1021     assert "False" == r(code, data=False) 
    1022     assert "False" == r(code, data=42) 
    1023     assert "False" == r(code, data=4.2) 
    1024     assert "False" == r(code, data="foo") 
    1025     assert "True" == r(code, data=datetime.datetime.now()) 
    1026     assert "False" == r(code, data=()) 
    1027     assert "False" == r(code, data=[]) 
    1028     assert "False" == r(code, data={}) 
    1029     assert "False" == r(code, data=ul4c.compile(u"")) 
    1030     assert "False" == r(code, data=color.red) 
    1031  
    1032  
    1033 @with_all_renderers 
    1034 def test_function_islist(r): 
     970    for r in all_renderers: 
     971        yield raises, "isdate.*unknown", r(u"<?print isdate()?>") 
     972        yield raises, "isdate.*unknown", r(u"<?print isdate(1, 2)?>") 
     973        yield eq, "False", r(code, data=None) 
     974        yield eq, "False", r(code, data=True) 
     975        yield eq, "False", r(code, data=False) 
     976        yield eq, "False", r(code, data=42) 
     977        yield eq, "False", r(code, data=4.2) 
     978        yield eq, "False", r(code, data="foo") 
     979        yield eq, "True", r(code, data=datetime.datetime.now()) 
     980        yield eq, "False", r(code, data=()) 
     981        yield eq, "False", r(code, data=[]) 
     982        yield eq, "False", r(code, data={}) 
     983        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     984        yield eq, "False", r(code, data=color.red) 
     985 
     986 
     987def test_function_islist(): 
    1035988    code = u"<?print islist(data)?>" 
    1036989 
    1037     with raises("islist.*unknown"): 
    1038         r(u"<?print islist()?>") 
    1039     with raises("islist.*unknown"): 
    1040         r(u"<?print islist(1, 2)?>") 
    1041     assert "False" == r(code, data=None) 
    1042     assert "False" == r(code, data=True) 
    1043     assert "False" == r(code, data=False) 
    1044     assert "False" == r(code, data=42) 
    1045     assert "False" == r(code, data=4.2) 
    1046     assert "False" == r(code, data="foo") 
    1047     assert "False" == r(code, data=datetime.datetime.now()) 
    1048     assert "True" == r(code, data=()) 
    1049     assert "True" == r(code, data=[]) 
    1050     assert "True" == r(code, data=PseudoList([])) 
    1051     assert "False" == r(code, data={}) 
    1052     assert "False" == r(code, data=ul4c.compile(u"")) 
    1053     assert "False" == r(code, data=color.red) 
    1054  
    1055  
    1056 @with_all_renderers 
    1057 def test_function_isdict(r): 
     990    for r in all_renderers: 
     991        yield raises, "islist.*unknown", r(u"<?print islist()?>") 
     992        yield raises, "islist.*unknown", r(u"<?print islist(1, 2)?>") 
     993        yield eq, "False", r(code, data=None) 
     994        yield eq, "False", r(code, data=True) 
     995        yield eq, "False", r(code, data=False) 
     996        yield eq, "False", r(code, data=42) 
     997        yield eq, "False", r(code, data=4.2) 
     998        yield eq, "False", r(code, data="foo") 
     999        yield eq, "False", r(code, data=datetime.datetime.now()) 
     1000        yield eq, "True", r(code, data=()) 
     1001        yield eq, "True", r(code, data=[]) 
     1002        yield eq, "True", r(code, data=PseudoList([])) 
     1003        yield eq, "False", r(code, data={}) 
     1004        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     1005        yield eq, "False", r(code, data=color.red) 
     1006 
     1007 
     1008def test_function_isdict(): 
    10581009    code = u"<?print isdict(data)?>" 
    10591010 
    1060     with raises("isdict.*unknown"): 
    1061         r(u"<?print isdict()?>") 
    1062     with raises("isdict.*unknown"): 
    1063         r(u"<?print isdict(1, 2)?>") 
    1064     assert "False" == r(code, data=None) 
    1065     assert "False" == r(code, data=True) 
    1066     assert "False" == r(code, data=False) 
    1067     assert "False" == r(code, data=42) 
    1068     assert "False" == r(code, data=4.2) 
    1069     assert "False" == r(code, data="foo") 
    1070     assert "False" == r(code, data=datetime.datetime.now()) 
    1071     assert "False" == r(code, data=()) 
    1072     assert "False" == r(code, data=[]) 
    1073     assert "True" == r(code, data={}) 
    1074     assert "True" == r(code, data=PseudoDict({})) 
    1075     assert "False" == r(code, data=ul4c.compile(u"")) 
    1076     assert "False" == r(code, data=color.red) 
    1077  
    1078  
    1079 @with_all_renderers 
    1080 def test_function_istemplate(r): 
     1011    for r in all_renderers: 
     1012        yield raises, "isdict.*unknown", r(u"<?print isdict()?>") 
     1013        yield raises, "isdict.*unknown", r(u"<?print isdict(1, 2)?>") 
     1014        yield eq, "False", r(code, data=None) 
     1015        yield eq, "False", r(code, data=True) 
     1016        yield eq, "False", r(code, data=False) 
     1017        yield eq, "False", r(code, data=42) 
     1018        yield eq, "False", r(code, data=4.2) 
     1019        yield eq, "False", r(code, data="foo") 
     1020        yield eq, "False", r(code, data=datetime.datetime.now()) 
     1021        yield eq, "False", r(code, data=()) 
     1022        yield eq, "False", r(code, data=[]) 
     1023        yield eq, "True", r(code, data={}) 
     1024        yield eq, "True", r(code, data=PseudoDict({})) 
     1025        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     1026        yield eq, "False", r(code, data=color.red) 
     1027 
     1028 
     1029def test_function_istemplate(): 
    10811030    code = u"<?print istemplate(data)?>" 
    10821031 
    1083     with raises("istemplate.*unknown"): 
    1084         r(u"<?print istemplate()?>") 
    1085     with raises("istemplate.*unknown"): 
    1086         r(u"<?print istemplate(1, 2)?>") 
    1087     assert "False" == r(code, data=None) 
    1088     assert "False" == r(code, data=True) 
    1089     assert "False" == r(code, data=False) 
    1090     assert "False" == r(code, data=42) 
    1091     assert "False" == r(code, data=4.2) 
    1092     assert "False" == r(code, data="foo") 
    1093     assert "False" == r(code, data=datetime.datetime.now()) 
    1094     assert "False" == r(code, data=()) 
    1095     assert "False" == r(code, data=[]) 
    1096     assert "False" == r(code, data={}) 
    1097     assert "True" == r(code, data=ul4c.compile(u"")) 
    1098     assert "False" == r(code, data=color.red) 
    1099  
    1100  
    1101 @with_all_renderers 
    1102 def test_function_iscolor(r): 
     1032    for r in all_renderers: 
     1033        yield raises, "istemplate.*unknown", r(u"<?print istemplate()?>") 
     1034        yield raises, "istemplate.*unknown", r(u"<?print istemplate(1, 2)?>") 
     1035        yield eq, "False", r(code, data=None) 
     1036        yield eq, "False", r(code, data=True) 
     1037        yield eq, "False", r(code, data=False) 
     1038        yield eq, "False", r(code, data=42) 
     1039        yield eq, "False", r(code, data=4.2) 
     1040        yield eq, "False", r(code, data="foo") 
     1041        yield eq, "False", r(code, data=datetime.datetime.now()) 
     1042        yield eq, "False", r(code, data=()) 
     1043        yield eq, "False", r(code, data=[]) 
     1044        yield eq, "False", r(code, data={}) 
     1045        yield eq, "True", r(code, data=ul4c.compile(u"")) 
     1046        yield eq, "False", r(code, data=color.red) 
     1047 
     1048 
     1049def test_function_iscolor(): 
    11031050    code = u"<?print iscolor(data)?>" 
    11041051 
    1105     with raises("iscolor.*unknown"): 
    1106         r(u"<?print iscolor()?>") 
    1107     with raises("iscolor.*unknown"): 
    1108         r(u"<?print iscolor(1, 2)?>") 
    1109     assert "False" == r(code, data=None) 
    1110     assert "False" == r(code, data=True) 
    1111     assert "False" == r(code, data=False) 
    1112     assert "False" == r(code, data=42) 
    1113     assert "False" == r(code, data=4.2) 
    1114     assert "False" == r(code, data="foo") 
    1115     assert "False" == r(code, data=datetime.datetime.now()) 
    1116     assert "False" == r(code, data=()) 
    1117     assert "False" == r(code, data=[]) 
    1118     assert "False" == r(code, data={}) 
    1119     assert "False" == r(code, data=ul4c.compile(u"")) 
    1120     assert "True" == r(code, data=color.red) 
    1121  
    1122  
    1123 @with_all_renderers 
    1124 def test_function_get(r): 
    1125     with raises("get.*unknown"): 
    1126         r(u"<?print get()?>") 
    1127     assert "" == r(u"<?print get('x')?>") 
    1128     assert "42" == r(u"<?print get('x')?>", x=42) 
    1129     assert "17" == r(u"<?print get('x', 17)?>") 
    1130     assert "42" == r(u"<?print get('x', 17)?>", x=42) 
    1131  
    1132  
    1133 @with_all_renderers 
    1134 def test_function_repr(r): 
     1052    for r in all_renderers: 
     1053        yield raises, "iscolor.*unknown", r(u"<?print iscolor()?>") 
     1054        yield raises, "iscolor.*unknown", r(u"<?print iscolor(1, 2)?>") 
     1055        yield eq, "False", r(code, data=None) 
     1056        yield eq, "False", r(code, data=True) 
     1057        yield eq, "False", r(code, data=False) 
     1058        yield eq, "False", r(code, data=42) 
     1059        yield eq, "False", r(code, data=4.2) 
     1060        yield eq, "False", r(code, data="foo") 
     1061        yield eq, "False", r(code, data=datetime.datetime.now()) 
     1062        yield eq, "False", r(code, data=()) 
     1063        yield eq, "False", r(code, data=[]) 
     1064        yield eq, "False", r(code, data={}) 
     1065        yield eq, "False", r(code, data=ul4c.compile(u"")) 
     1066        yield eq, "True", r(code, data=color.red) 
     1067 
     1068 
     1069def test_function_get(): 
     1070    for r in all_renderers: 
     1071        yield raises, "get.*unknown", r(u"<?print get()?>") 
     1072        yield eq, "", r(u"<?print get('x')?>") 
     1073        yield eq, "42", r(u"<?print get('x')?>", x=42) 
     1074        yield eq, "17", r(u"<?print get('x', 17)?>") 
     1075        yield eq, "42", r(u"<?print get('x', 17)?>", x=42) 
     1076 
     1077 
     1078def test_function_repr(): 
    11351079    code = u"<?print repr(data)?>" 
    11361080 
    1137     with raises("repr.*unknown"): 
    1138         r(u"<?print repr()?>") 
    1139     with raises("repr.*unknown"): 
    1140         r(u"<?print repr(1, 2)?>") 
    1141     assert "None" == r(code, data=None) 
    1142     assert "True" == r(code, data=True) 
    1143     assert "False" == r(code, data=False) 
    1144     assert "42" == r(code, data=42) 
    1145     assert 42.5 == eval(r(code, data=42.5)) 
    1146     assert r(code, data="foo") in ('"foo"', "'foo'") 
    1147     assert [1, 2, 3] == eval(r(code, data=[1, 2, 3])) 
    1148     if r is not renderjs: 
    1149         assert [1, 2, 3] == eval(r(code, data=(1, 2, 3))) 
    1150     assert {"a": 1, "b": 2} == eval(r(code, data={"a": 1, "b": 2})) 
    1151     assert "@2011-02-07T12:34:56.123000" == r(code, data=datetime.datetime(2011, 2, 7, 12, 34, 56, 123000)) 
    1152     assert "@2011-02-07T12:34:56" == r(code, data=datetime.datetime(2011, 2, 7, 12, 34, 56)) 
    1153     assert "@2011-02-07T" == r(code, data=datetime.datetime(2011, 2, 7)) 
    1154     assert "@2011-02-07T" == r(code, data=datetime.date(2011, 2, 7)) 
    1155  
    1156  
    1157 @with_all_renderers 
    1158 def test_function_chr(r): 
     1081    for r in all_renderers: 
     1082        yield raises, "repr.*unknown", r(u"<?print repr()?>") 
     1083        yield raises, "repr.*unknown", r(u"<?print repr(1, 2)?>") 
     1084        yield eq, "None", r(code, data=None) 
     1085        yield eq, "True", r(code, data=True) 
     1086        yield eq, "False", r(code, data=False) 
     1087        yield eq, "42", r(code, data=42) 
     1088        yield evaleq, 42.5, r(code, data=42.5) 
     1089        yield evalcontains, ('"foo"', "'foo'"), r(code, data="foo") 
     1090        yield evaleq, [1, 2, 3], r(code, data=[1, 2, 3]) 
     1091        if r is not renderjs: 
     1092            yield evaleq, [1, 2, 3], r(code, data=(1, 2, 3)) 
     1093        yield evaleq, {"a": 1, "b": 2}, r(code, data={"a": 1, "b": 2}) 
     1094        yield eq, "@2011-02-07T12:34:56.123000", r(code, data=datetime.datetime(2011, 2, 7, 12, 34, 56, 123000)) 
     1095        yield eq, "@2011-02-07T12:34:56", r(code, data=datetime.datetime(2011, 2, 7, 12, 34, 56)) 
     1096        yield eq, "@2011-02-07T", r(code, data=datetime.datetime(2011, 2, 7)) 
     1097        yield eq, "@2011-02-07T", r(code, data=datetime.date(2011, 2, 7)) 
     1098 
     1099 
     1100def test_function_chr(): 
    11591101    code = u"<?print chr(data)?>" 
    11601102 
    1161     with raises("chr.*unknown"): 
    1162         r(u"<?print chr()?>") 
    1163     with raises("chr.*unknown"): 
    1164         r(u"<?print chr(1, 2)?>") 
    1165     assert "\x00" == r(code, data=0) 
    1166     assert "a" == r(code, data=ord("a")) 
    1167     assert u"\u20ac" == r(code, data=0x20ac) 
    1168  
    1169  
    1170 @with_all_renderers 
    1171 def test_function_ord(r): 
     1103    for r in all_renderers: 
     1104        yield raises, "chr.*unknown", r(u"<?print chr()?>") 
     1105        yield raises, "chr.*unknown", r(u"<?print chr(1, 2)?>") 
     1106        yield eq, "\x00", r(code, data=0) 
     1107        yield eq, "a", r(code, data=ord("a")) 
     1108        yield eq, u"\u20ac", r(code, data=0x20ac) 
     1109 
     1110 
     1111def test_function_ord(): 
    11721112    code = u"<?print ord(data)?>" 
    11731113 
    1174     with raises("ord.*unknown"): 
    1175         r(u"<?print ord()?>") 
    1176     with raises("ord.*unknown"): 
    1177         r(u"<?print ord(1, 2)?>") 
    1178     assert "0" == r(code, data="\x00") 
    1179     assert str(ord("a")) == r(code, data="a") 
    1180     assert str(0x20ac) == r(code, data=u"\u20ac") 
    1181  
    1182  
    1183 @with_all_renderers 
    1184 def test_function_hex(r): 
     1114    for r in all_renderers: 
     1115        yield raises, "ord.*unknown", r(u"<?print ord()?>") 
     1116        yield raises, "ord.*unknown", r(u"<?print ord(1, 2)?>") 
     1117        yield eq, "0", r(code, data="\x00") 
     1118        yield eq, str(ord("a")), r(code, data="a") 
     1119        yield eq, str(0x20ac), r(code, data=u"\u20ac") 
     1120 
     1121 
     1122def test_function_hex(): 
    11851123    code = u"<?print hex(data)?>" 
    11861124 
    1187     with raises("hex.*unknown"): 
    1188         r(u"<?print hex()?>") 
    1189     with raises("hex.*unknown"): 
    1190         r(u"<?print hex(1, 2)?>") 
    1191     assert "0x0" == r(code, data=0) 
    1192     assert "0xff" == r(code, data=0xff) 
    1193     assert "0xffff" == r(code, data=0xffff) 
    1194     assert "-0xffff" == r(code, data=-0xffff) 
    1195  
    1196  
    1197 @with_all_renderers 
    1198 def test_function_oct(r): 
     1125    for r in all_renderers: 
     1126        yield raises, "hex.*unknown", r(u"<?print hex()?>") 
     1127        yield raises, "hex.*unknown", r(u"<?print hex(1, 2)?>") 
     1128        yield eq, "0x0", r(code, data=0) 
     1129        yield eq, "0xff", r(code, data=0xff) 
     1130        yield eq, "0xffff", r(code, data=0xffff) 
     1131        yield eq, "-0xffff", r(code, data=-0xffff) 
     1132 
     1133 
     1134def test_function_oct(): 
    11991135    code = u"<?print oct(data)?>" 
    12001136 
    1201     with raises("oct.*unknown"): 
    1202         r(u"<?print oct()?>") 
    1203     with raises("oct.*unknown"): 
    1204         r(u"<?print oct(1, 2)?>") 
    1205     assert "0o0" == r(code, data=0) 
    1206     assert "0o77" == r(code, data=077) 
    1207     assert "0o7777" == r(code, data=07777) 
    1208     assert "-0o7777" == r(code, data=-07777) 
    1209  
    1210  
    1211 @with_all_renderers 
    1212 def test_function_bin(r): 
     1137    for r in all_renderers: 
     1138        yield raises, "oct.*unknown", r(u"<?print oct()?>") 
     1139        yield raises, "oct.*unknown", r(u"<?print oct(1, 2)?>") 
     1140        yield eq, "0o0", r(code, data=0) 
     1141        yield eq, "0o77", r(code, data=077) 
     1142        yield eq, "0o7777", r(code, data=07777) 
     1143        yield eq, "-0o7777", r(code, data=-07777) 
     1144 
     1145 
     1146def test_function_bin(): 
    12131147    code = u"<?print bin(data)?>" 
    12141148 
    1215     with raises("bin.*unknown"): 
    1216         r(u"<?print bin()?>") 
    1217     with raises("bin.*unknown"): 
    1218         r(u"<?print bin(1, 2)?>") 
    1219     assert "0b0" == r(code, data=0) 
    1220     assert "0b11" == r(code, data=3) 
    1221     assert "-0b1111" == r(code, data=-15) 
    1222  
    1223  
    1224 @with_all_renderers 
    1225 def test_function_abs(r): 
     1149    for r in all_renderers: 
     1150        yield raises, "bin.*unknown", r(u"<?print bin()?>") 
     1151        yield raises, "bin.*unknown", r(u"<?print bin(1, 2)?>") 
     1152        yield eq, "0b0", r(code, data=0) 
     1153        yield eq, "0b11", r(code, data=3) 
     1154        yield eq, "-0b1111", r(code, data=-15) 
     1155 
     1156 
     1157def test_function_abs(): 
    12261158    code = u"<?print abs(data)?>" 
    12271159 
    1228     with raises("abs.*unknown"): 
    1229         r(u"<?print abs()?>") 
    1230     with raises("abs.*unknown"): 
    1231         r(u"<?print abs(1, 2)?>") 
    1232     assert "0" == r(code, data=0) 
    1233     assert "42" == r(code, data=42) 
    1234     assert "42" == r(code, data=-42) 
    1235  
    1236  
    1237 @with_all_renderers 
    1238 def test_function_sorted(r): 
     1160    for r in all_renderers: 
     1161        yield raises, "abs.*unknown", r(u"<?print abs()?>") 
     1162        yield raises, "abs.*unknown", r(u"<?print abs(1, 2)?>") 
     1163        yield eq, "0", r(code, data=0) 
     1164        yield eq, "42", r(code, data=42) 
     1165        yield eq, "42", r(code, data=-42) 
     1166 
     1167 
     1168def test_function_sorted(): 
    12391169    code = u"<?for i in sorted(data)?><?print i?><?end for?>" 
    12401170 
    1241     with raises("sorted.*unknown"): 
    1242         r(u"<?print sorted()?>") 
    1243     with raises("sorted.*unknown"): 
    1244         r(u"<?print sorted(1, 2)?>") 
    1245     assert "gkru" == r(code, data="gurk") 
    1246     assert "24679" == r(code, data="92746") 
    1247     assert "012" == r(code, data={0: "zero", 1: "one", 2: "two"}) 
    1248  
    1249  
    1250 @with_all_renderers 
    1251 def test_function_range(r): 
    1252     with raises("range.*unknown"): 
    1253         r(u"<?print range()?>") 
    1254     code = u"<?for i in range(data)?><?print i?><?end for?>" 
    1255     assert "" == r(code, data=-10) 
    1256     assert "" == r(code, data=0) 
    1257     assert "0" == r(code, data=1) 
    1258     assert "01234" == r(code, data=5) 
    1259     code = u"<?for i in range(data[0], data[1])?><?print i?><?end for?>" 
    1260     assert "" == r(code, data=[0, -10]) 
    1261     assert "" == r(code, data=[0, 0]) 
    1262     assert "01234" == r(code, data=[0, 5]) 
    1263     assert "-5-4-3-2-101234" == r(code, data=[-5, 5]) 
    1264     code = u"<?for i in range(data[0], data[1], data[2])?><?print i?><?end for?>" 
    1265     assert "" == r(code, data=[0, -10, 1]) 
    1266     assert "" == r(code, data=[0, 0, 1]) 
    1267     assert "02468" == r(code, data=[0, 10, 2]) 
    1268     assert "" == r(code, data=[0, 10, -2]) 
    1269     assert "108642" == r(code, data=[10, 0, -2]) 
    1270     assert "" == r(code, data=[10, 0, 2]) 
    1271  
    1272  
    1273 @with_all_renderers 
    1274 def test_function_zip(r): 
    1275     with raises("zip.*unknown"): 
    1276         r(u"<?print zip()?>") 
    1277     with raises("zip.*unknown"): 
    1278         r(u"<?print zip(1)?>") 
    1279     code = u"<?for (ix, iy) in zip(x, y)?><?print ix?>-<?print iy?>;<?end for?>" 
    1280     assert "" == r(code, x=[], y=[]) 
    1281     assert "1-3;2-4;" == r(code, x=[1, 2], y=[3, 4]) 
    1282     assert "1-4;2-5;" == r(code, x=[1, 2, 3], y=[4, 5]) 
    1283     code = u"<?for (ix, iy, iz) in zip(x, y, z)?><?print ix?>-<?print iy?>+<?print iz?>;<?end for?>" 
    1284     assert "" == r(code, x=[], y=[], z=[]) 
    1285     assert "1-3+5;2-4+6;" == r(code, x=[1, 2], y=[3, 4], z=[5, 6]) 
    1286     assert "1-4+6;" == r(code, x=[1, 2, 3], y=[4, 5], z=[6]) 
    1287  
    1288  
    1289 @with_all_renderers 
    1290 def test_function_type(r): 
     1171    for r in all_renderers: 
     1172        yield raises, "sorted.*unknown", r(u"<?print sorted()?>") 
     1173        yield raises, "sorted.*unknown", r(u"<?print sorted(1, 2)?>") 
     1174        yield eq, "gkru", r(code, data="gurk") 
     1175        yield eq, "24679", r(code, data="92746") 
     1176        yield eq, "012", r(code, data={0: "zero", 1: "one", 2: "two"}) 
     1177 
     1178 
     1179def test_function_range(): 
     1180    code1 = u"<?for i in range(data)?><?print i?><?end for?>" 
     1181    code2 = u"<?for i in range(data[0], data[1])?><?print i?><?end for?>" 
     1182    code3 = u"<?for i in range(data[0], data[1], data[2])?><?print i?><?end for?>" 
     1183 
     1184    for r in all_renderers: 
     1185        yield raises, "range.*unknown", r(u"<?print range()?>") 
     1186        yield eq, "", r(code1, data=-10) 
     1187        yield eq, "", r(code1, data=0) 
     1188        yield eq, "0", r(code1, data=1) 
     1189        yield eq, "01234", r(code1, data=5) 
     1190        yield eq, "", r(code2, data=[0, -10]) 
     1191        yield eq, "", r(code2, data=[0, 0]) 
     1192        yield eq, "01234", r(code2, data=[0, 5]) 
     1193        yield eq, "-5-4-3-2-101234", r(code2, data=[-5, 5]) 
     1194        yield eq, "", r(code3, data=[0, -10, 1]) 
     1195        yield eq, "", r(code3, data=[0, 0, 1]) 
     1196        yield eq, "02468", r(code3, data=[0, 10, 2]) 
     1197        yield eq, "", r(code3, data=[0, 10, -2]) 
     1198        yield eq, "108642", r(code3, data=[10, 0, -2]) 
     1199        yield eq, "", r(code3, data=[10, 0, 2]) 
     1200 
     1201 
     1202def test_function_zip(): 
     1203    code2 = u"<?for (ix, iy) in zip(x, y)?><?print ix?>-<?print iy?>;<?end for?>" 
     1204    code3 = u"<?for (ix, iy, iz) in zip(x, y, z)?><?print ix?>-<?print iy?>+<?print iz?>;<?end for?>" 
     1205 
     1206    for r in all_renderers: 
     1207        yield raises, "zip.*unknown", r(u"<?print zip(1)?>") 
     1208        yield eq, "", r(code2, x=[], y=[]) 
     1209        yield eq, "1-3;2-4;", r(code2, x=[1, 2], y=[3, 4]) 
     1210        yield eq, "1-4;2-5;", r(code2, x=[1, 2, 3], y=[4, 5]) 
     1211        yield eq, "", r(code3, x=[], y=[], z=[]) 
     1212        yield eq, "1-3+5;2-4+6;", r(code3, x=[1, 2], y=[3, 4], z=[5, 6]) 
     1213        yield eq, "1-4+6;", r(code3, x=[1, 2, 3], y=[4, 5], z=[6]) 
     1214 
     1215 
     1216def test_function_type(): 
    12911217    code = u"<?print type(x)?>" 
    12921218 
    1293     with raises("type.*unknown"): 
    1294         r(u"<?print type()?>") 
    1295     with raises("type.*unknown"): 
    1296         r(u"<?print type(1, 2)?>") 
    1297     assert "none" == r(code, x=None) 
    1298     assert "bool" == r(code, x=False) 
    1299     assert "bool" == r(code, x=True) 
    1300     assert "int" == r(code, x=42) 
    1301     assert "int" == r(code, x=42L) 
    1302     assert "float" == r(code, x=4.2) 
    1303     assert "str" == r(code, x="foo") 
    1304     assert "str" == r(code, x=u"foo") 
    1305     assert "date" == r(code, x=datetime.datetime.now()) 
    1306     assert "date" == r(code, x=datetime.date.today()) 
    1307     assert "list" == r(code, x=(1, 2)) 
    1308     assert "list" == r(code, x=[1, 2]) 
    1309     assert "list" == r(code, x=PseudoList([1, 2])) 
    1310     assert "dict" == r(code, x={1: 2}) 
    1311     assert "dict" == r(code, x=PseudoDict({1: 2})) 
    1312     assert "template" == r(code, x=ul4c.compile("")) 
    1313     assert "color" == r(code, x=color.red) 
    1314  
    1315  
    1316 @with_all_renderers 
    1317 def test_function_reversed(r): 
     1219    for r in all_renderers: 
     1220        yield raises, "type.*unknown", r(u"<?print type()?>") 
     1221        yield raises, "type.*unknown", r(u"<?print type(1, 2)?>") 
     1222        yield eq, "none", r(code, x=None) 
     1223        yield eq, "bool", r(code, x=False) 
     1224        yield eq, "bool", r(code, x=True) 
     1225        yield eq, "int", r(code, x=42) 
     1226        yield eq, "int", r(code, x=42L) 
     1227        yield eq, "float", r(code, x=4.2) 
     1228        yield eq, "str", r(code, x="foo") 
     1229        yield eq, "str", r(code, x=u"foo") 
     1230        yield eq, "date", r(code, x=datetime.datetime.now()) 
     1231        yield eq, "date", r(code, x=datetime.date.today()) 
     1232        yield eq, "list", r(code, x=(1, 2)) 
     1233        yield eq, "list", r(code, x=[1, 2]) 
     1234        yield eq, "list", r(code, x=PseudoList([1, 2])) 
     1235        yield eq, "dict", r(code, x={1: 2}) 
     1236        yield eq, "dict", r(code, x=PseudoDict({1: 2})) 
     1237        yield eq, "template", r(code, x=ul4c.compile("")) 
     1238        yield eq, "color", r(code, x=color.red) 
     1239 
     1240 
     1241def test_function_reversed(): 
    13181242    code = u"<?for i in reversed(x)?>(<?print i?>)<?end for?>" 
    13191243 
    1320     with raises("reversed.*unknown"): 
    1321         r(u"<?print reversed()?>") 
    1322     with raises("reversed.*unknown"): 
    1323         r(u"<?print reversed(1, 2)?>") 
    1324     assert "(3)(2)(1)" == r(code, x="123") 
    1325     assert "(3)(2)(1)" == r(code, x=[1, 2, 3]) 
    1326     assert "(3)(2)(1)" == r(code, x=(1, 2, 3)) 
    1327  
    1328  
    1329 @with_all_renderers 
    1330 def test_function_rgb(r): 
    1331     assert "#369" == r("<?print repr(rgb(0.2, 0.4, 0.6))?>") 
    1332     assert "#369c" == r("<?print repr(rgb(0.2, 0.4, 0.6, 0.8))?>") 
    1333  
    1334  
    1335 @with_all_renderers 
    1336 def test_function_hls(r): 
    1337     assert "#fff" == r("<?print repr(hls(0, 1, 0))?>") 
    1338     assert "#fff0" == r("<?print repr(hls(0, 1, 0, 0))?>") 
    1339  
    1340  
    1341 @with_all_renderers 
    1342 def test_function_hsv(r): 
    1343     assert "#fff" == r("<?print repr(hsv(0, 0, 1))?>") 
    1344     assert "#fff0" == r("<?print repr(hsv(0, 0, 1, 0))?>") 
    1345  
    1346  
    1347 @with_all_renderers 
    1348 def test_method_upper(r): 
    1349     assert "GURK" == r(u"<?print 'gurk'.upper()?>") 
    1350  
    1351  
    1352 @with_all_renderers 
    1353 def test_method_lower(r): 
    1354     assert "gurk" == r(u"<?print 'GURK'.lower()?>") 
    1355  
    1356  
    1357 @with_all_renderers 
    1358 def test_method_capitalize(r): 
    1359     assert "Gurk" == r(u"<?print 'gURK'.capitalize()?>") 
    1360  
    1361  
    1362 @with_all_renderers 
    1363 def test_method_startswith(r): 
    1364     assert "True" == r(u"<?print 'gurkhurz'.startswith('gurk')?>") 
    1365     assert "False" == r(u"<?print 'gurkhurz'.startswith('hurz')?>") 
    1366  
    1367  
    1368 @with_all_renderers 
    1369 def test_method_endswith(r): 
    1370     assert "True" == r(u"<?print 'gurkhurz'.endswith('hurz')?>") 
    1371     assert "False" == r(u"<?print 'gurkhurz'.endswith('gurk')?>") 
    1372  
    1373  
    1374 @with_all_renderers 
    1375 def test_method_strip(r): 
    1376     assert "gurk" == r(r"<?print ' \t\r\ngurk \t\r\n'.strip()?>") 
    1377     assert "gurk" == r(r"<?print 'xyzzygurkxyzzy'.strip('xyz')?>") 
    1378  
    1379  
    1380 @with_all_renderers 
    1381 def test_method_lstrip(r): 
    1382     assert "gurk \t\r\n" == r(ur"<?print ' \t\r\ngurk \t\r\n'.lstrip()?>") 
    1383     assert "gurkxyzzy" == r(ur"<?print 'xyzzygurkxyzzy'.lstrip('xyz')?>") 
    1384  
    1385  
    1386 @with_all_renderers 
    1387 def test_method_rstrip(r): 
    1388     assert " \t\r\ngurk" == r(ur"<?print ' \t\r\ngurk \t\r\n'.rstrip()?>") 
    1389     assert "xyzzygurk" == r(ur"<?print 'xyzzygurkxyzzy'.rstrip('xyz')?>") 
    1390  
    1391  
    1392 @with_all_renderers 
    1393 def test_method_split(r): 
    1394     assert "(g)(u)(r)(k)" == r(ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split()?>(<?print item?>)<?end for?>") 
    1395     assert "(g)(u \t\r\nr \t\r\nk \t\r\n)" == r(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?>") 
    1396     assert "()(g)(u)(r)(k)()" == r(ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx')?>(<?print item?>)<?end for?>") 
    1397     assert "()(g)(uxxrxxkxx)" == r(ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx', 2)?>(<?print item?>)<?end for?>") 
    1398  
    1399  
    1400 @with_all_renderers 
    1401 def test_method_rsplit(r): 
    1402     assert "(g)(u)(r)(k)" == r(ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.rsplit()?>(<?print item?>)<?end for?>") 
    1403     assert "( \t\r\ng \t\r\nu \t\r\nr)(k)" == r(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?>") 
    1404     assert "()(g)(u)(r)(k)()" == r(ur"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx')?>(<?print item?>)<?end for?>") 
    1405     assert "(xxgxxuxxr)(k)()" == r(ur"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx', 2)?>(<?print item?>)<?end for?>") 
    1406  
    1407  
    1408 @with_all_renderers 
    1409 def test_method_replace(r): 
    1410     assert 'goork' == r(ur"<?print 'gurk'.replace('u', 'oo')?>") 
    1411  
    1412  
    1413 @with_all_renderers 
    1414 def test_method_render(r): 
    1415     t = ul4c.compile(u'(<?print data?>)') 
    1416     assert '(GURK)' == r(u"<?print t.render(data='gurk').upper()?>", t=t) 
    1417     assert '(GURK)' == r(u"<?print t.render(**{'data': 'gurk'}).upper()?>", t=t) 
    1418  
    1419     t = ul4c.compile(u'(gurk)') 
    1420     assert '(GURK)' == r(u"<?print t.render().upper()?>", t=t) 
    1421  
    1422  
    1423 @with_all_renderers 
    1424 def test_method_format(r): 
     1244    for r in all_renderers: 
     1245        yield raises, "reversed.*unknown", r(u"<?print reversed()?>") 
     1246        yield raises, "reversed.*unknown", r(u"<?print reversed(1, 2)?>") 
     1247        yield eq, "(3)(2)(1)", r(code, x="123") 
     1248        yield eq, "(3)(2)(1)", r(code, x=[1, 2, 3]) 
     1249        yield eq, "(3)(2)(1)", r(code, x=(1, 2, 3)) 
     1250 
     1251 
     1252def test_function_rgb(): 
     1253    for r in all_renderers: 
     1254        yield eq, "#369", r("<?print repr(rgb(0.2, 0.4, 0.6))?>") 
     1255        yield eq, "#369c", r("<?print repr(rgb(0.2, 0.4, 0.6, 0.8))?>") 
     1256 
     1257 
     1258def test_function_hls(): 
     1259    for r in all_renderers: 
     1260        yield eq, "#fff", r("<?print repr(hls(0, 1, 0))?>") 
     1261        yield eq, "#fff0", r("<?print repr(hls(0, 1, 0, 0))?>") 
     1262 
     1263 
     1264def test_function_hsv(): 
     1265    for r in all_renderers: 
     1266        yield eq, "#fff", r("<?print repr(hsv(0, 0, 1))?>") 
     1267        yield eq, "#fff0", r("<?print repr(hsv(0, 0, 1, 0))?>") 
     1268 
     1269 
     1270def test_method_upper(): 
     1271    for r in all_renderers: 
     1272        yield eq, "GURK", r(u"<?print 'gurk'.upper()?>") 
     1273 
     1274 
     1275def test_method_lower(): 
     1276    for r in all_renderers: 
     1277        yield eq, "gurk", r(u"<?print 'GURK'.lower()?>") 
     1278 
     1279 
     1280def test_method_capitalize(): 
     1281    for r in all_renderers: 
     1282        yield eq, "Gurk", r(u"<?print 'gURK'.capitalize()?>") 
     1283 
     1284 
     1285def test_method_startswith(): 
     1286    for r in all_renderers: 
     1287        yield eq, "True", r(u"<?print 'gurkhurz'.startswith('gurk')?>") 
     1288        yield eq, "False", r(u"<?print 'gurkhurz'.startswith('hurz')?>") 
     1289 
     1290 
     1291def test_method_endswith(): 
     1292    for r in all_renderers: 
     1293        yield eq, "True", r(u"<?print 'gurkhurz'.endswith('hurz')?>") 
     1294        yield eq, "False", r(u"<?print 'gurkhurz'.endswith('gurk')?>") 
     1295 
     1296 
     1297def test_method_strip(): 
     1298    for r in all_renderers: 
     1299        yield eq, "gurk", r(r"<?print ' \t\r\ngurk \t\r\n'.strip()?>") 
     1300        yield eq, "gurk", r(r"<?print 'xyzzygurkxyzzy'.strip('xyz')?>") 
     1301 
     1302 
     1303def test_method_lstrip(): 
     1304    for r in all_renderers: 
     1305        yield eq, "gurk \t\r\n", r(ur"<?print ' \t\r\ngurk \t\r\n'.lstrip()?>") 
     1306        yield eq, "gurkxyzzy", r(ur"<?print 'xyzzygurkxyzzy'.lstrip('xyz')?>") 
     1307 
     1308 
     1309def test_method_rstrip(): 
     1310    for r in all_renderers: 
     1311        yield eq, " \t\r\ngurk", r(ur"<?print ' \t\r\ngurk \t\r\n'.rstrip()?>") 
     1312        yield eq, "xyzzygurk", r(ur"<?print 'xyzzygurkxyzzy'.rstrip('xyz')?>") 
     1313 
     1314 
     1315def test_method_split(): 
     1316    for r in all_renderers: 
     1317        yield eq, "(g)(u)(r)(k)", r(ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split()?>(<?print item?>)<?end for?>") 
     1318        yield eq, "(g)(u \t\r\nr \t\r\nk \t\r\n)", r(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?>") 
     1319        yield eq, "()(g)(u)(r)(k)()", r(ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx')?>(<?print item?>)<?end for?>") 
     1320        yield eq, "()(g)(uxxrxxkxx)", r(ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx', 2)?>(<?print item?>)<?end for?>") 
     1321 
     1322 
     1323def test_method_rsplit(): 
     1324    data = [ 
     1325        (' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n',), 
     1326        (' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n', None, 1), 
     1327        ('xxgxxuxxrxxkxx', 'xx'), 
     1328        ('xxgxxuxxrxxkxx', 'xx', 2), 
     1329    ] 
     1330    for r in all_renderers: 
     1331        for args in data: 
     1332            obj = args[0] 
     1333            args = args[1:] 
     1334            expected = "".join("({})".format(f) for f in obj.rsplit(*args)) 
     1335            code = ur"<?for item in {}.rsplit({})?>(<?print item?>)<?end for?>".format(ul4c._repr(obj), ", ".join(ul4c._repr(arg) for arg in args)) 
     1336            yield eq, expected, r(code) 
     1337 
     1338 
     1339def test_method_replace(): 
     1340    for r in all_renderers: 
     1341        yield eq, 'goork', r(ur"<?print 'gurk'.replace('u', 'oo')?>") 
     1342 
     1343 
     1344def test_method_render(): 
     1345    for r in all_renderers: 
     1346        t = ul4c.compile(u'(<?print data?>)') 
     1347        yield eq, '(GURK)', r(u"<?print t.render(data='gurk').upper()?>", t=t) 
     1348        yield eq, '(GURK)', r(u"<?print t.render(**{'data': 'gurk'}).upper()?>", t=t) 
     1349 
     1350        t = ul4c.compile(u'(gurk)') 
     1351        yield eq, '(GURK)', r(u"<?print t.render().upper()?>", t=t) 
     1352 
     1353 
     1354def test_method_format(): 
    14251355    t = datetime.datetime(2010, 11, 2, 12, 34, 56, 987000) 
    1426     format = "%Y-%m-%d %H:%M:%S.%f %a %A %b %B %% %I %j %p %U %w %W %y" 
    1427     assert t.strftime(format) == r(u"<?print data.format('{}')?>".format(format), data=t) 
    1428  
    1429  
    1430 @with_all_renderers 
    1431 def test_method_isoformat(r): 
     1356    for r in all_renderers: 
     1357        format = ("%Y", "%m", "%d", "%H", "%M", "%S", "%f", "%a", "%A", "%b", "%B", "%I", "%j", "%p", "%U", "%W", "%y", "%%") 
     1358        if r is not RenderJava: 
     1359            format += ("%c", "%w", "%x", "%X") 
     1360        for char in format: 
     1361            yield eq, t.strftime(char), r(u"<?print data.format('{}')?>".format(char), data=t) 
     1362 
     1363 
     1364def test_method_isoformat(): 
    14321365    t = datetime.datetime(2010, 02, 22, 12, 34, 56) 
    1433     assert 'Mon, 22 Feb 2010 12:34:56 GMT' == r(ur"<?print data.mimeformat()?>", data=t) 
    1434  
    1435  
    1436 @with_all_renderers 
    1437 def test_method_get(r): 
    1438     assert "42" == r(u"<?print {}.get('foo', 42)?>") 
    1439     assert "17" == r(u"<?print {'foo': 17}.get('foo', 42)?>") 
    1440     assert "" == r(u"<?print {}.get('foo')?>") 
    1441     assert "17" == r(u"<?print {'foo': 17}.get('foo')?>") 
    1442  
    1443  
    1444 @with_all_renderers 
    1445 def test_method_r_g_b_a(r): 
    1446     assert '0x11' == r(u'<?code c = #123?><?print hex(c.r())?>') 
    1447     assert '0x22' == r(u'<?code c = #123?><?print hex(c.g())?>') 
    1448     assert '0x33' == r(u'<?code c = #123?><?print hex(c.b())?>') 
    1449     assert '0xff' == r(u'<?code c = #123?><?print hex(c.a())?>') 
    1450  
    1451  
    1452 @with_all_renderers 
    1453 def test_method_hls(r): 
    1454     assert '0' == r(u'<?code c = #fff?><?print int(c.hls()[0])?>') 
    1455     assert '1' == r(u'<?code c = #fff?><?print int(c.hls()[1])?>') 
    1456     assert '0' == r(u'<?code c = #fff?><?print int(c.hls()[2])?>') 
    1457  
    1458  
    1459 @with_all_renderers 
    1460 def test_method_hlsa(r): 
    1461     assert '0' == r(u'<?code c = #fff?><?print int(c.hlsa()[0])?>') 
    1462     assert '1' == r(u'<?code c = #fff?><?print int(c.hlsa()[1])?>') 
    1463     assert '0' == r(u'<?code c = #fff?><?print int(c.hlsa()[2])?>') 
    1464     assert '1' == r(u'<?code c = #fff?><?print int(c.hlsa()[3])?>') 
    1465  
    1466  
    1467 @with_all_renderers 
    1468 def test_method_hsv(r): 
    1469     assert '0' == r(u'<?code c = #fff?><?print int(c.hsv()[0])?>') 
    1470     assert '0' == r(u'<?code c = #fff?><?print int(c.hsv()[1])?>') 
    1471     assert '1' == r(u'<?code c = #fff?><?print int(c.hsv()[2])?>') 
    1472  
    1473  
    1474 @with_all_renderers 
    1475 def test_method_hsva(r): 
    1476     assert '0' == r(u'<?code c = #fff?><?print int(c.hsva()[0])?>') 
    1477     assert '0' == r(u'<?code c = #fff?><?print int(c.hsva()[1])?>') 
    1478     assert '1' == r(u'<?code c = #fff?><?print int(c.hsva()[2])?>') 
    1479     assert '1' == r(u'<?code c = #fff?><?print int(c.hsva()[3])?>') 
    1480  
    1481  
    1482 @with_all_renderers 
    1483 def test_method_lum(r): 
    1484     assert 'True' == r(u'<?print #fff.lum() == 1?>') 
    1485  
    1486  
    1487 @with_all_renderers 
    1488 def test_method_withlum(r): 
    1489     assert '#fff' == r(u'<?print #000.withlum(1)?>') 
    1490  
    1491  
    1492 @with_all_renderers 
    1493 def test_method_witha(r): 
    1494     assert '#0063a82a' == r(u'<?print repr(#0063a8.witha(42))?>') 
    1495  
    1496  
    1497 @with_all_renderers 
    1498 def test_method_join(r): 
    1499     assert '1,2,3,4' == r(u'<?print ",".join("1234")?>') 
    1500     assert '1,2,3,4' == r(u'<?print ",".join([1, 2, 3, 4])?>') 
    1501  
    1502  
    1503 @with_all_renderers 
    1504 def test_method_find(r): 
    1505     assert '-1' == r(u'<?print s.find("ks")?>', s="gurkgurk") 
    1506     assert '2' == r(u'<?print s.find("rk")?>', s="gurkgurk") 
    1507     assert '2' == r(u'<?print s.find("rk", 2)?>', s="gurkgurk") 
    1508     assert '2' == r(u'<?print s.find("rk", 2, 4)?>', s="gurkgurk") 
    1509     assert '6' == r(u'<?print s.find("rk", 4, 8)?>', s="gurkgurk") 
    1510     assert '-1' == r(u'<?print s.find("rk", 2, 3)?>', s="gurkgurk") 
    1511     assert '-1' == r(u'<?print s.find("rk", 7)?>', s="gurkgurk") 
    1512  
    1513  
    1514 @with_all_renderers 
    1515 def test_method_rfind(r): 
    1516     assert '-1' == r(u'<?print s.rfind("ks")?>', s="gurkgurk") 
    1517     assert '6' == r(u'<?print s.rfind("rk")?>', s="gurkgurk") 
    1518     assert '6' == r(u'<?print s.rfind("rk", 2)?>', s="gurkgurk") 
    1519     assert '2' == r(u'<?print s.rfind("rk", 2, 4)?>', s="gurkgurk") 
    1520     assert '6' == r(u'<?print s.rfind("rk", 4, 8)?>', s="gurkgurk") 
    1521     assert '-1' == r(u'<?print s.rfind("rk", 2, 3)?>', s="gurkgurk") 
    1522     assert '-1' == r(u'<?print s.rfind("rk", 7)?>', s="gurkgurk") 
    1523  
    1524  
    1525 @with_all_renderers 
    1526 def test_method_day(r): 
    1527     assert '12' == r(u'<?print @2010-05-12T.day()?>') 
    1528     assert '12' == r(u'<?print d.day()?>', d=datetime.date(2010, 5, 12)) 
    1529  
    1530  
    1531 @with_all_renderers 
    1532 def test_method_month(r): 
    1533     assert '5' == r(u'<?print @2010-05-12T.month()?>') 
    1534     assert '5' == r(u'<?print d.month()?>', d=datetime.date(2010, 5, 12)) 
    1535  
    1536  
    1537 @with_all_renderers 
    1538 def test_method_year(r): 
    1539     assert '5' == r(u'<?print @2010-05-12T.month()?>') 
    1540     assert '5' == r(u'<?print d.month()?>', d=datetime.date(2010, 5, 12)) 
    1541  
    1542  
    1543 @with_all_renderers 
    1544 def test_method_hour(r): 
    1545     assert '16' == r(u'<?print @2010-05-12T16:47:56.hour()?>') 
    1546     assert '16' == r(u'<?print d.hour()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
    1547  
    1548  
    1549 @with_all_renderers 
    1550 def test_method_minute(r): 
    1551     assert '47' == r(u'<?print @2010-05-12T16:47:56.minute()?>') 
    1552     assert '47' == r(u'<?print d.minute()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
    1553  
    1554  
    1555 @with_all_renderers 
    1556 def test_method_second(r): 
    1557     assert '56' == r(u'<?print @2010-05-12T16:47:56.second()?>') 
    1558     assert '56' == r(u'<?print d.second()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
    1559  
    1560  
    1561 @with_all_renderers 
    1562 def test_method_microsecond(r): 
    1563     assert '123000' == r(u'<?print @2010-05-12T16:47:56.123000.microsecond()?>') 
    1564     assert '123000' == r(u'<?print d.microsecond()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56, 123000)) 
    1565  
    1566  
    1567 @with_all_renderers 
    1568 def test_method_weekday(r): 
    1569     assert '2' == r(u'<?print @2010-05-12T.weekday()?>') 
    1570     assert '2' == r(u'<?print d.weekday()?>', d=datetime.date(2010, 5, 12)) 
    1571  
    1572  
    1573 @with_all_renderers 
    1574 def test_method_yearday(r): 
    1575     assert '1' == r(u'<?print @2010-01-01T.yearday()?>') 
    1576     assert '366' == r(u'<?print @2008-12-31T.yearday()?>') 
    1577     assert '365' == r(u'<?print @2010-12-31T.yearday()?>') 
    1578     assert '132' == r(u'<?print @2010-05-12T.yearday()?>') 
    1579     assert '132' == r(u'<?print @2010-05-12T16:47:56.yearday()?>') 
    1580     assert '132' == r(u'<?print d.yearday()?>', d=datetime.date(2010, 5, 12)) 
    1581     assert '132' == r(u'<?print d.yearday()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
    1582  
    1583  
    1584 @with_all_renderers 
    1585 def test_render(r): 
     1366    for r in all_renderers: 
     1367        yield eq, 'Mon, 22 Feb 2010 12:34:56 GMT', r(ur"<?print data.mimeformat()?>", data=t) 
     1368 
     1369 
     1370def test_method_get(): 
     1371    for r in all_renderers: 
     1372        yield eq, "42", r(u"<?print {}.get('foo', 42)?>") 
     1373        yield eq, "17", r(u"<?print {'foo': 17}.get('foo', 42)?>") 
     1374        yield eq, "", r(u"<?print {}.get('foo')?>") 
     1375        yield eq, "17", r(u"<?print {'foo': 17}.get('foo')?>") 
     1376 
     1377 
     1378def test_method_r_g_b_a(): 
     1379    for r in all_renderers: 
     1380        yield eq, '0x11', r(u'<?code c = #123?><?print hex(c.r())?>') 
     1381        yield eq, '0x22', r(u'<?code c = #123?><?print hex(c.g())?>') 
     1382        yield eq, '0x33', r(u'<?code c = #123?><?print hex(c.b())?>') 
     1383        yield eq, '0xff', r(u'<?code c = #123?><?print hex(c.a())?>') 
     1384 
     1385 
     1386def test_method_hls(): 
     1387    for r in all_renderers: 
     1388        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hls()[0])?>') 
     1389        yield eq, '1', r(u'<?code c = #fff?><?print int(c.hls()[1])?>') 
     1390        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hls()[2])?>') 
     1391 
     1392 
     1393def test_method_hlsa(): 
     1394    for r in all_renderers: 
     1395        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hlsa()[0])?>') 
     1396        yield eq, '1', r(u'<?code c = #fff?><?print int(c.hlsa()[1])?>') 
     1397        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hlsa()[2])?>') 
     1398        yield eq, '1', r(u'<?code c = #fff?><?print int(c.hlsa()[3])?>') 
     1399 
     1400 
     1401def test_method_hsv(): 
     1402    for r in all_renderers: 
     1403        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hsv()[0])?>') 
     1404        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hsv()[1])?>') 
     1405        yield eq, '1', r(u'<?code c = #fff?><?print int(c.hsv()[2])?>') 
     1406 
     1407 
     1408def test_method_hsva(): 
     1409    for r in all_renderers: 
     1410        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hsva()[0])?>') 
     1411        yield eq, '0', r(u'<?code c = #fff?><?print int(c.hsva()[1])?>') 
     1412        yield eq, '1', r(u'<?code c = #fff?><?print int(c.hsva()[2])?>') 
     1413        yield eq, '1', r(u'<?code c = #fff?><?print int(c.hsva()[3])?>') 
     1414 
     1415 
     1416def test_method_lum(): 
     1417    for r in all_renderers: 
     1418        yield eq, 'True', r(u'<?print #fff.lum() == 1?>') 
     1419 
     1420 
     1421def test_method_withlum(): 
     1422    for r in all_renderers: 
     1423        yield eq, '#fff', r(u'<?print #000.withlum(1)?>') 
     1424 
     1425 
     1426def test_method_witha(): 
     1427    for r in all_renderers: 
     1428        yield eq, '#0063a82a', r(u'<?print repr(#0063a8.witha(42))?>') 
     1429 
     1430 
     1431def test_method_join(): 
     1432    for r in all_renderers: 
     1433        yield eq, '1,2,3,4', r(u'<?print ",".join("1234")?>') 
     1434        yield eq, '1,2,3,4', r(u'<?print ",".join([1, 2, 3, 4])?>') 
     1435 
     1436 
     1437def test_method_find(): 
     1438    for r in all_renderers: 
     1439        yield eq, '-1', r(u'<?print s.find("ks")?>', s="gurkgurk") 
     1440        yield eq, '2', r(u'<?print s.find("rk")?>', s="gurkgurk") 
     1441        yield eq, '2', r(u'<?print s.find("rk", 2)?>', s="gurkgurk") 
     1442        yield eq, '2', r(u'<?print s.find("rk", 2, 4)?>', s="gurkgurk") 
     1443        yield eq, '6', r(u'<?print s.find("rk", 4, 8)?>', s="gurkgurk") 
     1444        yield eq, '-1', r(u'<?print s.find("rk", 2, 3)?>', s="gurkgurk") 
     1445        yield eq, '-1', r(u'<?print s.find("rk", 7)?>', s="gurkgurk") 
     1446 
     1447 
     1448def test_method_rfind(): 
     1449    for r in all_renderers: 
     1450        yield eq, '-1', r(u'<?print s.rfind("ks")?>', s="gurkgurk") 
     1451        yield eq, '6', r(u'<?print s.rfind("rk")?>', s="gurkgurk") 
     1452        yield eq, '6', r(u'<?print s.rfind("rk", 2)?>', s="gurkgurk") 
     1453        yield eq, '2', r(u'<?print s.rfind("rk", 2, 4)?>', s="gurkgurk") 
     1454        yield eq, '6', r(u'<?print s.rfind("rk", 4, 8)?>', s="gurkgurk") 
     1455        yield eq, '-1', r(u'<?print s.rfind("rk", 2, 3)?>', s="gurkgurk") 
     1456        yield eq, '-1', r(u'<?print s.rfind("rk", 7)?>', s="gurkgurk") 
     1457 
     1458 
     1459def test_method_day(): 
     1460    for r in all_renderers: 
     1461        yield eq, '12', r(u'<?print @2010-05-12T.day()?>') 
     1462        yield eq, '12', r(u'<?print d.day()?>', d=datetime.date(2010, 5, 12)) 
     1463 
     1464 
     1465def test_method_month(): 
     1466    for r in all_renderers: 
     1467        yield eq, '5', r(u'<?print @2010-05-12T.month()?>') 
     1468        yield eq, '5', r(u'<?print d.month()?>', d=datetime.date(2010, 5, 12)) 
     1469 
     1470 
     1471def test_method_year(): 
     1472    for r in all_renderers: 
     1473        yield eq, '5', r(u'<?print @2010-05-12T.month()?>') 
     1474        yield eq, '5', r(u'<?print d.month()?>', d=datetime.date(2010, 5, 12)) 
     1475 
     1476 
     1477def test_method_hour(): 
     1478    for r in all_renderers: 
     1479        yield eq, '16', r(u'<?print @2010-05-12T16:47:56.hour()?>') 
     1480        yield eq, '16', r(u'<?print d.hour()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
     1481 
     1482 
     1483def test_method_minute(): 
     1484    for r in all_renderers: 
     1485        yield eq, '47', r(u'<?print @2010-05-12T16:47:56.minute()?>') 
     1486        yield eq, '47', r(u'<?print d.minute()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
     1487 
     1488 
     1489def test_method_second(): 
     1490    for r in all_renderers: 
     1491        yield eq, '56', r(u'<?print @2010-05-12T16:47:56.second()?>') 
     1492        yield eq, '56', r(u'<?print d.second()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
     1493 
     1494 
     1495def test_method_microsecond(): 
     1496    for r in all_renderers: 
     1497        yield eq, '123000', r(u'<?print @2010-05-12T16:47:56.123000.microsecond()?>') 
     1498        yield eq, '123000', r(u'<?print d.microsecond()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56, 123000)) 
     1499 
     1500 
     1501def test_method_weekday(): 
     1502    for r in all_renderers: 
     1503        yield eq, '2', r(u'<?print @2010-05-12T.weekday()?>') 
     1504        yield eq, '2', r(u'<?print d.weekday()?>', d=datetime.date(2010, 5, 12)) 
     1505 
     1506 
     1507def test_method_yearday(): 
     1508    for r in all_renderers: 
     1509        yield eq, '1', r(u'<?print @2010-01-01T.yearday()?>') 
     1510        yield eq, '366', r(u'<?print @2008-12-31T.yearday()?>') 
     1511        yield eq, '365', r(u'<?print @2010-12-31T.yearday()?>') 
     1512        yield eq, '132', r(u'<?print @2010-05-12T.yearday()?>') 
     1513        yield eq, '132', r(u'<?print @2010-05-12T16:47:56.yearday()?>') 
     1514        yield eq, '132', r(u'<?print d.yearday()?>', d=datetime.date(2010, 5, 12)) 
     1515        yield eq, '132', r(u'<?print d.yearday()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
     1516 
     1517 
     1518def test_render(): 
    15861519    t = ul4c.compile(u'<?print prefix?><?print data?><?print suffix?>') 
    1587     assert '(f)(o)(o)' == r(u'<?for c in data?><?render t(data=c, prefix="(", suffix=")")?><?end for?>', t=t, data='foo') 
    1588     assert '(f)(o)(o)' == r(u'<?for c in data?><?render t(data=c, **{"prefix": "(", "suffix": ")"})?><?end for?>', t=t, data='foo') 
    1589  
    1590  
    1591 @with_all_renderers 
    1592 def test_render_var(r): 
     1520    for r in all_renderers: 
     1521        yield eq, '(f)(o)(o)', r(u'<?for c in data?><?render t(data=c, prefix="(", suffix=")")?><?end for?>', t=t, data='foo') 
     1522        yield eq, '(f)(o)(o)', r(u'<?for c in data?><?render t(data=c, **{"prefix": "(", "suffix": ")"})?><?end for?>', t=t, data='foo') 
     1523 
     1524 
     1525def test_render_var(): 
    15931526    t = ul4c.compile(u'<?code x += 1?><?print x?>') 
    1594     assert '42,43,42' == r(u'<?print x?>,<?render t(x=x)?>,<?print x?>', t=t, x=42) 
    1595  
    1596  
    1597 @with_all_renderers 
    1598 def test_def(r): 
    1599     assert 'foo' == r(u'<?def lower?><?print x.lower()?><?end def?><?print lower.render(x="FOO")?>') 
    1600  
    1601  
    1602 @with_all_renderers 
    1603 def test_parse(r): 
    1604     assert '42' == r(u'<?print data.Noner?>', data=dict(Noner=42)) 
    1605  
    1606  
    1607 @with_all_renderers 
    1608 def test_nested_exceptions(r): 
     1527    for r in all_renderers: 
     1528        yield eq, '42,43,42', r(u'<?print x?>,<?render t(x=x)?>,<?print x?>', t=t, x=42) 
     1529 
     1530 
     1531def test_def(): 
     1532    for r in all_renderers: 
     1533        yield eq, 'foo', r(u'<?def lower?><?print x.lower()?><?end def?><?print lower.render(x="FOO")?>') 
     1534 
     1535 
     1536def test_parse(): 
     1537    for r in all_renderers: 
     1538        yield eq, '42', r(u'<?print data.Noner?>', data=dict(Noner=42)) 
     1539 
     1540 
     1541def test_nested_exceptions(): 
    16091542    tmpl1 = ul4c.compile(u"<?print 2*x?>") 
    16101543    tmpl2 = ul4c.compile(u"<?render tmpl1(x=x)?>") 
    16111544    tmpl3 = ul4c.compile(u"<?render tmpl2(tmpl1=tmpl1, x=x)?>") 
    16121545 
    1613     if r is not renderjs: 
     1546    for r in all_python_renderers: 
    16141547        msg = "TypeError .*render tmpl3.*render tmpl2.*render tmpl1.*print 2.*unsupported operand type|.* \\* .* not supported" 
    1615         with raises(msg): 
    1616             r(u"<?render tmpl3(tmpl1=tmpl1, tmpl2=tmpl2, x=x)?>", tmpl1=tmpl1, tmpl2=tmpl2, tmpl3=tmpl3, x=None) 
    1617  
    1618  
    1619 @with_all_renderers 
    1620 def test_note(r): 
    1621     assert "foo" == r(u"f<?note This is?>o<?note a comment?>o") 
    1622  
    1623  
    1624 @with_all_renderers 
    1625 def test_templateattributes(r): 
    1626     if r not in (renderjs, renderjava): 
    1627         s = "<?print x?>" 
    1628         t = ul4c.compile(s) 
    1629         assert "<?" == r(u"<?print template.startdelim?>", template=t) 
    1630         assert "?>" == r(u"<?print template.enddelim?>", template=t) 
    1631         assert s == r(u"<?print template.source?>", template=t) 
    1632         assert "2" == r(u"<?print len(template.opcodes)?>", template=t) 
    1633         assert "loadvar" == r(u"<?print template.opcodes[0].code?>", template=t) 
    1634         assert "0" == r(u"<?print template.opcodes[0].r1?>", template=t) 
    1635         assert "" == r(u"<?print template.opcodes[0].r2?>", template=t) 
    1636         assert "x" == r(u"<?print template.opcodes[0].arg?>", template=t) 
    1637         assert s == r(u"<?code loc = template.opcodes[0].location?><?print template.source[loc.starttag:loc.endtag]?>", template=t) 
    1638         assert "x" == r(u"<?code loc = template.opcodes[0].location?><?print template.source[loc.startcode:loc.endcode]?>", template=t) 
     1548        yield raises, msg, r(u"<?render tmpl3(tmpl1=tmpl1, tmpl2=tmpl2, x=x)?>", tmpl1=tmpl1, tmpl2=tmpl2, tmpl3=tmpl3, x=None) 
     1549 
     1550 
     1551def test_note(): 
     1552    for r in all_renderers: 
     1553        yield eq, "foo", r(u"f<?note This is?>o<?note a comment?>o") 
     1554 
     1555 
     1556def test_templateattributes(): 
     1557    s = "<?print x?>" 
     1558    t = ul4c.compile(s) 
     1559 
     1560    for r in all_python_renderers: 
     1561        yield eq, "<?", r(u"<?print template.startdelim?>", template=t) 
     1562        yield eq, "?>", r(u"<?print template.enddelim?>", template=t) 
     1563        yield eq, s, r(u"<?print template.source?>", template=t) 
     1564        yield eq, "2", r(u"<?print len(template.opcodes)?>", template=t) 
     1565        yield eq, "loadvar", r(u"<?print template.opcodes[0].code?>", template=t) 
     1566        yield eq, "0", r(u"<?print template.opcodes[0].r1?>", template=t) 
     1567        yield eq, "", r(u"<?print template.opcodes[0].r2?>", template=t) 
     1568        yield eq, "x", r(u"<?print template.opcodes[0].arg?>", template=t) 
     1569        yield eq, s, r(u"<?code loc = template.opcodes[0].location?><?print template.source[loc.starttag:loc.endtag]?>", template=t) 
     1570        yield eq, "x", r(u"<?code loc = template.opcodes[0].location?><?print template.source[loc.startcode:loc.endcode]?>", template=t) 
    16391571 
    16401572