%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_adbapi.cpython-312.pyc

�

Ϫ�f�e��N�dZddlZddlZddlmZmZddlmZmZm	Z	m
Z
ddlmZm
Z
mZddlmZddlmZddlmZd	ZGd
�d�ZGd�d
�ZGd�d�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Zd�Zeede ��eede ��Gd�d �Z!Gd!�d"ejD�Z#Gd#�d$ejD�Z$Gd%�d&�Z%Gd'�d(e	�Z&Gd)�d*�Z'Gd+�d,ejD�Z(y)-z&
Tests for twisted.enterprise.adbapi.
�N)�Dict�Optional)�
Connection�ConnectionLost�ConnectionPool�Transaction)�defer�
interfaces�reactor)�Failure��
requireModule)�unittestz%
CREATE TABLE simple (
  x integer
)
c���eZdZUdZiZeeefed<e	jed��dZd�Z
d�Zd�Zdd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#y)�ADBAPITestBasez,
    Test the asynchronous DB-API code.
    �openfun_calledN�5ADB-API requires threads, no way to test without themc��|j�|j|j��|_|jj	�y)zR
        Set up the database and create a connection pool pointing at it.
        )�
cp_openfunN)�startDB�makePool�openfun�dbpool�start��selfs �:/usr/lib/python3/dist-packages/twisted/test/test_adbapi.py�
extraSetUpzADBAPITestBase.extraSetUp(s3��	
�����m�m�t�|�|�m�<���������c����jjd�}|j�fd��|j�fd��|S)N�DROP TABLE simplec�8���jj�S�N�r�close��resrs �r�<lambda>z)ADBAPITestBase.tearDown.<locals>.<lambda>2����$�+�+�"3�"3�"5�rc�$���j�Sr#��stopDBr&s �rr(z)ADBAPITestBase.tearDown.<locals>.<lambda>3�
���$�+�+�-�r�r�runOperation�addCallback�r�ds` r�tearDownzADBAPITestBase.tearDown0�7����K�K�$�$�%8�9��	�
�
�5�6�	�
�
�/�0��rc�"�d|j|<y)NT)r�r�conns  rrzADBAPITestBase.openfun6s��$(����D�!rc�x�|s|j|j�y|j||j�yr#)�
assertTruer�assertInr6s  r�checkOpenfunCalledz!ADBAPITestBase.checkOpenfunCalled9s+����O�O�D�/�/�0��M�M�$�� 3� 3�4rc����jjt�}�jr�|j	�j
�|j	�j�|j	�j�|j	�j�|j	�fd��|j	�j�|j	�j�|j	�j�|j	�j�|j	�j�|j	�j�|j	�j�|j	�j �|S)Nc�$���j�Sr#)�flushLoggedErrorsr&s �rr(z*ADBAPITestBase.test_pool.<locals>.<lambda>Fs���d�&<�&<�&>�r)rr/�simple_table_schema�
test_failuresr0�
_testPool_1_1�
_testPool_1_2�
_testPool_1_3�
_testPool_1_4�_testPool_2�_testPool_3�_testPool_4�_testPool_5�_testPool_6�_testPool_7�_testPool_8�_testPool_9r1s` r�	test_poolzADBAPITestBase.test_pool?s����K�K�$�$�%8�9�����
�M�M�$�,�,�-�
�M�M�$�,�,�-�
�M�M�$�,�,�-�
�M�M�$�,�,�-�
�M�M�>�?�	�
�
�d�&�&�'�	�
�
�d�&�&�'�	�
�
�d�&�&�'�	�
�
�d�&�&�'�	�
�
�d�&�&�'�	�
�
�d�&�&�'�	�
�
�d�&�&�'�	�
�
�d�&�&�'��rc���tj�jjd�}|j	�fd�d��|S)N�select * from NOTABLEc�&���jd�S�Nzno exception��failr&s �rr(z.ADBAPITestBase._testPool_1_1.<locals>.<lambda>S����4�9�9�^�#<�rc��yr#���fs rr(z.ADBAPITestBase._testPool_1_1.<locals>.<lambda>S��r�r	�
maybeDeferredr�runQuery�addCallbacks�rr'r2s`  rrAzADBAPITestBase._testPool_1_1Qs4��������� 4� 4�6M�N��	���<�n�M��rc���tj�jjd�}|j	�fd�d��|S)Nzdeletexxx from NOTABLEc�&���jd�SrQrRr&s �rr(z.ADBAPITestBase._testPool_1_2.<locals>.<lambda>XrTrc��yr#rVrWs rr(z.ADBAPITestBase._testPool_1_2.<locals>.<lambda>XrYr)r	r[rr/r]r^s`  rrBzADBAPITestBase._testPool_1_2Vs4��������� 8� 8�:R�S��	���<�n�M��rc���tj�jj�j�}|j�fd�d��|S)Nc�&���jd�SrQrRr&s �rr(z.ADBAPITestBase._testPool_1_3.<locals>.<lambda>]rTrc��yr#rVrWs rr(z.ADBAPITestBase._testPool_1_3.<locals>.<lambda>]rYr)r	r[r�runInteraction�bad_interactionr]r^s`  rrCzADBAPITestBase._testPool_1_3[s9��������� :� :�D�<P�<P�Q��	���<�n�M��rc���tj�jj�j�}|j�fd�d��|S)Nc�&���jd�SrQrRr&s �rr(z.ADBAPITestBase._testPool_1_4.<locals>.<lambda>brTrc��yr#rVrWs rr(z.ADBAPITestBase._testPool_1_4.<locals>.<lambda>brYr)r	r[r�runWithConnection�bad_withConnectionr]r^s`  rrDzADBAPITestBase._testPool_1_4`s9��������� =� =�t�?V�?V�W��	���<�n�M��rc�n��d}�jj|�}�fd�}|j|�|S)N�select count(1) from simplec�n���jt|dd�dk(d��j�y)NrzInteraction not rolled back)r9�intr;��rowrs �r�_checkz*ADBAPITestBase._testPool_2.<locals>._checkjs/����O�O�C��A��q�	�N�a�/�1N�O��#�#�%r�rr\r0�rr'�sqlr2rrs`    rrEzADBAPITestBase._testPool_2es4���+���K�K� � ��%��	&�	
�
�
�f���rc�$��d}g}t�j�D]1}d|z}|j�jj	|���3tj|�}�fd�}|j|��fd�}|j|�|S)Nrmz insert into simple(x) values(%d)c�B��d}�jj|�}|S)N�select x from simple order by x)rr\)r'rur2rs   �r�_selectz+ADBAPITestBase._testPool_3.<locals>._selectzs!���3�C����$�$�S�)�A��Hrc����jt|��jk(d�t�j�D]>}�jt||�dk(d��j||d|k(d��@y)NzWrong number of rows��Wrong size rowrzValues not returned.)r9�len�num_iterations�range)�rows�irs  �rrrz*ADBAPITestBase._testPool_3.<locals>._check�st����O�O�C��I��)<�)<�<�>T�U��4�.�.�/�
I������D��G��� 1�3C�D�����Q���
�a��1G�H�
Ir)rr~�appendrr/r	�
gatherResultsr0)rr'ru�insertsr�r2ryrrs`       rrFzADBAPITestBase._testPool_3qs����+�����t�*�*�+�	:�A�4�q�8�C��N�N�4�;�;�3�3�C�8�9�	:�
����(��	�	
�
�
�g��	I�	
�
�
�f���rc�z���jj�j�}|j�fd��|S)Nc�(���j|d�S�N�done��assertEqualr&s �rr(z,ADBAPITestBase._testPool_4.<locals>.<lambda>�����$�"2�"2�3��"?�r)rre�interactionr0r^s`  rrGzADBAPITestBase._testPool_4�s/����K�K�&�&�t�'7�'7�8��	�
�
�?�@��rc�z���jj�j�}|j�fd��|S)Nc�(���j|d�Sr�r�r&s �rr(z,ADBAPITestBase._testPool_5.<locals>.<lambda>�r�r)rrj�withConnectionr0r^s`  rrHzADBAPITestBase._testPool_5�s/����K�K�)�)�$�*=�*=�>��	�
�
�?�@��rc�P�|jj|j�}|Sr#)rrj�close_withConnectionr^s   rrIzADBAPITestBase._testPool_6�s!���K�K�)�)�$�*C�*C�D���rc���g}t�j�D]1}d|z}|j�jj	|���3tj|d��}�fd�}|j|�|S)Nz!select x from simple where x = %dT��fireOnOneErrbackc�|��t�j�D]#}�j||ddd|k(d��%y)Nr{rzValue not returned)rr~r9)�resultr�rs  �rrrz*ADBAPITestBase._testPool_7.<locals>._check�sD����4�.�.�/�
O������q�	�!��Q��� 2�a� 7�9M�N�
Or)rr~r�rr\r	�DeferredListr0)rr'�dsr�ru�dlistrrs`      rrJzADBAPITestBase._testPool_7�sv���
���t�*�*�+�	1�A�5��9�C��I�I�d�k�k�*�*�3�/�0�	1��"�"�2��=��	O�	���&�!��rc���g}t|j�D]1}d|z}|j|jj	|���3tj|d��}|S)Nzdelete from simple where x = %dTr�)rr~r�rr/r	r�)rr'r�r�rur�s      rrKzADBAPITestBase._testPool_8�s_��
���t�*�*�+�	5�A�3�a�7�C��I�I�d�k�k�.�.�s�3�4�	5��"�"�2��=���rc�n��d}�jj|�}�fd�}|j|�|S)Nrmc�n���jt|dd�dk(d��j�y)Nrz)Didn't successfully delete table contents)r9ro�checkConnectrps �rrrz*ADBAPITestBase._testPool_9.<locals>._check�s4����O�O��C��F�1�I��!�#�%P�
�
���rrsrts`    rrLzADBAPITestBase._testPool_9�s4���+���K�K� � ��%��	 �	
�
�
�f���rc�l�|jj�}|j|�|j�}|j	d�|j	d�|j�}|j
t|�d�|j
t|d�d�|j
|ddd�|j	d�|j	d�|j
t|j��d�|j�|jj|�y)z/Check the connect/disconnect synchronous calls.zinsert into simple(x) values(1)zselect x from simpler{rzdelete from simpleN)
r�connectr;�cursor�execute�fetchallr�r}r%�
disconnect)rr7�cursr's    rr�zADBAPITestBase.checkConnect�s����{�{�"�"�$������%��{�{�}�����6�7����+�,��m�m�o������S��1�%�����S��V��a�(�����Q����A�&����)�*����+�,�����T�]�]�_�-�q�1��
�
�������t�$rc�&�|jd�t|j�D]H}|j�}|j	t|�dk(d�|j	|d|k(d��J|j
|j�d�y)Nrxr{r|r�Value not returned.z
Too many rowsr�)r�rr~�fetchoner9r}�assertIsNone)r�transactionr�rqs    rr�zADBAPITestBase.interaction�s������=�>��t�*�*�+�	@�A��&�&�(�C��O�O�C��H��M�+;�<��O�O�C��F�a�K�)>�?�	@�	
���+�.�.�0�/�B�rc�`�|jr|jd�|jd�y)Nzinsert into simple(x) values(0)rO)�can_rollbackr�)rr�s  rrfzADBAPITestBase.bad_interaction�s)�������� A�B����3�4rc�T�|j�}	|jd�t|j�D]H}|j	�}|jt
|�dk(d�|j|d|k(d��J	|j�y#|j�wxYw)Nrxr{r|rr�r�)r�r�rr~r�r9r}r%)rr7r�r�rqs     rr�zADBAPITestBase.withConnection�s����{�{�}��	��L�L�:�;��4�.�.�/�
D���m�m�o������C��A�
�/?�@�����A��!��-B�C�
D�

�J�J�L���
�J�J�L�s�A1B�B'c�$�|j�yr#)r%r6s  rr�z#ADBAPITestBase.close_withConnection�s���
�
�rc��|j�}	|jd�|j�y#|j�wxYw)NrO)r�r�r%)rr7r�s   rrkz!ADBAPITestBase.bad_withConnection�s2���{�{�}��	��L�L�0�1��J�J�L��D�J�J�L�s	�4�Ar#)$�__name__�
__module__�__qualname__�__doc__rr�object�bool�__annotations__r
�IReactorThreadsr�skiprr3rr;rMrArBrCrDrErFrGrHrIrJrKrLr�r�rfr�r�rkrVrrrrs����*,�N�D����&�+�!�z�!�!�'�4�0�8�F����)�5��$�
�
�
�

��6���

���%�"�5�
��rrc�j�eZdZdZej
ed��dZd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zy)�ReconnectTestBasez;
    Test the asynchronous DB-API code with reconnect.
    Nrc��|j�tjd��|j�|j	dd|j��|_|j
