Changeset 4087:41976089e64e in livinglogic.python.xist

Show
Ignore:
Timestamp:
07/09/10 16:47:21 (9 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Use the new "with" form of py.test.raises() in the test suite.

This requires py 1.3.2.

Files:
10 modified

Legend:

Unmodified
Added
Removed
  • INSTALL.rst

    r4052 r4087  
    2020    *   `setuptools`_ (if you want to install this package as an egg); 
    2121 
    22     *   `py.test`_ (if you want to run the test suite) 
     22    *   `py.test`_ (if you want to run the test suite; at least version 1.3.2) 
    2323 
    2424    *   `execnet`_ (if you want to use ssh URLs) 
  • test/test_misc.py

    r4042 r4087  
    9595    assert misc.item(e, 0) == 1 
    9696    assert misc.item(e, -1) == 9 
    97     py.test.raises(IndexError, misc.item, e, -1) 
     97    with py.test.raises(IndexError): 
     98        misc.item(e, -1) 
    9899    assert misc.item(e, -1, 42) == 42 
    99100 
     
    102103 
    103104    e = iter(range(10)) 
    104     py.test.raises(IndexError, misc.item, e, 10) 
     105    with py.test.raises(IndexError): 
     106        misc.item(e, 10) 
    105107 
    106108    e = iter(range(10)) 
     
    114116 
    115117    e = iter(range(10)) 
    116     py.test.raises(IndexError, misc.item, e, -11) 
     118    with py.test.raises(IndexError): 
     119        misc.item(e, -11) 
    117120 
    118121    e = iter(range(10)) 
     
    122125 
    123126    # Wrong arguments 
    124     py.test.raises(TypeError, misc.item) 
    125     py.test.raises(TypeError, misc.item, []) 
    126     py.test.raises(TypeError, misc.item, 42, 42) 
     127    with py.test.raises(TypeError): 
     128        misc.item() 
     129    with py.test.raises(TypeError): 
     130        misc.item([]) 
     131    with py.test.raises(TypeError): 
     132        misc.item(42, 42) 
    127133 
    128134    # Non-negative index 
    129135    assert misc.item(iterable, 0), 17 
    130136    assert misc.item(iterable, 2), 37 
    131     py.test.raises(IndexError, misc.item, iterable, 3) 
     137    with py.test.raises(IndexError): 
     138        misc.item(iterable, 3) 
    132139    assert misc.item(iterable, 3, 42), 42 
    133140    assert misc.item(err(10), 9), 9 
    134     py.test.raises(SyntaxError, misc.item, err(10), 10) 
     141    with py.test.raises(SyntaxError): 
     142        misc.item(err(10), 10) 
    135143 
    136144    # Negative index 
    137145    assert misc.item(iterable, -1), 37 
    138146    assert misc.item(iterable, -3), 17 
    139     py.test.raises(IndexError, misc.item, iterable, -4) 
     147    with py.test.raises(IndexError): 
     148        misc.item(iterable, -4) 
    140149    assert misc.item(iterable, -4, 42), 42 
    141150    # iterator is always exhausted 
    142     py.test.raises(SyntaxError, misc.item, err(10), -1) 
     151    with py.test.raises(SyntaxError): 
     152        misc.item(err(10), -1) 
    143153 
    144154 
     
    149159 
    150160    e = iter([]) 
    151     py.test.raises(IndexError, misc.first, e) 
     161    with py.test.raises(IndexError): 
     162        misc.first(e) 
    152163 
    153164    e = iter([]) 
     
    158169    e = iter(range(10)) 
    159170    assert misc.last(e) == 9 
    160     py.test.raises(IndexError, misc.last, e) 
    161  
    162     e = iter([]) 
    163     py.test.raises(IndexError, misc.last, e) 
     171    with py.test.raises(IndexError): 
     172        misc.last(e) 
     173 
     174    e = iter([]) 
     175    with py.test.raises(IndexError): 
     176        misc.last(e) 
    164177 
    165178    e = iter([]) 
     
    188201    assert e.next() == 0 
    189202    assert e.next() == 1 
    190     py.test.raises(StopIteration, e.next) 
     203    with py.test.raises(StopIteration): 
     204        e.next() 
    191205 
    192206 
     
    196210    assert e[0] == 1 
    197211    assert e[-1] == 9 
    198     py.test.raises(IndexError, e.__getitem__, -1) 
     212    with py.test.raises(IndexError): 
     213        e[-1] 
    199214 
    200215 
     
    242257            pass 
    243258 
    244     py.test.raises(NotImplementedError, Bad().bad) 
     259    with py.test.raises(NotImplementedError): 
     260        Bad().bad() 
  • test/test_orasql.py

    r4037 r4087  
    205205def test_procedure_nonexistant(): 
    206206    db = orasql.connect(dbname) 
    207     py.test.raises(orasql.SQLObjectNotFoundError, orasql.Procedure("DOESNOTEXIST"), db.cursor()) 
     207    with py.test.raises(orasql.SQLObjectNotFoundError): 
     208        orasql.Procedure("DOESNOTEXIST")(db.cursor()) 
    208209 
    209210 
  • test/test_xist_basics.py

    r4052 r4087  
    6060        node.append(html.p.Attrs.id(7)) 
    6161        check_lenunicode(node, 7, u"1234567") 
    62         py.test.raises(TypeError, node.append, xml.Attrs(lang=8)) 
     62        with py.test.raises(TypeError): 
     63            node.append(xml.Attrs(lang=8)) 
    6364 
    6465 
     
    473474    assert u"withdef" in node.attrs 
    474475    assert u"withoutdef" not in node.attrs 
    475     py.test.raises(xsc.IllegalAttrError, node.attrs.__contains__, u"illegal") 
     476    with py.test.raises(xsc.IllegalAttrError): 
     477        u"illegal" in node.attrs 
    476478    node = Test(withdef=None) 
    477479    assert u"withdef" not in node.attrs 
     
    595597def test_allowedattr(): 
    596598    assert html.a.Attrs.allowedattr(u"href") is html.a.Attrs.href 
    597     py.test.raises(xsc.IllegalAttrError, html.a.Attrs.allowedattr, u"gurk") 
     599    with py.test.raises(xsc.IllegalAttrError): 
     600        html.a.Attrs.allowedattr(u"gurk") 
    598601    assert html.a.Attrs.allowedattr(xml.Attrs.lang) is xml.Attrs.lang 
    599602 
     
    692695            assert unicode(i.next()) == u"foo" 
    693696            assert unicode(i.next()) == u"baz" 
    694             py.test.raises(StopIteration, i.next) 
     697            with py.test.raises(StopIteration): 
     698                i.next() 
    695699 
    696700        # list 
     
    740744            node[[0, 1, attr]] = u"hurz" 
    741745            assert unicode(node[[0, 1, attr]]) == u"hurz" 
    742             py.test.raises(ValueError, node.__setitem__, [], None) 
    743             py.test.raises(ValueError, node.__delitem__, []) 
     746            with py.test.raises(ValueError): 
     747                node[[]] = None 
     748            with py.test.raises(ValueError): 
     749                del node[[]] 
    744750 
    745751 
  • test/test_xist_detox.py

    r4041 r4087  
    141141            +detox.end(u"for") 
    142142 
    143     py.test.raises(SyntaxError, makeoutput, e, u"gurk") 
     143    with py.test.raises(SyntaxError): 
     144        makeoutput(e, u"gurk") 
    144145 
    145146 
  • test/test_xist_parse.py

    r4063 r4087  
    126126        w = recwarn.pop(xsc.RequiredAttrMissingWarning) 
    127127 
    128     py.test.raises(xsc.IllegalElementError, parse.tree, b'<Test required="foo"/>', parse.Expat(), parse.NS(xmlns), parse.Node()) 
     128    with py.test.raises(xsc.IllegalElementError): 
     129        parse.tree(b'<Test required="foo"/>', parse.Expat(), parse.NS(xmlns), parse.Node()) 
    129130 
    130131 
     
    223224 
    224225    s = b"<a><a xmlns={0!r}/></a>".format(ihtml.xmlns) 
    225     py.test.raises(xsc.IllegalElementError, parse.tree, s, parse.Expat(), parse.NS(html), parse.Node(pool=xsc.Pool(ihtml))) 
     226    with py.test.raises(xsc.IllegalElementError): 
     227        parse.tree(s, parse.Expat(), parse.NS(html), parse.Node(pool=xsc.Pool(ihtml))) 
    226228    e = parse.tree(s, parse.Expat(), parse.NS(html), parse.Node(pool=xsc.Pool(html, ihtml))) 
    227229    assert isinstance(e[0], html.a) 
     
    231233    e = parse.tree(s, parse.Expat(ns=True), parse.Node(pool=xsc.Pool(doc.z))) 
    232234    assert isinstance(e[0], doc.z) 
    233     py.test.raises(xsc.IllegalElementError, parse.tree, s, parse.Expat(ns=True), parse.Node(pool=xsc.Pool())) 
     235    with py.test.raises(xsc.IllegalElementError): 
     236        parse.tree(s, parse.Expat(ns=True), parse.Node(pool=xsc.Pool())) 
    234237 
    235238 
     
    349352 
    350353def test_expat_events_on_exception(): 
    351     # Test that all collected events are output, before an exception is thrown 
     354    # Test that all collected events are output before an exception is thrown 
    352355    i = parse.events(b"<x/>schrott", parse.Expat()) 
    353356    assert i.next() == (u"url", url.URL("STRING")) 
     
    357360    assert i.next() == (u"position", (0, 4)) 
    358361    assert i.next() == (u"endtag", u"x") 
    359     py.test.raises(expat.ExpatError, i.next) 
     362    with py.test.raises(expat.ExpatError): 
     363        i.next() 
    360364 
    361365 
     
    371375    assert i.next() == (u"position", (0, 40)) 
    372376    assert i.next() == (u"endtag", u"a") 
    373     py.test.raises(StopIteration, i.next) 
     377    with py.test.raises(StopIteration): 
     378        i.next() 
    374379 
    375380 
     
    382387    assert i.next() == (u"text", u"gurk & hurz & hinz & kunz") 
    383388    assert i.next() == (u"endtag", u"a") 
    384     py.test.raises(StopIteration, i.next) 
    385  
     389    with py.test.raises(StopIteration): 
     390        i.next() 
     391 
  • test/test_xist_pool.py

    r4041 r4087  
    1919    # empty pool 
    2020    r = xsc.Pool() 
    21     py.test.raises(xsc.IllegalElementError, r.elementclass, u"a", html) 
    22     py.test.raises(xsc.IllegalElementError, r.elementclass_xml, u"a", html) 
     21    with py.test.raises(xsc.IllegalElementError): 
     22        r.elementclass(u"a", html) 
     23    with py.test.raises(xsc.IllegalElementError): 
     24        r.elementclass_xml(u"a", html) 
    2325 
    2426    # register one element 
     
    2628    assert r.elementclass(u"a", html) is html.a 
    2729    assert r.elementclass_xml(u"a", html) is html.a 
    28     py.test.raises(xsc.IllegalElementError, r.elementclass, u"b", html) 
    29     py.test.raises(xsc.IllegalElementError, r.elementclass_xml, u"b", html) 
     30    with py.test.raises(xsc.IllegalElementError): 
     31        r.elementclass(u"b", html) 
     32    with py.test.raises(xsc.IllegalElementError): 
     33        r.elementclass_xml(u"b", html) 
    3034 
    3135    # register a module 
     
    3539    assert r.elementclass(u"b", html) is html.b 
    3640    assert r.elementclass_xml(u"b", html) is html.b 
    37     py.test.raises(xsc.IllegalElementError, r.elementclass, u"c", html) 
    38     py.test.raises(xsc.IllegalElementError, r.elementclass_xml, u"c", html) 
     41    with py.test.raises(xsc.IllegalElementError): 
     42        r.elementclass(u"c", html) 
     43    with py.test.raises(xsc.IllegalElementError): 
     44        r.elementclass_xml(u"c", html) 
    3945 
    4046    # procinsts 
     
    4450    assert r.procinst(u"php", u"foo") == php.php(u"foo") 
    4551    assert r.procinst_xml(u"php", u"foo") == php.php(u"foo") 
    46     py.test.raises(xsc.IllegalProcInstError, r.procinstclass, u"nophp") 
    47     py.test.raises(xsc.IllegalProcInstError, r.procinstclass_xml, u"nophp") 
     52    with py.test.raises(xsc.IllegalProcInstError): 
     53        r.procinstclass(u"nophp") 
     54    with py.test.raises(xsc.IllegalProcInstError): 
     55        r.procinstclass_xml(u"nophp") 
    4856 
    4957    # entities 
     
    5361    assert r.entity(u"xist") == abbr.xist() 
    5462    assert r.entity_xml(u"xist") == abbr.xist() 
    55     py.test.raises(xsc.IllegalEntityError, r.entityclass, u"dontxist") 
    56     py.test.raises(xsc.IllegalEntityError, r.entityclass_xml, u"dontxist") 
     63    with py.test.raises(xsc.IllegalEntityError): 
     64        r.entityclass(u"dontxist") 
     65    with py.test.raises(xsc.IllegalEntityError): 
     66        r.entityclass_xml(u"dontxist") 
    5767 
    5868    # charrefs 
     
    6676    assert r.charref(ord(u"ö")) == chars.ouml() 
    6777    assert r.charref_xml(ord(u"ö")) == chars.ouml() 
    68     py.test.raises(xsc.IllegalEntityError, r.charrefclass, u"nothing") 
    69     py.test.raises(xsc.IllegalEntityError, r.charrefclass_xml, u"nothing") 
     78    with py.test.raises(xsc.IllegalEntityError): 
     79        r.charrefclass(u"nothing") 
     80    with py.test.raises(xsc.IllegalEntityError): 
     81        r.charrefclass_xml(u"nothing") 
    7082 
    7183 
     
    113125    assert r.element(u"element", u"nix") == element() 
    114126    assert r.element_xml(u"-element", u"nix") == element() 
    115     py.test.raises(xsc.IllegalElementError, r.elementclass, u"-element", u"nix") 
    116     py.test.raises(xsc.IllegalElementError, r.elementclass_xml, u"element", u"nix") 
    117     # make sure that the default pool didn't pick up the new class 
    118     py.test.raises(xsc.IllegalElementError, xsc.threadlocalpool.pool.elementclass, u"element", u"nix") 
    119     py.test.raises(xsc.IllegalElementError, xsc.threadlocalpool.pool.elementclass_xml, u"-element", u"nix") 
     127    with py.test.raises(xsc.IllegalElementError): 
     128        r.elementclass(u"-element", u"nix") 
     129    with py.test.raises(xsc.IllegalElementError): 
     130        r.elementclass_xml(u"element", u"nix") 
     131    # make sure that the default pool didn't pick up the new class 
     132    with py.test.raises(xsc.IllegalElementError): 
     133        xsc.threadlocalpool.pool.elementclass(u"element", u"nix") 
     134    with py.test.raises(xsc.IllegalElementError): 
     135        xsc.threadlocalpool.pool.elementclass_xml(u"-element", u"nix") 
    120136 
    121137    # procinsts 
     
    124140    assert r.procinst(u"procinst", u"spam") == procinst(u"spam") 
    125141    assert r.procinst_xml(u"-procinst", u"spam") == procinst(u"spam") 
    126     py.test.raises(xsc.IllegalProcInstError, r.procinstclass, u"-procinst") 
    127     py.test.raises(xsc.IllegalProcInstError, r.procinstclass_xml, u"procinst") 
    128     # make sure that the default pool didn't pick up the new class 
    129     py.test.raises(xsc.IllegalProcInstError, xsc.threadlocalpool.pool.procinstclass, u"procinst") 
    130     py.test.raises(xsc.IllegalProcInstError, xsc.threadlocalpool.pool.procinstclass_xml, u"-procinst") 
     142    with py.test.raises(xsc.IllegalProcInstError): 
     143        r.procinstclass(u"-procinst") 
     144    with py.test.raises(xsc.IllegalProcInstError): 
     145        r.procinstclass_xml(u"procinst") 
     146    # make sure that the default pool didn't pick up the new class 
     147    with py.test.raises(xsc.IllegalProcInstError): 
     148        xsc.threadlocalpool.pool.procinstclass(u"procinst") 
     149    with py.test.raises(xsc.IllegalProcInstError): 
     150        xsc.threadlocalpool.pool.procinstclass_xml(u"-procinst") 
    131151 
    132152    # entities 
     
    135155    assert r.entity(u"entity") == entity() 
    136156    assert r.entity_xml(u"-entity") == entity() 
    137     py.test.raises(xsc.IllegalEntityError, r.entityclass, u"-entity") 
    138     py.test.raises(xsc.IllegalEntityError, r.entityclass_xml, u"entity") 
    139     # make sure that the default pool didn't pick up the new class 
    140     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.entityclass, u"entity") 
    141     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.entityclass_xml, u"-entity") 
     157    with py.test.raises(xsc.IllegalEntityError): 
     158        r.entityclass(u"-entity") 
     159    with py.test.raises(xsc.IllegalEntityError): 
     160        r.entityclass_xml(u"entity") 
     161    # make sure that the default pool didn't pick up the new class 
     162    with py.test.raises(xsc.IllegalEntityError): 
     163        xsc.threadlocalpool.pool.entityclass(u"entity") 
     164    with py.test.raises(xsc.IllegalEntityError): 
     165        xsc.threadlocalpool.pool.entityclass_xml(u"-entity") 
    142166    # the charref is an entity too 
    143167    assert r.entityclass(u"charref") is charref 
     
    145169    assert r.entity(u"charref") == charref() 
    146170    assert r.entity_xml(u"-charref") == charref() 
    147     py.test.raises(xsc.IllegalEntityError, r.entityclass, u"-charref") 
    148     py.test.raises(xsc.IllegalEntityError, r.entityclass_xml, u"charref") 
    149     # make sure that the default pool didn't pick up the new class 
    150     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.entityclass, u"charref") 
    151     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.entityclass_xml, u"-charref") 
     171    with py.test.raises(xsc.IllegalEntityError): 
     172        r.entityclass(u"-charref") 
     173    with py.test.raises(xsc.IllegalEntityError): 
     174        r.entityclass_xml(u"charref") 
     175    # make sure that the default pool didn't pick up the new class 
     176    with py.test.raises(xsc.IllegalEntityError): 
     177        xsc.threadlocalpool.pool.entityclass(u"charref") 
     178    with py.test.raises(xsc.IllegalEntityError): 
     179        xsc.threadlocalpool.pool.entityclass_xml(u"-charref") 
    152180 
    153181    # charrefs 
     
    160188    assert r.charref(42) == charref() 
    161189    assert r.charref_xml(42) == charref() 
    162     py.test.raises(xsc.IllegalEntityError, r.charrefclass, u"-charref") 
    163     py.test.raises(xsc.IllegalEntityError, r.charrefclass_xml, u"charref") 
    164     # make sure that the default pool didn't pick up the new class 
    165     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.charrefclass, u"charref") 
    166     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.charrefclass_xml, u"-charref") 
     190    with py.test.raises(xsc.IllegalEntityError): 
     191        r.charrefclass(u"-charref") 
     192    with py.test.raises(xsc.IllegalEntityError): 
     193        r.charrefclass_xml(u"charref") 
     194    # make sure that the default pool didn't pick up the new class 
     195    with py.test.raises(xsc.IllegalEntityError): 
     196        xsc.threadlocalpool.pool.charrefclass(u"charref") 
     197    with py.test.raises(xsc.IllegalEntityError): 
     198        xsc.threadlocalpool.pool.charrefclass_xml(u"-charref") 
    167199    # make sure that entity has not been register as a charref 
    168     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.charrefclass, u"entity") 
    169     py.test.raises(xsc.IllegalEntityError, xsc.threadlocalpool.pool.charrefclass_xml, u"-entity") 
     200    with py.test.raises(xsc.IllegalEntityError): 
     201        xsc.threadlocalpool.pool.charrefclass(u"entity") 
     202    with py.test.raises(xsc.IllegalEntityError): 
     203        xsc.threadlocalpool.pool.charrefclass_xml(u"-entity") 
    170204 
    171205    # attributes 
    172206    assert r.attrclass(u"attr", u"nix") is Attrs.attr 
    173207    assert r.attrclass_xml(u"-attr", u"nix") is Attrs.attr 
    174     py.test.raises(xsc.IllegalAttrError, r.attrclass, u"-attr", u"nix") 
    175     py.test.raises(xsc.IllegalAttrError, r.attrclass_xml, u"attr", u"nix") 
    176     # make sure that the default pool didn't pick up the new class 
    177     py.test.raises(xsc.IllegalAttrError, xsc.threadlocalpool.pool.attrclass, u"attr", u"nix") 
    178     py.test.raises(xsc.IllegalAttrError, xsc.threadlocalpool.pool.attrclass_xml, u"-attr", u"nix") 
     208    with py.test.raises(xsc.IllegalAttrError): 
     209        r.attrclass(u"-attr", u"nix") 
     210    with py.test.raises(xsc.IllegalAttrError): 
     211        r.attrclass_xml(u"attr", u"nix") 
     212    # make sure that the default pool didn't pick up the new class 
     213    with py.test.raises(xsc.IllegalAttrError): 
     214        xsc.threadlocalpool.pool.attrclass(u"attr", u"nix") 
     215    with py.test.raises(xsc.IllegalAttrError): 
     216        xsc.threadlocalpool.pool.attrclass_xml(u"-attr", u"nix") 
    179217 
    180218 
     
    234272 
    235273    assert p1.elementclass_xml(u"foo", u"nix") is foo1 
    236     py.test.raises(xsc.IllegalElementError, p1.elementclass, u"bar", u"nix") 
     274    with py.test.raises(xsc.IllegalElementError): 
     275        p1.elementclass(u"bar", u"nix") 
    237276    assert p1.elementclass_xml(u"baz", u"nix") is baz 
    238277 
  • test/test_xist_walk.py

    r4041 r4087  
    107107    assert unicode(e.walknodes(isdiv)[0]) == u"123" 
    108108    assert unicode(e.walknodes(isdiv)[-1]) == u"3" 
    109     py.test.raises(IndexError, e.walknodes(isdiv).__getitem__, 3) 
    110     py.test.raises(IndexError, e.walknodes(isdiv).__getitem__, -4) 
     109    with py.test.raises(IndexError): 
     110        e.walknodes(isdiv)[3] 
     111    with py.test.raises(IndexError): 
     112        e.walknodes(isdiv)[-4] 
    111113    assert unicode(e.walkpaths(isdiv)[0][-1]) == u"123" 
    112114    assert unicode(e.walkpaths(isdiv)[-1][-1]) == u"3" 
    113     py.test.raises(IndexError, e.walkpaths(isdiv).__getitem__, 3) 
    114     py.test.raises(IndexError, e.walkpaths(isdiv).__getitem__, -4) 
     115    with py.test.raises(IndexError): 
     116        e.walkpaths(isdiv)[3] 
     117    with py.test.raises(IndexError): 
     118        e.walkpaths(isdiv)[-4] 
  • test/test_xist_xfind.py

    r4055 r4087  
    328328    assert unicode(e[xsc.Text][-1]) == u"9" 
    329329    assert unicode(e[xsc.Text][-10]) == u"0" 
    330     py.test.raises(IndexError, e[xsc.Text].__getitem__, 10) 
    331     py.test.raises(IndexError, e[xsc.Text].__getitem__, -11) 
     330    with py.test.raises(IndexError): 
     331        e[xsc.Text][10] 
     332    with py.test.raises(IndexError): 
     333        e[xsc.Text][-11] 
    332334    assert unicode(misc.item(e[xsc.Text], 10, u"x")) == u"x" 
    333335    assert unicode(misc.item(e[xsc.Text], -11, u"x")) == u"x" 
  • test/test_xml_codec.py

    r4042 r4087  
    7373    assert xml_codec._detectencoding("<?xml\rversion='1.0' Encoding='x'") is None # encoding not recognized (might come later) 
    7474    assert xml_codec._detectencoding("<?xml\rVersion='1.0'") is None 
    75     py.test.raises(ValueError, xml_codec._detectencoding, "<?xml\rversion='1.0' encoding=''") # empty encoding 
     75    with py.test.raises(ValueError): 
     76        xml_codec._detectencoding("<?xml\rversion='1.0' encoding=''") # empty encoding 
    7677    assert xml_codec._detectencoding("<", False) is None 
    7778    assert xml_codec._detectencoding("<", True) == "utf-8" 
     
    200201 
    201202    # No recursion 
    202     py.test.raises(ValueError, "<?xml version='1.0' encoding='xml'?><gurk/>".decode, "xml") 
     203    with py.test.raises(ValueError): 
     204        "<?xml version='1.0' encoding='xml'?><gurk/>".decode("xml") 
    203205 
    204206 
     
    236238 
    237239    # No recursion 
    238     py.test.raises(ValueError, u"<?xml version='1.0' encoding='xml'?><gurk/>".encode, "xml") 
    239  
     240    with py.test.raises(ValueError): 
     241        u"<?xml version='1.0' encoding='xml'?><gurk/>".encode("xml")