Your IP : 216.73.216.52


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_pulldom.cpython-35.pyc



��YfQ0�@s"ddlZddlZddlZddlZddlmZddlmZddl	m
Z
e
ddd�ZdZGd	d
�d
ej
�ZGdd�dej
�ZGd
d�de�ZGdd�de�ZGdd�dej�ZGdd�dej
�Zedkrej�dS)�N)�AttributesImpl)�pulldom)�findfileztest.xmlZsubdirZxmltestdataa
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xdc="http://www.xml.com/books">
<!-- A comment -->
<title>Introduction to XSL</title>
<hr/>
<p><xdc:author xdc:attrib="prefixed attribute" attrib="other attrib">A. Namespace</xdc:author></p>
</html>c@s^eZdZdd�Zdd�Zdd�Zejdd��Zejd	d
��Z	dS)�PullDOMTestCasec
Cs\tjt�}|j|jj�t|�ttd��}ttj|��WdQRXdS)z&Minimal test of DOMEventStream.parse()�rbN)r�parse�tstfileZ
addCleanup�stream�close�list�open)�self�handler�fin�r�6/opt/alt/python35/lib64/python3.5/test/test_pulldom.py�
test_parses

zPullDOMTestCase.test_parsecCs�tjt�}t|�\}}|jt|d��|jtj|�t|�\}}|jtj|�|jd|j	�|jdt
|j��|j|jjd�j
d�t|�\}}|jtj|�t|�\}}|jtj|�t|�\}}|jd|j	�|}t|�\}}|jtj|�|jd|j�t|�\}}|jtj|�|jd|j	�|j||k�t|�\}}|jtj|�t|�\}}|jtj|�|jd|j	�t|�\}}|jtj|�|jd|j	�t|�\}}|jtj|�t|�\}}|jtj|�|jd	|j	�t|�\}}|jtj|�|jd
|j	�t|�\}}|jtj|�t|�\}}|jtj|�|jd
|j	�t|�\}}|jtj|�t|�\}}|jtj|�t|�\}}|jtj|�dS)z&Test DOMEventStream parsing semantics.�
createElement�html�z	xmlns:xdczhttp://www.xml.com/books�titlezIntroduction to XSL�hr�pz
xdc:authorN)r�parseString�SMALL_SAMPLE�next�
assertTrue�hasattr�assertEqual�START_DOCUMENT�
START_ELEMENT�tagName�lenZ
attributesZgetNamedItem�value�
CHARACTERS�data�END_ELEMENT)r
�items�evt�nodeZ
title_noderrr�test_parse_semantics+sfz$PullDOMTestCase.test_parse_semanticsc	Cs�tjt�}xf|D]Q\}}|tjkr|jdkr|j|�|jdt|j��PqW|j	d�x$|D]\}}|tjkrPqW|jd|jd�|j|�|jt
|�dtj�t
|�\}}|j|jd�|j|�t
|�t
|�\}}|j|jd�|jt
��t
|�Wd	QRX|j�|j|j�|j|j�d	S)
z$Ensure expandItem works as expected.r�z,No "title" element detected in SMALL_SAMPLE!rz=expandNode did not leave DOMEventStream in the correct state.rrrN)rrrr r!Z
expandNoderr"�
childNodes�failrr$ZassertRaises�
StopIteration�clear�assertIsNone�parserr	)r
r'r(�itemr)rrr�test_expandItemis2





zPullDOMTestCase.test_expandItemcCsGtjt�}x1|D]\}}|tjkrPqW|jd�dS)z*PullDOM does not receive "comment" events.zNo comment was encounteredN)rrr�COMMENTr-)r
r'r(�_rrr�test_comment�s
zPullDOMTestCase.test_commentcCs�tjt�}x3|D]+\}}|tjkr|jdkrPqWy)t|�\}}|jtj|�Wntk
r�|j	d�YnXdS)z/PullDOM does not receive "end-document" events.rz8Ran out of events, but should have received END_DOCUMENTN)
rrrr&r!rr�END_DOCUMENTr.r-)r
r'r(r)rrr�test_end_document�s
z!PullDOMTestCase.test_end_documentN)
�__name__�
__module__�__qualname__rr*r3�unittest�expectedFailurer6r8rrrrrs
> 
rc@sReZdZdZdd�Zejdd��Zdd�Zdd	d
�Z	dS)�ThoroughTestCasez(Test the hard-to-reach parts of pulldom.cCs#|jtjddt���dS)z0Test some of the hard-to-reach parts of PullDOM.Nr1)�_test_thoroughrr�SAXExerciser)r
rrr�test_thorough_parse�sz$ThoroughTestCase.test_thorough_parsecCs&tdt�d�}|j|�dS)z2SAX2DOM can"t handle a PI before the root element.N�)�SAX2DOMTestHelperr@r?)r
�pdrrr�test_sax2dom_fail�sz"ThoroughTestCase.test_sax2dom_failcCs)tdt�d�}|j|d�dS)z0Test some of the hard-to-reach parts of SAX2DOM.NrBF)rC�SAX2DOMExerciserr?)r
rDrrr�test_thorough_sax2dom�sz&ThoroughTestCase.test_thorough_sax2domTcCs�t|�\}}|jtj|�|jt|d��|r�t|�\}}|jtj|�|jd|j�t|�\}}|jtj|�|jd|j	�|jd|j�t|�\}}|jtj
|�|jd|j�t|�\}}|jtj|�|jd|j�t|�\}}|jtj|�|jd|j	�|jd|j�t|�\}}|jtj
|�|jd|j�t|�\}}|jtj|�|jd|j�t|�\}}|jtj
|�|jd|j�t|�\}}|jtj
|�|jd|j�t|�\}}|jtj|�dS)	zPTest some of the hard-to-reach parts of the parser, using a mock
        parser.rz	a comment�targetr%rr�textN)rrrrrrr4r%ZPROCESSING_INSTRUCTIONrHr r!r$r&r7)r