j
�|j
jt�S)z�
        Skip the test if C{good_sql} is unavailable.  Otherwise, set up the
        database, create a connection pool pointed at it, and set up a simple
        schema in it.
        zno good sql for reconnect testr{T)�cp_max�cp_reconnect�cp_good_sql)	�good_sqlr�SkipTestrrrrr/r?rs rrzReconnectTestBase.extraSetUpsq���=�=� ��#�#�$D�E�E������m�m��4�T�]�]�$�
���	
�������{�{�'�'�(;�<�<rc����jjd�}|j�fd��|j�fd��|S)Nr!c�8���jj�Sr#r$r&s �rr(z,ReconnectTestBase.tearDown.<locals>.<lambda>r)rc�$���j�Sr#r+r&s �rr(z,ReconnectTestBase.tearDown.<locals>.<lambda>r-rr.r1s` rr3zReconnectTestBase.tearDownr4rc�V�tjd�}|j|j�|j|j�|j
s|j|j�|j|j�|j|j�|Sr#)	r	�succeedr0�_testPool_1rE�early_reconnectrFrGrHr1s  rrMzReconnectTestBase.test_poolsx���M�M�$���	�
�
�d�&�&�'�	�
�
�d�&�&�'��#�#�
�M�M�$�*�*�+�	�
�
�d�&�&�'�	�
�
�d�&�&�'��rc�n��d}�jj|�}�fd�}|j|�|S)Nrmc�N���jt|dd�dk(d�y�NrzTable not empty�r9rorps �rrrz-ReconnectTestBase._testPool_1.<locals>._check%�#����O�O�C��A��q�	�N�a�/�1B�Crrsrts`    rr�zReconnectTestBase._testPool_1!�5���+���K�K� � ��%��	D�	
�
�
�f���rc��t|jjj��dj	�y)Nr)�listr�connections�valuesr%)rr's  rrEzReconnectTestBase._testPool_2+s+���T�[�[�
$�
$�
+�
+�
-�.�q�1�7�7�9rc���d}tj�jj|�}|j	�fd�d��|S)Nrmc�&���jd�SrQrRr&s �rr(z/ReconnectTestBase._testPool_3.<locals>.<lambda>2rTrc��yr#rVrWs rr(z/ReconnectTestBase._testPool_3.<locals>.<lambda>2rYrrZ�rr'rur2s`   rrFzReconnectTestBase._testPool_3/s8���+�������� 4� 4�c�:��	���<�n�M��rc�n��d}�jj|�}�fd�}|j|�|S)Nrmc�N���jt|dd�dk(d�yr�r�rps �rrrz-ReconnectTestBase._testPool_4.<locals>._check9r�rrsrts`    rrGzReconnectTestBase._testPool_45r�rc����j�d}tj�jj|�}|j�fd��fd��|S)NrOc�&���jd�SrQrRr&s �rr(z/ReconnectTestBase._testPool_5.<locals>.<lambda>Ds����	�	�.�1�rc�L���j|jt��Sr#)�assertFalse�checkr)rXrs �rr(z/ReconnectTestBase._testPool_5.<locals>.<lambda>Es���d�&�&�q�w�w�~�'>�?�r)r>r	r[rr\r]r�s`   rrHzReconnectTestBase._testPool_5?sI������ �%�������� 4� 4�c�:��	���1�?�	
��r)r�r�r�r�r
r�rr�rr3rMr�rErFrGrHrVrrr�r��sK���"�z�!�!�'�4�0�8�F��
=����:���rr�c��eZdZUdZdZeeed<dZdZ	dZ
dZdZdZ
dZdZdZej$Zeeed<dZdZdZd�Zd	�Zd
�Zd�Zd�Zd
�Zy)�DBTestConnectora>
    A class which knows how to test for the presence of
    and establish a connection to a relational database.

    To enable test cases  which use a central, system database,
    you must create a database named DB_NAME with a user DB_USER
    and password DB_PASS with full access rights to database DB_NAME.
    N�TEST_PREFIX�twisted_testTr��2c���|j�|_tj|j�|j	�s"tjd|jz��|j�S)Nz%s: Cannot access db)	�mktemp�DB_DIR�os�mkdir�can_connectrr�r�rrs r�setUpzDBTestConnector.setUpisU���k�k�m���
