https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/trac/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/__pycache__/test.cpython-310.pyc
o

�k�`�S�@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZzddlmZWneyOdZYnwe�d�ZddlZddlmZddlmZmZmZddlmZmZddlm Z ddl!m"Z"dd	l#m$Z$dd
l%m&Z&ddl'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-dd
l.m/Z/ddl0m1Z1d+dd�Z2Gdd�de3�Z4dd�Z5Gdd�dej6�Z7Gdd�dej8�Z9dd�Z:Gdd�de �Z;dd�Z<d d!�Z=d"d#�Z>d$a?d%d&�Z@eAd'k�rd(e
jBvr�e
jB�Cd(�d)a?ejDd&d*�dSdS),�N)�Locale�en_US)�
Configuration)�ComponentManager�
ComponentMeta�	TracError)�DatabaseManager�parse_connection_uri)�Environment)�PermissionCache)�load_workflow_config_snippet)�translation)�time_now�utc)�_RequestArgs�Request�arg_list_to_args)�Chrome��Session�c
Os�t|t�s|f}i}dd�}|D]'}t�||�}t�|�D]\}}||vr&qt|tj�s2t|dd�r6|||<qqt	d||�}	|	|�}
|�
�D]
\}}t|
||�qF|
S)a�
    Simple factory for dummy classes that can be used as replacement for the
    real implementation in tests.

    Base classes for the mock can be specified using the first parameter, which
    must be either a tuple of class objects or a single class object. If the
    bases parameter is omitted, the base class of the mock will be object.

    So to create a mock that is derived from the builtin dict type, you can do:

    >>> mock = Mock(dict)
    >>> mock['foo'] = 'bar'
    >>> mock['foo']
    'bar'

    Attributes of the class are provided by any additional keyword parameters.

    >>> mock = Mock(foo='bar')
    >>> mock.foo
    'bar'

    Objects produces by this function have the special feature of not requiring
    the 'self' parameter on methods, because you should keep data at the scope
    of the test function. So you can just do:

    >>> mock = Mock(add=lambda x,y: x+y)
    >>> mock.add(1, 1)
    2

    To access attributes from the mock object from inside a lambda function,
    just access the mock itself:

    >>> mock = Mock(dict, do=lambda x: 'going to the %s' % mock[x])
    >>> mock['foo'] = 'bar'
    >>> mock.do('foo')
    'going to the bar'

    Because assignments or other types of statements don't work in lambda
    functions, assigning to a local variable from a mock function requires some
    extra work:

    >>> myvar = [None]
    >>> mock = Mock(set=lambda x: myvar.__setitem__(0, x))
    >>> mock.set(1)
    >>> myvar[0]
    1
    c_st��N)�NotImplementedError)�self�args�kwargsrr�+/usr/lib/python3/dist-packages/trac/test.py�dummyfno�zMock.<locals>.dummyfn�__isabstractmethod__F�Mock)�
isinstance�tuple�types�
MethodType�inspect�
getmembers�abc�abstractproperty�getattr�type�items�setattr)
�bases�initargs�kw�attrsr�base�fn�name�attr�cls�mock�k�vrrrr 9s(
0
���r c@sBeZdZdZdZ		ddd�ZeZddd�Z		d
d	d
�ZeZ	dS)�MockPermzWFake permission class. Necessary as Mock can not be used with operator
    overloading.�NFcC�dS)NTr)r�action�realm_or_resource�id�versionrrr�has_permission��zMockPerm.has_permissioncCs|Srr)rr=r>r?rrr�__call__�rzMockPerm.__call__cC�dSrr)rr<r=r>r?�messagerrr�require�rAzMockPerm.require)NFF)FF)NFFN)
�__name__�
__module__�__qualname__�__doc__�usernamer@�__contains__rBrE�assert_permissionrrrrr9�s
�

�r9cs���d���durd�t��nt�����fdd��d�vr.�fdd��dD��t���nt�����fd	d
���di���D���fdd��D�����d
��dd���dd���dd���dd���dd���d����dd���dd���dd�d�}|D]}t||t	�r�t
||d�||<q�g�	i�t���d0���	fd d!�	}t
t||�}�	|_�|_�|_|j��fd"d#��fd$d#��fd%d#�t��j�fd&d#��fd'd#��fd(d#��fd)d#��fd*d#��fd+d#�d,d#�d-d#�d.d#�d/�
�|S)1aORequest object for testing. Keyword arguments populate an
    `environ` dictionary and the callbacks.

    If `authname` is specified in a keyword arguments a `PermissionCache`
    object is created, otherwise if `authname` is not specified or is
    `None` a `MockPerm` object is used and the `authname` is set to
    'anonymous'.

    The following keyword arguments are commonly used:
    :keyword args: dictionary of request arguments
    :keyword authname: the name of the authenticated user, or 'anonymous'
    :keyword method: the HTTP request method
    :keyword path_info: the request path inside the application

    Additionally `cookie`, `format`, `language`, `lc_time`, `locale`,
    `remote_addr`, `remote_user`, `script_name`, `server_name`, `server_port`
    and `tz` can be specified as keyword arguments.

    :since: 1.0.11
    �authnameN�	anonymouscsNt|t�rtt|��St|tj�rt|�St|ttf�r%�fdd�|D�S|S)Ncsg|]}�|��qSrr)�.0r8��convertrr�
<listcomp>�sz0MockRequest.<locals>.convert.<locals>.<listcomp>)r!�bool�str�int�numbers�Real�listr")�valrPrrrQ�s
zMockRequest.<locals>.convert�arg_listcsg|]
\}}|�|�f�qSrr�rOr7r8rPrrrR�szMockRequest.<locals>.<listcomp>c3s �|]\}}|�|�fVqdSrrr[rPrr�	<genexpr>�s��zMockRequest.<locals>.<genexpr>rcs$g|]}��|�D]}||f�q	qSr)�getlist)rOr3�value�rrrrR�s
���http�languager:�cookie�	path_info�/�method�GET�remote_addrz	127.0.0.1�remote_user�script_namez	/trac.cgi�server_name�	localhost�server_port�80)z
trac.base_urlzwsgi.url_scheme�HTTP_ACCEPT_LANGUAGE�HTTP_COOKIE�	PATH_INFO�REQUEST_METHOD�REMOTE_ADDR�REMOTE_USER�SCRIPT_NAME�SERVER_NAME�SERVER_PORTzutf-8cs��|���t|���jSr)�append�update�dict�write)�status�headers�exc_info)�headers_sent�
response_sent�status_sentrr�start_response�s
z#MockRequest.<locals>.start_responsec��Srr��req)rZrr�<lambda>��zMockRequest.<locals>.<lambda>cr�rrr�r_rrr��r�cr�rrr�)rMrrr��r�cs��dd�S)N�
form_tokenr��getr��rrrr���c���dt�S)N�lc_time)r��	locale_enr�r�rrr��r�cs
��d�S)N�localer�r�r�rrr���
cr�rrr�)�permrrr��r�cs
t�|�Srrr�)�envrrr��r�cr�)N�tz)r�rr�r�rrr��r�cSr;)NFrr�rrrr��r�cSrCrrr�rrrr��r�cSsgSrrr�rrrr��r�)
rZrrM�chromer�r�r�r��sessionr��
use_xsendfile�xsendfile_header�configurable_headersr)r�r9rrrrxr+�abs_hrefr!�bytesrT�io�BytesIOr rr�r~r�	callbacksr�prepare_request)r�r�environ�keyr�r�r)
rZrrMrQr�r~rr�rr�r�MockRequest�sl



�








�
�








�r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�	TestSetupzh
    Test suite decorator that allows a fixture to be setup for a complete
    suite of test cases.
    cCr;)z4Sets up the fixture, and sets self.fixture if neededNr�rrrr�setUp�rAzTestSetup.setUpcCr;)zTears down the fixtureNrr�rrr�tearDownrAzTestSetup.tearDowncCsN|��t|d�r|jD]
}t|d�r|�|j�qtj�||�|��|S)zuSetup the fixture (self.setUp), call .setFixture on all the tests,
        and tear down the fixture (self.tearDown).�fixture�
setFixture)	r��hasattr�_testsr�r��unittest�	TestSuite�runr�)r�result�testrrrr�s


�z
TestSetup.runcOsZ|��t|d�r|jD]
}t|d�r|�|j�qtjj|g|�Ri|��|��dS)zLPython 2.7 / unittest2 compatibility - there must be a better
        way...r�r�N)	r�r�r�r�r�r�r��_wrapped_runr�)rrrr�rrrr�s


�zTestSetup._wrapped_runN)rFrGrHrIr�r�r�r�rrrrr��sr�c@seZdZdd�ZdS)�
TestCaseSetupcCs
||_dSr)r�)rr�rrrr�s
zTestCaseSetup.setFixtureN)rFrGrHr�rrrrr�sr�cCs�tj�d�}|rHt|�\}}|dkr(|�di��d�s(|d|vr"dndd7}n&|dkrG|d	d
krG|�di��d�sG|d|vrBdndd7}nd}d
|}t�d|�|S)N�TRAC_TEST_DB_URI�postgres�params�schema�?�&zschema=tractest�sqlite�pathz:memory:�synchronouszsynchronous=offz%s::memory:ztrac.db.%s_backend)�osr�r�r	�	importlib�
import_module)�dburi�scheme�db_proprrr�	get_dburi%s ���r�c@sdeZdZdZdZdZ		ddd�Zdd�Zed	d
��Z	ddd�Z
d
d�Zdd�Zdd�Z
dd�ZdS)�EnvironmentStubz5A stub of the trac.env.Environment class for testing.FTNcCs�|durt|ttf�std��|durt|ttf�std��t�|�d|_d|_ddl}||_	|j	durAt
j	�t
j	�|j
��|_	t
j	�t
j	�|j	��|_	td�|_t|jd�|j�ddd�|j�dd	d
�|duru|j�ddd
�n|j�ddd�|p�dD]}|�|�}	|j�d|	d�q�|p�dD]}|�|�}	|j�d|	d
�q�|j�ddd�|p�gD]}
|jj|
�q�|��t�|_|j�ddd�|j�dd|j�|s�|�|�|j�ddd�t�t�dS)a�Construct a new Environment stub object.

        :param default_data: If True, populate the database with some
                             defaults.
        :param enable: A list of component classes or name globs to
                       activate in the stub environment.
        :param disable: A list of component classes or name globs to
                        deactivate in the stub environment.
        :param path: The location of the environment in the file system.
                     No files or directories are created when specifying
                     this parameter.
        :param destroying: If True, the database will not be reset. This is
                           useful for cases when the object is being
                           constructed in order to call `destroy_db`.
        :param config: A list of (section, key, value) configuration
                       tuples.
        Nz(Keyword argument "enable" must be a listz)Keyword argument "disable" must be a listrzbasic-workflow.ini�logging�	log_level�DEBUG�log_type�none�
componentsztrac.*�disabledztracopt.versioncontrol.*�enabledr�trac�permission_policiesz/DefaultPermissionPolicy, LegacyAttachmentPolicyz	trac.db.*�database�base_urlzhttp://example.org/trac.cgi)r!rXr"�	TypeErrorr�__init__�
_old_registry�_old_componentsr�r�r��abspath�dirname�__file__�normpath�normcaser�configr�set�_component_name�	setup_logr�r��reset_dbr
�activater�)r�default_data�enable�disabler��
destroyingr�r��
name_or_class�
config_key�itemrrrr�>sP



�


�
zEnvironmentStub.__init__cCs�t�d�|_|j��}tjj�|�}|j�|�tj	j
}|jj	s8|tj�}t�
|j�}|�|�|j�|�dSt|jj	�dkrSt|jj	d|�rS|jj	d��dStd��)Nz	trac.test�rz!Logger has unexpected handler(s).)r��	getLogger�logr��upperr��
LOG_LEVEL_MAPr��setLevel�handlers�BufferingHandler�sys�maxsize�	Formatter�
log_format�setFormatter�
addHandler�lenr!�flushr)r�level�level_as_int�handler_cls�log_handler�	formatterrrrr��s


�zEnvironmentStub.setup_logcCsdd�|jjdjD�S)z*Returns a list of tuples (level, message).cSsg|]	}|j|��f�qSr)�	levelname�
getMessage)rO�recordrrrrR�s�z0EnvironmentStub.log_messages.<locals>.<listcomp>r)r�r��bufferr�rrr�log_messages�s�zEnvironmentStub.log_messagesc	Cs�ddlm}g}t|�}z|��}Wn
t|jjfyYnw||jkr*|��}n|�	�|s=|�
�|jdkr=|��|rC|�
�|�|j�dS)z�Remove all data from Trac tables, keeping the tables themselves.

        :param default_data: after clean-up, initialize with default data
        :return: True upon success
        r)�
db_defaultzsqlite::memory:N)r�r�r�get_database_versionr�db_exc�
DatabaseError�
db_version�reset_tables�
destroy_db�init_dbr��shutdown�insert_default_data�set_database_version)rr�r��tables�dbmrrrrr��s$�


zEnvironmentStub.reset_dbc	Cs0z	t|���WdSt|jjfyYdSw)zDestroy the database.N)rrrrrr�rrrr�s
�zEnvironmentStub.destroy_dbcCs6|��|��t|jj�|jdur|��dSdS)z�Performs a complete environment reset in a robust way.

        The database is reset, then the connections are shut down, and
        finally all environment files are removed from the disk.
        N)r�r�rmtreer�r�r��restore_component_registryr�rrr�reset_db_and_disk�s
�z!EnvironmentStub.reset_db_and_diskcCs�|j�=}|D]1}t|�dkr|\}}}d}n|\}}}}|d||tt��f�|d|||f�|d|||f�qWd�dS1sCwYdS)a�Insert a tuple representing a user session to the
        `session` and `session_attributes` tables.

        The tuple can be length 3 with entries username, name and
        email, in which case an authenticated user is assumed. The
        tuple can also be length 4, with the last entry specifying
        `1` for an authenticated user or `0` for an unauthenticated
        user.
        �r�z'INSERT INTO session VALUES (%s, %s, %s)z6INSERT INTO session_attribute VALUES (%s,%s,'name',%s)z7INSERT INTO session_attribute VALUES (%s,%s,'email',%s)N)�db_transactionr�rUr)r�users�db�rowrJr3�email�
authenticatedrrr�insert_users�s"

����"�zEnvironmentStub.insert_userscCs |�|��d�r
dSt�||�S)Nz	__main__.T)r��
startswithr
�is_component_enabled)rr5rrrr�sz$EnvironmentStub.is_component_enabled)FNNNFNr)rFrGrHrI�required�abstractr�r��propertyr�r�rr
rrrrrrr�8s
�J

 	r�cCs tjdd�}tj�tj�|��S)zZCreate a temp directory with prefix `trac-tempenv`
    and return the directory name.
    z
trac-testdir-)�prefix)�tempfile�mkdtempr�r�r��realpath)�tmpdirrrrr�srcCsZtjdkrdnd}dgtjd�tj�D]}tj�|||�}tj�|�r*|SqdS)zRLocates a binary on the path.

    Returns the fully-qualified path, or None.
    �ntz.exer:�.�PATHN)r�r3r��split�pathsepr��join�exists)r2�exec_suffix�p�frrr�locate�s�r*csBd�fdd�	�tjdkrt|t�rt|t���}tj|�d�dS)Nr�c	s�|tjtjfvr	�|d}t|t�rEt�|�j}t�||dB�z||�WdStyD|dkr3�t	�
d��||||d�YdSw�)Nr�i��
g�������?)r��unlink�remover!�PermissionError�stat�st_mode�chmod�	Exception�time�sleep)�functionr��excinfo�retry�e�mode��onerrorrrr;
s

�zrmtree.<locals>.onerrorr r:)r�)	r�r3r!r�rTr��getfilesystemencoding�shutilr)r�rr:rrsrTcCs ddl}ddl}ddl}ddl}ddl}ddl}ddl}ddl}ddl}ddl	}ddl
}ddl}ddl}ddl
}ddl}ddl}ddl}ddl}tj�d�rPdat��}|�|j���|�|jj���|�|jj���|�|jj���|�|jj���|�|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%j+j���|�t,�-t.j/t0��t�r|�|j�1��|S)Nr�SKIP_FUNCTIONAL_TESTSF)2�
trac.tests�trac.admin.tests�
trac.db.tests�trac.mimeview.tests�trac.notification.tests�trac.search.tests�trac.ticket.tests�trac.timeline.tests�trac.upgrades.tests�trac.util.tests�trac.versioncontrol.tests� trac.versioncontrol.web_ui.tests�trac.web.tests�trac.wiki.tests�tracopt.perm.tests�tracopt.ticket.tests� tracopt.versioncontrol.git.tests� tracopt.versioncontrol.svn.testsr�r�r��INCLUDE_FUNCTIONAL_TESTSr�r��addTest�tests�
basicSuite�admin�
test_suiter�mimeview�notification�search�ticket�timeline�upgrades�util�versioncontrol�web_ui�web�wikir��git�svn�doctest�DocTestSuiter��modulesrF�functionalSuite)r��tracopt�suiterrrrV*sVrV�__main__z--skip-functional-testsF)�defaultTest)r)Er'rdr�r%r�r��logging.handlersrVr�r=r�rr3r#r��babelr�ImportErrorr��parse�trac.logr��trac.configr�	trac.corerrr�trac.db.apirr	�trac.envr
�	trac.permr�trac.ticket.default_workflowr�	trac.utilr
�trac.util.datefmtrr�trac.web.apirrr�trac.web.chromer�trac.web.sessionrr �objectr9r�r�r��TestCaser�r�r�rr*rrQrVrF�argvr-�mainrrrr�<module>sh�

Hd%?
1
�

https://t.me/RX1948 - 2025