Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_pulldom.cpython-34.pyo

�
f f�0�@s4ddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZeddd�ZdZ
Gd	d
�d
ej�ZGdd�dej�ZGd
d�de�ZGdd�de�ZGdd�dej�ZGdd�dej�Zdd�Zedkr0e�ndS)�N)�AttributesImpl)�pulldom)�run_unittest�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|��WdQXdS)z&Minimal test of DOMEventStream.parse()�rbN)r�parse�tstfileZ
addCleanup�stream�close�list�open)�self�handler�fin�r�6/opt/alt/python34/lib64/python3.4/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�}xi|D]T\}}|tjkr|jdkr|j|�|jdt|j��PqqW|j	d�x'|D]\}}|tjkr�Pq�q�W|jd|jd�|j|�|jt
|�dtj�t
|�\}}|j|jd�|j|�t
|�t
|�\}}|j|jd�|jt
��t
|�Wd	QX|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
)rr(r)�itemr*rrr�test_expandItemis2





zPullDOMTestCase.test_expandItemcCsJtjt�}x4|D]\}}|tjkrPqqW|jd�dS)z*PullDOM does not receive "comment" events.zNo comment was encounteredN)rrr�COMMENTr.)rr(r)�_rrr�test_comment�s
zPullDOMTestCase.test_commentcCs�tjt�}x6|D].\}}|tjkr|jdkrPqqWy)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.)rr(r)r*rrr�test_end_document�s
z!PullDOMTestCase.test_end_documentN)
�__name__�
__module__�__qualname__rr+r4�unittest�expectedFailurer7r9rrrrrs
> 
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.Nr2)�_test_thoroughrr�SAXExerciser)rrrr�test_thorough_parse�sz$ThoroughTestCase.test_thorough_parsecCs&tdt�d�}|j|�dS)z2SAX2DOM can"t handle a PI before the root element.N�)�SAX2DOMTestHelperrAr@)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.NrCF)rD�SAX2DOMExerciserr@)rrErrr�test_thorough_sax2dom�sz&ThoroughTestCase.test_thorough_sax2domTcCs�t|�\}}|jtj|�|jt|d��|r�t|�\}}|jtj|�|jd|j�t|�\}}|jtj|�|jd|j	�|jd|j�nt|�\}}|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)rrrr rrr5r&ZPROCESSING_INSTRUCTIONrIr!r"r%r'r8)rrEZbefore_rootr)r*rrrr@�sFzThoroughTestCase._test_thoroughN)
r:r;r<�__doc__rBr=r>rFrHr@rrrrr?�s
r?c@sFeZdZdZdd�Zdd�Zdd�ZeZeZdS)	rAznA fake sax parser that calls some of the harder-to-reach sax methods to
    ensure it emits the correct eventscCs
||_dS)N)�_handler)rrrrr�setContentHandler�szSAXExerciser.setContentHandlercCs�|j}|j�|jd�|jdd�|jdti��|jd�|jdd�|jdtidd6��|jd�|jd�|jd�|j�dS)	Nz	a commentrIr&rr�	paraclass�classrJ)	rL�
startDocument�comment�processingInstruction�startElementr�
characters�
endElement�endDocument)rr6�hrrrr�s	





zSAXExerciser.parsecOsdS)zStub method. Does nothing.Nr)r�args�kwargsrrr�stubszSAXExerciser.stubN)	r:r;r<rKrMrrZZsetProperty�
setFeaturerrrrrA�srAc@s"eZdZdZdd�ZdS)rGz�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�|jdtidd6��|jd�|jd�|jd�|j�dS)	Nrz	a commentrIr&rrNrOrJ)	rLrPrSrrQrRrTrUrV)rr6rWrrrrs	




zSAX2DOMExerciser.parseN)r:r;r<rKrrrrrrGsrGc@s"eZdZdZdd�ZdS)rDz1Allows us to drive SAX2DOM from a DOMEventStream.cCsBtj�|_|jjtjjjd�|jj|j�dS)Nr,)	r�SAX2DOMr2r[�xml�saxrZfeature_namespacesrM)rrrr�resetszSAX2DOMTestHelper.resetN)r:r;r<rKr_rrrrrDsrDc@s7eZdZddd�Zdd�Zdd�ZdS)	�SAX2DOMTestCaseZTestcCs|j||�dS)N)r)rZtestZtestnamerrr�confirm$szSAX2DOMTestCase.confirmcCs�tjt��z}t|tjj�tt��}x6|D].\}}|tj	kr:|j
dkr:Pq:q:W|jt|j�d�WdQXdS)z'Ensure SAX2DOM can parse from a stream.rrN)
�io�StringIOrrDr]r^Zmake_parserr#rr!r"Z
assertGreaterr-)rrZsdr)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.�docrJZsubelmrN)rr\rPrSrTrUrVZdocumentZdocumentElementr-r1ZpreviousSiblingZassertIsZnextSiblingZ
parentNode�unlink)rZsax2domre�rootZtext1Zelm1Ztext2Ztext3rrr�testSAX2DOM3s8






		
zSAX2DOMTestCase.testSAX2DOMN)r:r;r<rardrhrrrrr`"sr`cCstttt�dS)N)rrr?r`rrrr�	test_mainVsri�__main__)rbr=�sysZxml.saxr]Zxml.sax.xmlreaderrZxml.domrZtest.supportrrr	rZTestCaserr?�objectrArGZDOMEventStreamrDr`rir:rrrr�<module>s"
�A"
4