����������!��#�#�$:�T�=M�=M�$M�N�N���� � rc��t��)zXReturn true if this database is present on the system
        and can be used in a test.��NotImplementedErrorrs rr�zDBTestConnector.can_connectps
��"�#�#rc��y)z+Take any steps needed to bring database up.NrVrs rrzDBTestConnector.startDBu���rc��y)zBring database down, if needed.NrVrs rr,zDBTestConnector.stopDByr�rc��|j�\}}|j�}|j|�t|i|��S)z;Create a connection pool with additional keyword arguments.)�getPoolArgs�copy�updater)r�newkw�args�kws    rrzDBTestConnector.makePool}s;���#�#�%���b�
�W�W�Y��
�	�	�%���t�*�r�*�*rc��t��)z�Return a tuple (args, kw) of list and keyword arguments
        that need to be passed to ConnectionPool to create a connection
        to this database.r�rs rr�zDBTestConnector.getPoolArgs�s
��"�#�#r)r�r�r�r�r�r�strr��DB_NAME�DB_USER�DB_PASSr��nulls_ok�trailing_spaces_okr�r@�escape_slashesrr�r��	can_clearr~r�r�rr,rr�rVrrr�r�Js����"&�K��#��%��G��G��G�
�F��H����L��M��N�,�5�5�H�h�s�m�5��O��I��N�!�$�

