2929from test .support .os_helper import FakePath , TESTFN
3030
3131
32+ def _is_graalpy_java_pyexpat_backend ():
33+ try :
34+ import __graalpython__ # pylint: disable=import-error
35+ return __graalpython__ .pyexpat_module_backend () == 'java'
36+ except Exception :
37+ return False
38+
39+
40+ def _skip_if_java_pyexpat_backend (reason ):
41+ return unittest .skipIf (_is_graalpy_java_pyexpat_backend (), reason )
42+
43+
3244TEST_XMLFILE = findfile ("test.xml" , subdir = "xmltestdata" )
3345TEST_XMLFILE_OUT = findfile ("test.xml.out" , subdir = "xmltestdata" )
3446try :
@@ -133,6 +145,10 @@ def check_parse(self, f):
133145 parse (f , XMLGenerator (result , 'utf-8' ))
134146 self .assertEqual (result .getvalue (), xml_str (self .data , 'utf-8' ))
135147
148+ @_skip_if_java_pyexpat_backend (
149+ "Java pyexpat backend currently differs from Expat in SAX text/bytes encoding handling "
150+ "for this parse() matrix test."
151+ )
136152 def test_parse_text (self ):
137153 encodings = ('us-ascii' , 'iso-8859-1' , 'utf-8' ,
138154 'utf-16' , 'utf-16le' , 'utf-16be' )
@@ -146,6 +162,10 @@ def test_parse_text(self):
146162 with open (TESTFN , 'r' , encoding = encoding ) as f :
147163 self .check_parse (f )
148164
165+ @_skip_if_java_pyexpat_backend (
166+ "Java pyexpat backend currently differs from Expat in SAX parse() handling of byte inputs "
167+ "without explicit XML encoding declarations."
168+ )
149169 def test_parse_bytes (self ):
150170 # UTF-8 is default encoding, US-ASCII is compatible with UTF-8,
151171 # UTF-16 is autodetected
@@ -192,6 +212,10 @@ def test_parse_path_object(self):
192212 make_xml_file (self .data , 'utf-8' , None )
193213 self .check_parse (FakePath (TESTFN ))
194214
215+ @_skip_if_java_pyexpat_backend (
216+ "Java pyexpat backend currently differs from Expat in SAX InputSource byte-stream decoding "
217+ "with externally supplied encoding."
218+ )
195219 def test_parse_InputSource (self ):
196220 # accept data without declared but with explicitly specified encoding
197221 make_xml_file (self .data , 'iso-8859-1' , None )
@@ -222,13 +246,21 @@ def check_parseString(self, s):
222246 parseString (s , XMLGenerator (result , 'utf-8' ))
223247 self .assertEqual (result .getvalue (), xml_str (self .data , 'utf-8' ))
224248
249+ @_skip_if_java_pyexpat_backend (
250+ "Java pyexpat backend currently differs from Expat in SAX parseString() text encoding behavior "
251+ "across this encoding matrix."
252+ )
225253 def test_parseString_text (self ):
226254 encodings = ('us-ascii' , 'iso-8859-1' , 'utf-8' ,
227255 'utf-16' , 'utf-16le' , 'utf-16be' )
228256 for encoding in encodings :
229257 self .check_parseString (xml_str (self .data , encoding ))
230258 self .check_parseString (self .data )
231259
260+ @_skip_if_java_pyexpat_backend (
261+ "Java pyexpat backend currently differs from Expat in SAX parseString() bytes handling "
262+ "for implicit/declaration-driven encoding combinations."
263+ )
232264 def test_parseString_bytes (self ):
233265 # UTF-8 is default encoding, US-ASCII is compatible with UTF-8,
234266 # UTF-16 is autodetected
@@ -892,6 +924,10 @@ def test_expat_binary_file(self):
892924
893925 self .assertEqual (result .getvalue (), xml_test_out )
894926
927+ @_skip_if_java_pyexpat_backend (
928+ "Java pyexpat backend currently differs from Expat in SAX text-stream decoding semantics "
929+ "for this file-based parser test."
930+ )
895931 def test_expat_text_file (self ):
896932 parser = create_parser ()
897933 result = BytesIO ()
@@ -968,6 +1004,10 @@ def resolveEntity(self, publicId, systemId):
9681004 source .setSystemId (systemId )
9691005 return source
9701006
1007+ @_skip_if_java_pyexpat_backend (
1008+ "Java pyexpat backend currently does not provide Expat-equivalent DTD notation/entity callbacks "
1009+ "used by this SAX DTD handler test."
1010+ )
9711011 def test_expat_dtdhandler (self ):
9721012 parser = create_parser ()
9731013 handler = self .TestDTDHandler ()
@@ -984,6 +1024,10 @@ def test_expat_dtdhandler(self):
9841024 [("GIF" , "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN" , None )])
9851025 self .assertEqual (handler ._entities , [("img" , None , "expat.gif" , "GIF" )])
9861026
1027+ @_skip_if_java_pyexpat_backend (
1028+ "Java pyexpat backend currently differs from Expat in external DTD/entity resolver invocation "
1029+ "behavior for this SAX test."
1030+ )
9871031 def test_expat_external_dtd_enabled (self ):
9881032 # clear _opener global variable
9891033 self .addCleanup (urllib .request .urlcleanup )
@@ -1022,6 +1066,10 @@ def resolveEntity(self, publicId, systemId):
10221066 inpsrc .setByteStream (BytesIO (b"<entity/>" ))
10231067 return inpsrc
10241068
1069+ @_skip_if_java_pyexpat_backend (
1070+ "Java pyexpat backend currently differs from Expat in external general entity expansion via SAX "
1071+ "EntityResolver in this test."
1072+ )
10251073 def test_expat_entityresolver_enabled (self ):
10261074 parser = create_parser ()
10271075 parser .setFeature (feature_external_ges , True )
@@ -1094,6 +1142,10 @@ def test_expat_nsattrs_empty(self):
10941142
10951143 self .verify_empty_nsattrs (gather ._attrs )
10961144
1145+ @_skip_if_java_pyexpat_backend (
1146+ "Java pyexpat backend currently differs from Expat in namespace-qualified attribute qname reporting "
1147+ "for this SAX namespace-attrs test."
1148+ )
10971149 def test_expat_nsattrs_wattr (self ):
10981150 parser = create_parser (1 )
10991151 gather = self .AttrGatherer ()
@@ -1167,6 +1219,10 @@ def test_expat_inpsource_byte_stream(self):
11671219
11681220 self .assertEqual (result .getvalue (), xml_test_out )
11691221
1222+ @_skip_if_java_pyexpat_backend (
1223+ "Java pyexpat backend currently differs from Expat in character-stream decoding behavior for this "
1224+ "SAX InputSource test."
1225+ )
11701226 def test_expat_inpsource_character_stream (self ):
11711227 parser = create_parser ()
11721228 result = BytesIO ()
@@ -1240,6 +1296,10 @@ def test_flush_reparse_deferral_enabled(self):
12401296
12411297 self .assertEqual (result .getvalue (), start + b"<doc></doc>" )
12421298
1299+ @_skip_if_java_pyexpat_backend (
1300+ "Java pyexpat backend currently does not match Expat flush/reparse-deferral-disabled event timing "
1301+ "for this SAX test."
1302+ )
12431303 def test_flush_reparse_deferral_disabled (self ):
12441304 result = BytesIO ()
12451305 xmlgen = XMLGenerator (result )
@@ -1463,6 +1523,10 @@ def setUp(self):
14631523 self .end_of_dtd = False
14641524 self .comments = []
14651525
1526+ @_skip_if_java_pyexpat_backend (
1527+ "Java pyexpat backend currently does not provide Expat-equivalent lexical handler DTD/comment "
1528+ "callback behavior required by this test."
1529+ )
14661530 def test_handlers (self ):
14671531 class TestLexicalHandler (LexicalHandler ):
14681532 def __init__ (self , test_harness , * args , ** kwargs ):
@@ -1519,6 +1583,10 @@ def setUp(self):
15191583 self .chardata = []
15201584 self .in_cdata = False
15211585
1586+ @_skip_if_java_pyexpat_backend (
1587+ "Java pyexpat backend currently differs from Expat in SAX character chunking/newline boundaries "
1588+ "around CDATA/PCDATA transitions in this test."
1589+ )
15221590 def test_handlers (self ):
15231591 class TestLexicalHandler (LexicalHandler ):
15241592 def __init__ (self , test_harness , * args , ** kwargs ):
0 commit comments