rDZbefore_rootr(r)rrrr?�sFzThoroughTestCase._test_thoroughN)
r9r:r;�__doc__rAr<r=rErGr?rrrrr>�s
r>c@sFeZdZdZdd�Zdd�Zdd�ZeZeZdS)	r@znA fake sax parser that calls some of the harder-to-reach sax methods to
    ensure it emits the correct eventscCs
||_dS)N)�_handler)r
rrrr�setContentHandler�szSAXExerciser.setContentHandlercCs�|j}|j�|jd�|jdd�|jdti��|jd�|jdd�|jdtddi��|jd�|jd�|jd�|j�dS)	Nz	a commentrHr%rr�class�	paraclassrI)	rK�
startDocument�comment�processingInstruction�startElementr�
characters�
endElement�endDocument)r
r5�hrrrr�s	





zSAXExerciser.parsecOsdS)zStub method. Does nothing.Nr)r
�args�kwargsrrr�stubszSAXExerciser.stubN)	r9r:r;rJrLrrYZsetProperty�
setFeaturerrrrr@�sr@c@s"eZdZdZdd�ZdS)rFz�The same as SAXExerciser, but without the processing instruction and
    comment before the root element, because S2D can"t handle itcCs�|j}|j�|jdti��|jd�|jdd�|jdtddi��|jd�|jd�|jd�|j�dS)	Nrz	a commentrHr%rrMrNrI)	rKrOrRrrPrQrSrTrU)r
r5rVrrrrs	




zSAX2DOMExerciser.parseN)r9r:r;rJrrrrrrFsrFc@s"eZdZdZdd�ZdS)rCz1Allows us to drive SAX2DOM from a DOMEventStream.cCsBtj�|_|jjtjjjd�|jj|j�dS)Nr+)	r�SAX2DOMr1rZ�xml�saxrZfeature_namespacesrL)r
rrr�resetszSAX2DOMTestHelper.resetN)r9r:r;rJr^rrrrrCsrCc@s7eZdZddd�Zdd�Zdd�ZdS)	�SAX2DOMTestCaseZTestcCs|j||�dS)N)r)r
ZtestZtestnamerrr�confirm$szSAX2DOMTestCase.confirmcCs�tjt��w}t|tjj�tt��}x3|D]+\}}|tj	kr:|j
dkr:Pq:W|jt|j�d�WdQRXdS)z'Ensure SAX2DOM can parse from a stream.rrN)
�io�StringIOrrCr\r]Zmake_parserr"rr r!Z
assertGreaterr,)r
rZsdr(r)rrr�
test_basic'szSAX2DOMTestCase.test_basiccCs�tj�}|j�|jdi�|jd�|jdi�|jd�|jd�|jd�|jd�|j�|j}|j}|j	\}}}|j	d}|j
|j�|j|j
|�|j|j|�|j|j
|�|j|j|�|j
|j
�|j
|j�|j
|j
�|j|j|�|j|j|�|j|j|�|j|j|�|j|j|�|j�dS)z)Ensure SAX2DOM expands nodes as expected.�docrIZsubelmrN)rr[rOrRrSrTrUZdocumentZdocumentElementr,r0ZpreviousSiblingZassertIsZnextSiblingZ
parentNode�unlink)r
Zsax2domrd�rootZtext1Zelm1Ztext2Ztext3rrr�testSAX2DOM3s8






		
zSAX2DOMTestCase.testSAX2DOMN)r9r:r;r`rcrgrrrrr_"sr_�__main__)rar<�sysZxml.saxr\Zxml.sax.xmlreaderrZxml.domrZtest.supportrrrZTestCaserr>�objectr@rFZDOMEventStreamrCr_r9�mainrrrr�<module>s 
�A"
4