�
�+�$rr�c�.�eZdZdZdZdZdZd�Zd�Zd�Z	y)	�SQLite3ConnectorzB
    Connector that uses the stdlib SQLite3 database support.
    �SQLite3Fr{c��td��yy)N�sqlite3FTr
rs rr�zSQLite3Connector.can_connect�s����#�+��rc��tjj|j|j�|_tjj
|j
�r tj|j
�yyr#�r��path�joinr�r��database�exists�unlinkrs rrzSQLite3Connector.startDB��I�������T�[�[�$�,�,�?��
�
�7�7�>�>�$�-�-�(��I�I�d�m�m�$�)rc�.�d}|jddd�}||fS)N)rr{F�rr��check_same_thread�r�rr�r�s   rr�zSQLite3Connector.getPoolArgs�s �����-�-�1�5�
Q���R�x�rN�
r�r�r�r�r�r�r~r�rr�rVrrr�r��s'����K��N��N��%�
rr�c�.�eZdZdZdZdZdZd�Zd�Zd�Z	y)	�PySQLite2ConnectorzA
    Connector that uses pysqlite's SQLite database support.
    �	pysqlite2Fr{c��td��yy)N�pysqlite2.dbapi2FTr
rs rr�zPySQLite2Connector.can_connect�s���+�,�4��rc��tjj|j|j�|_tjj
|j
�r tj|j
�yyr#rrs rrzPySQLite2Connector.startDB�r
rc�.�d}|jddd�}||fS)N)rr{Frrrs   rr�zPySQLite2Connector.getPoolArgs�s ��$���-�-�1�5�
Q���R�x�rNrrVrrrr�s'����K��N��N��%�
rrc��eZdZdZd�Zd�Zy)�PyPgSQLConnector�PyPgSQLc���	ddlm}	|j|j|j
|j��}|j�y#t$rYywxYw#t$rYywxYw)Nr)�PgSQLF�r�user�passwordT)�pyPgSQLr�
BaseExceptionr�r�r�r�r%)rrr7s   rr�zPyPgSQLConnector.can_connect�sj��	�%�	��=�=����D�L�L�4�<�<�!��D�
�J�J�L����	��	���	��	�s#�A�AA�	A�A�	A'�&A'c�X�d}|j|j|jdd�}||fS)N)z
pyPgSQL.PgSQLr�rrr�cp_min�r�r�r�rs   rr�zPyPgSQLConnector.getPoolArgs�s1��!������L�L�����	
���R�x�rN�r�r�r�r�r�r�rVrrrr�����K��rrc��eZdZdZd�Zd�Zy)�PsycopgConnector�Psycopgc���	ddl}	|j|j|j|j
��}|j
�y#t$rYywxYw#t$rYywxYw)NrFrT)�psycopgr!r�r�r�r�r%)rr,r7s   rr�zPsycopgConnector.can_connect�sj��	��	��?�?����D�L�L�4�<�<�#��D�
�J�J�L����	��	���	��	��#�A
�AA�
	A�A�	A%�$A%c�X�d}|j|j|jdd�}||fS)N)r,rr#r%rs   rr�zPsycopgConnector.getPoolArgs�s1��������L�L�����	
