<s> """<STR_LIT>""" <EOL> import unittest , 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 etree , BytesIO , _bytes , HelperTestCase , fileInTestDir <EOL> from common_imports import doctest , make_doctest <EOL> class ETreeRelaxNGTestCase ( HelperTestCase ) : <EOL> def test_relaxng ( self ) : <EOL> tree_valid = self . parse ( '<STR_LIT>' ) <EOL> tree_invalid = self . parse ( '<STR_LIT>' ) <EOL> schema = self . parse ( '''<STR_LIT>''' ) <EOL> schema = etree . RelaxNG ( schema ) <EOL> self . assertTrue ( schema . validate ( tree_valid ) ) <EOL> self . assertFalse ( schema . error_log . filter_from_errors ( ) ) <EOL> self . assertFalse ( schema . validate ( tree_invalid ) ) <EOL> self . assertTrue ( schema . error_log . filter_from_errors ( ) ) <EOL> self . assertTrue ( schema . validate ( tree_valid ) ) <EOL> self . assertFalse ( schema . error_log . filter_from_errors ( ) ) <EOL> def test_relaxng_stringio ( self ) : <EOL> tree_valid = self . parse ( '<STR_LIT>' ) <EOL> tree_invalid = self . parse ( '<STR_LIT>' ) <EOL> schema_file = BytesIO ( '''<STR_LIT>''' ) <EOL> schema = etree . RelaxNG ( file = schema_file ) <EOL> self . assertTrue ( schema . validate ( tree_valid ) ) <EOL> self . assertFalse ( schema . validate ( tree_invalid ) ) <EOL> def test_relaxng_elementtree_error ( self ) : <EOL> self . assertRaises ( ValueError , etree . RelaxNG , etree . ElementTree ( ) ) <EOL> def test_relaxng_error ( self ) : <EOL> tree_invalid = self . parse ( '<STR_LIT>' ) <EOL> schema = self . parse ( '''<STR_LIT>''' ) <EOL> schema = etree . RelaxNG ( schema ) <EOL> self . assertFalse ( schema . validate ( tree_invalid ) ) <EOL> errors = schema . error_log <EOL> self . assertTrue ( [ log for log in errors <EOL> if log . level_name == "<STR_LIT>" ] ) <EOL> self . assertTrue ( [ log for log in errors <EOL> if "<STR_LIT>" in log . message ] ) <EOL> def test_relaxng_invalid_schema ( self ) : <EOL> schema = self . parse ( '''<STR_LIT>''' ) <EOL> self . assertRaises ( etree . RelaxNGParseError , <EOL> etree . RelaxNG , schema ) <EOL> def test_relaxng_invalid_schema2 ( self ) : <EOL> schema = self . parse ( '''<STR_LIT>''' ) <EOL> self . assertRaises ( etree . RelaxNGParseError , <EOL> etree . RelaxNG , schema ) <EOL> def test_relaxng_invalid_schema3 ( self ) : <EOL> schema = self . parse ( '''<STR_LIT>''' ) <EOL> self . assertRaises ( etree . RelaxNGParseError , <EOL> etree . RelaxNG , schema ) <EOL> def test_relaxng_invalid_schema4 ( self ) : <EOL> schema = self . parse ( '''<STR_LIT>''' ) <EOL> self . assertRaises ( etree . RelaxNGParseError , <EOL> etree . RelaxNG , schema ) <EOL> def test_relaxng_include ( self ) : <EOL> f = open ( fileInTestDir ( '<STR_LIT>' ) , '<STR_LIT:rb>' ) <EOL> try : <EOL> schema = etree . RelaxNG ( file = f ) <EOL> finally : <EOL> f . close ( ) <EOL> def test_relaxng_shortcut ( self ) : <EOL> tree_valid = self . parse ( '<STR_LIT>' ) <EOL> tree_invalid = self . parse ( '<STR_LIT>' ) <EOL> schema = self . parse ( '''<STR_LIT>''' ) <EOL> self . assertTrue ( tree_valid . relaxng ( schema ) ) <EOL> self . assertFalse ( tree_invalid . relaxng ( schema ) ) <EOL> def test_multiple_elementrees ( self ) : <EOL> tree = self . parse ( '<STR_LIT>' ) <EOL> schema = etree . RelaxNG ( self . parse ( '''<STR_LIT>''' ) ) <EOL> self . assertTrue ( schema . validate ( tree ) ) <EOL> self . assertFalse ( schema . error_log . filter_from_errors ( ) ) <EOL> self . assertTrue ( schema . validate ( tree ) ) <EOL> self . assertFalse ( schema . error_log . filter_from_errors ( ) ) <EOL> schema = etree . RelaxNG ( self . parse ( '''<STR_LIT>''' ) ) <EOL> c_tree = etree . ElementTree ( tree . getroot ( ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( self . _rootstring ( c_tree ) , _bytes ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( schema . validate ( c_tree ) ) <EOL> self . assertTrue ( schema . error_log . filter_from_errors ( ) ) <EOL> b_tree = etree . ElementTree ( tree . getroot ( ) [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( self . _rootstring ( b_tree ) , _bytes ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( schema . validate ( b_tree ) ) <EOL> self . assertFalse ( schema . error_log . filter_from_errors ( ) ) <EOL> def test_suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTests ( [ unittest . makeSuite ( ETreeRelaxNGTestCase ) ] ) <EOL> suite . addTests ( <EOL> [ make_doctest ( '<STR_LIT>' ) ] ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print ( '<STR_LIT>' % __file__ ) </s>
