<s> import unittest , doctest , sys , os . path <EOL> this_dir = os . path . dirname ( __file__ ) <EOL> if this_dir not in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , this_dir ) <EOL> from common_imports import StringIO , etree , SillyFileLike , HelperTestCase <EOL> from common_imports import _str , _bytes <EOL> try : <EOL> unicode <EOL> except NameError : <EOL> unicode = str <EOL> ascii_uni = _bytes ( '<STR_LIT:a>' ) . decode ( '<STR_LIT:utf8>' ) <EOL> klingon = _bytes ( "<STR_LIT>" ) . decode ( "<STR_LIT>" ) <EOL> invalid_tag = _bytes ( "<STR_LIT:test>" ) . decode ( '<STR_LIT:utf8>' ) + klingon <EOL> uni = _bytes ( '<STR_LIT>' ) . decode ( "<STR_LIT>" ) <EOL> uxml = _bytes ( "<STR_LIT>" <EOL> ) . decode ( "<STR_LIT>" ) <EOL> class UnicodeTestCase ( HelperTestCase ) : <EOL> def test_unicode_xml ( self ) : <EOL> tree = etree . XML ( '<STR_LIT>' % uni ) <EOL> self . assertEqual ( uni , tree . text ) <EOL> def test_wide_unicode_xml ( self ) : <EOL> if sys . maxunicode < <NUM_LIT> : <EOL> return <EOL> tree = etree . XML ( _bytes ( '<STR_LIT>' ) . decode ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( tree . text ) ) <EOL> self . assertEqual ( _bytes ( '<STR_LIT>' ) . decode ( '<STR_LIT>' ) , <EOL> tree . text ) <EOL> def test_unicode_xml_broken ( self ) : <EOL> uxml = ( '<STR_LIT>' + <EOL> '<STR_LIT>' % uni ) <EOL> self . assertRaises ( ValueError , etree . XML , uxml ) <EOL> def test_unicode_tag ( self ) : <EOL> el = etree . Element ( uni ) <EOL> self . assertEqual ( uni , el . tag ) <EOL> def test_unicode_tag_invalid ( self ) : <EOL> self . assertRaises ( ValueError , etree . Element , invalid_tag ) <EOL> def test_unicode_nstag ( self ) : <EOL> tag = "<STR_LIT>" % uni <EOL> el = etree . Element ( tag ) <EOL> self . assertEqual ( tag , el . tag ) <EOL> def test_unicode_ns_invalid ( self ) : <EOL> tag = "<STR_LIT>" % uni <EOL> self . assertRaises ( ValueError , etree . Element , tag ) <EOL> def test_unicode_nstag_invalid ( self ) : <EOL> tag = "<STR_LIT>" % invalid_tag <EOL> self . assertRaises ( ValueError , etree . Element , tag ) <EOL> def test_unicode_qname ( self ) : <EOL> qname = etree . QName ( uni , uni ) <EOL> tag = "<STR_LIT>" % ( uni , uni ) <EOL> self . assertEqual ( qname . text , tag ) <EOL> self . assertEqual ( unicode ( qname ) , tag ) <EOL> def test_unicode_qname_invalid ( self ) : <EOL> self . assertRaises ( ValueError , etree . QName , invalid_tag ) <EOL> def test_unicode_attr ( self ) : <EOL> el = etree . Element ( '<STR_LIT:foo>' , { '<STR_LIT:bar>' : uni } ) <EOL> self . assertEqual ( uni , el . attrib [ '<STR_LIT:bar>' ] ) <EOL> def test_unicode_comment ( self ) : <EOL> el = etree . Comment ( uni ) <EOL> self . assertEqual ( uni , el . text ) <EOL> def test_unicode_parse_stringio ( self ) : <EOL> el = etree . parse ( StringIO ( '<STR_LIT>' % uni ) ) . getroot ( ) <EOL> self . assertEqual ( uni , el . text ) <EOL> def test_suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTests ( [ unittest . makeSuite ( UnicodeTestCase ) ] ) <EOL> return suite </s>