���R�x�rNr&rVrrr)r)�r'rr)c�(�eZdZdZdZdZdZd�Zd�Zy)�MySQLConnector�MySQLFc���	ddl}	|j|j|j|j
��}|j
�y#t$rYywxYw#t$rYywxYw)NrF��dbr�passwdT)�MySQLdbr!r�r�r�r�r%)rr6r7s   rr�zMySQLConnector.can_connect�sj��	��	��?�?��<�<�d�l�l�4�<�<�#��D�
�J�J�L����	��	���	��	�r-c�V�d}|j|j|jd�}||fS)N)r6r3r%rs   rr�zMySQLConnector.getPoolArgss(�����L�L�$�,�,�$�,�,�
O���R�x�rN)	r�r�r�r�r�r�r�r�r�rVrrr0r0�s!���K����L��O��rr0c�<�eZdZdZdZdZdZdZdZd�Z	d�Z
d�Zd�Zy)	�FirebirdConnector�FirebirdFN�c�|�td��y	|j�|j�y#t$rYywxYw)N�kinterbasdbFT)rrr,r!rs rr�zFirebirdConnector.can_connects<����'�/��	��L�L�N��K�K�M����	��	�s� /�	;�;c��ddl}tjj|jt
j�|_tj|jtjtjztjz�d}||j|j|jfz}|j|�}|j�y)Nrz,create database "%s" user "%s" password "%s")r=r�rrr�r�r��chmod�stat�S_IRWXU�S_IRWXG�S_IRWXOr�r��create_databaser%)rr=rur7s    rrzFirebirdConnector.startDB&s�����w�w�|�|�D�K�K��1H�1H�I���
������d�l�l�T�\�\�9�D�L�L�H�I�<������d�l�l�D�L�L�9�9���*�*�3�/���
�
�rc�X�d}|jd|j|jd�}||fS)N)r=�	127.0.0.1�r�hostrrr%rs   rr�zFirebirdConnector.getPoolArgs0s1���������L�L����	
���R�x�rc��ddl}|j|jd|j|j��}|j�y)NrrFrG)r=r�r�r�r��
drop_database)rr=r7s   rr,zFirebirdConnector.stopDB:s@����"�"��\�\������\�\�	#�
��	
���r)
r�r�r�r�r@r�r�r�r~r�rr�r,rVrrr9r9s4���K��M��N��H��I��N����	rr9c�l��tttttt
g}i}|D]{��j|z}G�fd�d�|tj�}||_	t�d�r5dj�jj�dd|gz�|_|||<�}|j|�y)aQ
    Make a test case for every db connector which can connect.

    @param base: Base class for test case. Additional base classes
                 will be a DBConnector subclass and unittest.TestCase
    @param suffix: A suffix used to create test case names. Prefixes
                   are defined in the DBConnector subclasses.
    c�(��eZdZW�jZy)�makeSQLTests.<locals>.testcaseN)r�r�r�)�	connclasss�r�testcaserM[s���"�-�-�JrrOr��.r���N)rr�rr)r0r9r�r�TestCaser��hasattrrr��splitr�)�base�suffix�globals�
connectors�tests�namerOrNs       @r�makeSQLTestsr[Fs����	������
�J�
�E���	��$�$�v�-��	.�y�$��(9�(9�	.�!����9�n�-�$'�H�H��&�&�,�,�.�q��4��v�=�%�H�!���d����N�N�5�r�ADBAPITests�ReconnectTestsc�*�eZdZdZdZdZd�Zd�Zd�Zy)�FakePoolz�
    A fake L{ConnectionPool} for tests.

    @ivar connectionFactory: factory for making connections returned by the
        C{connect} method.
    @type connectionFactory: any callable
    Tc��||_yr#��connectionFactory)rrbs  r�__init__zFakePool.__init__}s
��!2��rc�"�|j�S)zB
        Return an instance of C{self.connectionFactory}.
        rars rr�zFakePool.connect�s���%�%�'�'rc��y)z
        Do nothing.
        NrV)r�
connections  rr�zFakePool.disconnect�rYrN)	r�r�r�r��	reconnect�noisyrcr�r�rVrrr_r_qs"����I��E�3�(�rr_c��eZdZdZd�Zy)�ConnectionTestsz,
    Tests for the L{Connection} class.
    c�<�Gd�d�}t|�}t|�}|jt|j�|jt�}|jt|�d�|j|djjdd�y)z|
        If an error happens during rollback, L{ConnectionLost} is raised but
        the original error is logged.
        c��eZdZd�Zy)�IConnectionTests.test_rollbackErrorLogged.<locals>.ConnectionRollbackRaisec��td���N�problem!��RuntimeErrorrs r�rollbackzRConnectionTests.test_rollbackErrorLogged.<locals>.ConnectionRollbackRaise.rollback��
��"�:�.�.rN)r�r�r�rsrVrr�ConnectionRollbackRaiserm����
/rrur{rrpN)r_r�assertRaisesrrsr>rrr�r}�valuer�)rru�poolrf�errorss     r�test_rollbackErrorLoggedz(ConnectionTests.test_rollbackErrorLogged�s���	/�	/��/�0����%�
����.�*�*=�*=�>��'�'��5������V��a�(���������-�-�a�0�*�=rN)r�r�r�r�r{rVrrrjrj�s���>rrjc��eZdZdZd�Zy)�TransactionTestsz-
    Tests for the L{Transaction} class.
    c�(�Gd�d�}td�}t||��}|j�|jt�}|jt
|�d�|j|djjdd�y)z�
        If the cursor creation raises an error in L{Transaction.reopen}, it
        reconnects but log the error occurred.
        c��eZdZdZd�Zd�Zy)�NTransactionTests.test_reopenLogErrorIfReconnect.<locals>.ConnectionCursorRaiserc��yr#rVrs rrgzXTransactionTests.test_reopenLogErrorIfReconnect.<locals>.ConnectionCursorRaise.reconnect����rc�b�|jdk(r |xjdz
c_td��y)Nrr{rp)�countrrrs rr�zUTransactionTests.test_reopenLogErrorIfReconnect.<locals>.ConnectionCursorRaise.cursor�s*���:�:��?��J�J�!�O�J�&�z�2�2�#rN)r�r�r�r�rgr�rVrr�ConnectionCursorRaiser��s���E�
�
3rr�Nr{rrp)	r_r�reopenr>rrr�r}rxr�)rr�ryr�rzs     r�test_reopenLogErrorIfReconnectz/TransactionTests.test_reopenLogErrorIfReconnect�sz��		3�		3���~��!�$�(=�(?�@�������'�'��5������V��a�(���������-�-�a�0�*�=rN)r�r�r�r�r�rVrrr}r}�s���>rr}c��eZdZd�Zy)�
NonThreadPoolc�b�d}	||i|��}|||�y#t$rd}t�}Y�!wxYw)NTF)�	Exceptionr)r�onResultrX�ar��successr�s       r�callInThreadWithCallbackz&NonThreadPool.callInThreadWithCallback�sB����	���[�R�[�F�	��&�!���	��G��Y�F�	�s��.�.N)r�r�r�r�rVrrr�r��s��"rr�c�$�eZdZdZe�Zd�Zy)�DummyConnectionPoolz'
    A testable L{ConnectionPool};
    c��t|_y)z*
        Don't forward init call.
        N)r�_reactorrs rrczDummyConnectionPool.__init__�s�� ��
rN)r�r�r�r�r��
threadpoolrcrVrrr�r��s�����J� rr�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�EventReactora
    Partial L{IReactorCore} implementation with simple event-related
    methods.

    @ivar _running: A C{bool} indicating whether the reactor is pretending
        to have been started already or not.

    @ivar triggers: A C{list} of pending system event triggers.
    c� �||_g|_yr#)�_running�triggers)r�runnings  rrczEventReactor.__init__�s����
���
rc�P�|jr|�y|jdd|�S)N�after�startup)r��addSystemEventTrigger)r�functions  r�callWhenRunningzEventReactor.callWhenRunning�s#���=�=��J��-�-�g�y�(�K�Krc�F�|||f}|jj|�|Sr#)r�r�)r�phase�event�trigger�handles     rr�z"EventReactor.addSystemEventTrigger�s%�����(���
�
���V�$��
rc�:�|jj|�yr#)r��remove)rr�s  r�removeSystemEventTriggerz%EventReactor.removeSystemEventTrigger�s���
�
���V�$rN)r�r�r�r�rcr�r�r�rVrrr�r��s����L��
%rr�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�ConnectionPoolTestsz+
    Unit tests for L{ConnectionPool}.
    c���Gd�d�}d�}t�}||_|j|�}�j|t�}�fd�}|j|�|S)z�
        If rollback fails, L{ConnectionPool.runWithConnection} raises the
        original exception and log the error of the rollback.
        c��eZdZd�Zd�Zy)�]ConnectionPoolTests.test_runWithConnectionRaiseOriginalError.<locals>.ConnectionRollbackRaisec��yr#rV�rrys  rrczfConnectionPoolTests.test_runWithConnectionRaiseOriginalError.<locals>.ConnectionRollbackRaise.__init__r�rc��td��rorqrs rrszfConnectionPoolTests.test_runWithConnectionRaiseOriginalError.<locals>.ConnectionRollbackRaise.rollbackrtrN�r�r�r�rcrsrVrrrur����
�
/rruc��td���N�foo��
ValueError)rfs r�raisingFunctionzUConnectionPoolTests.test_runWithConnectionRaiseOriginalError.<locals>.raisingFunction
�
���U�#�#rc����jt�}�jt|�d��j|djj
dd�y�Nr{rrp�r>rrr�r}rxr���ignoredrzrs  �r�cbFailedzNConnectionPoolTests.test_runWithConnectionRaiseOriginalError.<locals>.cbFailed�J����+�+�L�9�F����S��[�!�,����V�A�Y�_�_�1�1�!�4�j�Ar)r�rbrj�
assertFailurer�r0)rrur�ryr2r�s`     r�(test_runWithConnectionRaiseOriginalErrorz<ConnectionPoolTests.test_runWithConnectionRaiseOriginalError�s_���	/�	/�	$�#�$��!8����"�"�?�3�����q�*�-��	B�
	
�
�
�h���rc��Gd�d�}t�}|j|��|jt�}|j	t|�d�|j	|djjdd�y)z;
        L{ConnectionPool._close} logs exceptions.
        c��eZdZd�Zy)�DConnectionPoolTests.test_closeLogError.<locals>.ConnectionCloseRaisec��td��rorqrs rr%zJConnectionPoolTests.test_closeLogError.<locals>.ConnectionCloseRaise.close rtrN)r�r�r�r%rVrr�ConnectionCloseRaiser�rvrr�r{rrpN)r��_closer>rrr�r}rxr�)rr�ryrzs    r�test_closeLogErrorz&ConnectionPoolTests.test_closeLogErrorsm��
	/�	/�#�$�����(�*�+��'�'��5������V��a�(���������-�-�a�0�*�=rc����Gd�d�}Gd�d�}d�}t�}||_||_|j|�}�j	|t
�}�fd�}|j
|�|S)z�
        If rollback fails, L{ConnectionPool.runInteraction} raises the
        original exception and log the error of the rollback.
        c��eZdZd�Zd�Zy)�^ConnectionPoolTests.test_runWithInteractionRaiseOriginalError.<locals>.ConnectionRollbackRaisec��yr#rVr�s  rrczgConnectionPoolTests.test_runWithInteractionRaiseOriginalError.<locals>.ConnectionRollbackRaise.__init__1r�rc��td��rorqrs rrszgConnectionPoolTests.test_runWithInteractionRaiseOriginalError.<locals>.ConnectionRollbackRaise.rollback4rtrNr�rVrrrur�0r�rruc��eZdZd�Zy)�WConnectionPoolTests.test_runWithInteractionRaiseOriginalError.<locals>.DummyTransactionc��yr#rV)rryrfs   rrcz`ConnectionPoolTests.test_runWithInteractionRaiseOriginalError.<locals>.DummyTransaction.__init__8r�rN)r�r�r�rcrVrr�DummyTransactionr�7s��
rr�c��td��r�r�)r�s rr�zVConnectionPoolTests.test_runWithInteractionRaiseOriginalError.<locals>.raisingFunction;r�rc����jt�}�jt|�d��j|djj
dd�yr�r�r�s  �rr�zOConnectionPoolTests.test_runWithInteractionRaiseOriginalError.<locals>.cbFailedEr�r)r�rb�transactionFactoryrer�r�r0)rrur�r�ryr2r�s`      r�)test_runWithInteractionRaiseOriginalErrorz=ConnectionPoolTests.test_runWithInteractionRaiseOriginalError*sq���	/�	/�	�	�	$�#�$��!8���"2�������0�����q�*�-��	B�
	
�
�
�h���rc���td�}td|��}|j|jdd|jfg�|j�|j
|j�y)z�
        If L{ConnectionPool.close} is called without L{ConnectionPool.start}
        having been called, the pool's startup event is cancelled.
        F�twisted.test.test_adbapi��
cp_reactorr�r�N)r�rr�r��_startr%r��rrrys   r�test_unstartedClosez'ConnectionPoolTests.test_unstartedCloseMs\��
�u�%���8�W�M������)�)�W�i����,M�+N�O��
�
������)�)�*rc���td�}td|��}|j|jdd|jfg�|j�|j
|j�y)z�
        If L{ConnectionPool.close} is called after it has been started, but
        not by its shutdown trigger, the shutdown trigger is cancelled.
        Tr�r��during�shutdownN)r�rr�r��
finalCloser%r�r�s   r�test_startedClosez%ConnectionPoolTests.test_startedCloseZs\��
�t�$���8�W�M������)�)�X�z�4�?�?�,S�+T�U��
�
������)�)�*rN)	r�r�r�r�r�r�r�r�r�rVrrr�r��s!����:>� !�F+�+rr�))r�r�r@�typingrr�twisted.enterprise.adbapirrrr�twisted.internetr	r
r�twisted.python.failurer�twisted.python.reflectr�
twisted.trialrr?rr�r�r�rrr)r0r9r[rWr_rRrjr}r�r�r�r�rVrr�<module>r�s0���
��!���8�7�*�0�"���Y�Y�xM�M�`>$�>$�B���4���4���8���8�_��61��1�h�H
�^�]�G�I�6�
�
� 0�'�)�<���6>�h�'�'�>�.>�x�(�(�>�<"�"� �.� �%�%�<m+�(�+�+�m+r

Zerion Mini Shell 1.0