HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pbr/tests/__pycache__/base.cpython-38.pyc
U

jP�^�"�@s�dZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
Gdd�dej�ZGdd�dej
ej�ZGd	d
�d
ej�Zdd�Zd
d�ZdS)z Common utilities used in testing�N)�content)�optionscs(eZdZdZdd�Z�fdd�Z�ZS)�DiveDirzaDive into given directory and return back on cleanup.

    :ivar path: The target directory.
    cCs
||_dS�N)�path)�selfr�r�0/usr/lib/python3/dist-packages/pbr/tests/base.py�__init__=szDiveDir.__init__cs0tt|���|�tjt���t�|j�dSr)�superr�setUp�
addCleanup�os�chdir�getcwdr)r��	__class__rr	r@sz
DiveDir.setUp��__name__�
__module__�__qualname__�__doc__r
r�
__classcell__rrrr	r7srcsDeZdZ�fdd�Zdd�Zdd�Zdd�Zgd	d
fdd�Z�ZS)
�BaseTestCasec	s
tt|���tj�dd�}zt|�}Wn tk
rHtd�d}YnX|dkrf|�	t
j|dd��tj�d�tj
kr�|�	t
�d��j}|�	t
�d	|��tj�d
�tj
kr�|�	t
�d��j}|�	t
�d|��|�	t
�d
��|_|�	t
���|�	t
���|�	t
���|�	t
�dd��|�	t
���j|_tj�|jd�|_t�tj�tj�t�d�|j�|�tj t�!��t� |j�|�|j"�t#|dd��s|�	t
�d��tj�|jd�}t$|d��}|�%�}W5QRX|�&dd�}t$|d��}|�'|�W5QRXdS)NZOS_TEST_TIMEOUT�z=OS_TEST_TIMEOUT set to invalid value defaulting to no timeoutrT)ZgentleZOS_STDOUT_CAPTURE�stdoutz
sys.stdoutZOS_STDERR_CAPTURE�stderrz
sys.stderr�pbrZPBR_VERSIONz0.0ZtestpackageZpreversionedz	setup.cfgZrtzversion = 0.1.dev�Zwt)(rrrr�environ�get�int�
ValueError�printZ
useFixture�fixturesZTimeoutrZTRUE_VALUESZStringStream�streamZMonkeyPatchZ
FakeLoggerZlog_fixtureZTempHomeDirZNestedTempfileZEnvironmentVariableZTempDirrZtemp_dir�join�package_dir�shutilZcopytree�dirname�__file__r
rr�_discard_testpackage�getattr�open�read�replace�write)rZtest_timeoutrrZsetup_cfg_pathZcfgrrrr	rHsL
��zBaseTestCase.setUpcCs.ttj�D]}|dks |�d�r
tj|=q
dS)NZpbr_testpackagezpbr_testpackage.)�list�sys�modules�
startswith)r�krrr	r+{s
�z!BaseTestCase._discard_testpackagecOs|jd|f|�S)Nr��_run_cmd�r�args�kwargsrrr	�run_pbr�szBaseTestCase.run_pbrcOs|jtjd|f|�S)N)zsetup.py)r7r2�
executabler8rrr	�	run_setup�szBaseTestCase.run_setupTNcCs@|p|j}t|gt|�|d�}|dr<|s<td|d��|S)afRun a command in the root of the test working copy.

        Runs a command, with the given argument list, in the root of the test
        working copy--returns the stdout and stderr streams and the exit code
        from the subprocess.

        :param cwd: If falsy run within the test package dir, otherwise run
            within the named path.
        )�cwd�zCommand failed retcode=%s)r'r7r1�	Exception)r�cmdr9Z
allow_failr>�resultrrr	r7�s


zBaseTestCase._run_cmd)	rrrrr+r;r=r7rrrrr	rFs
3rcs,eZdZdZ�fdd�Z�fdd�Z�ZS)�CapturedSubprocessa)Run a process and capture its output.

    :attr stdout: The output (a string).
    :attr stderr: The standard error (a string).
    :attr returncode: The return code of the process.

    Note that stdout and stderr are decoded from the bytestrings subprocess
    returns using error=replace.
    csHtt|���||_||_||_tj|jd<tj|jd<tj|jd<dS)z�Create a CapturedSubprocess.

        :param label: A label for the subprocess in the test log. E.g. 'foo'.
        :param *args: The *args to pass to Popen.
        :param **kwargs: The **kwargs to pass to Popen.
        r�stdinrN)rrCr
�labelr9r:�
subprocess�PIPE)rrEr9r:rrr	r
�szCapturedSubprocess.__init__cs�tt|���tj|j|j�}|��\}}|�dd�|_	|�dd�|_
|�|jdt
�|j	��|�|jdt
�|j
��|j|_|jr�td|j|j|jf��|�t|d�|�t|d�|�t|d�dS)	Nzutf-8r/z-stdoutz-stderrz0Failed process args=%r, kwargs=%r, returncode=%s�out�err�
returncode)rrCrrF�Popenr9r:�communicate�decoderHrIZ	addDetailrErZtext_contentrJ�AssertionErrorr
�delattr)r�procrHrIrrr	r�s&��zCapturedSubprocess.setUprrrrr	rC�s
rCcCsNtj|tjtjtj|d�}tdd�|��D��}|D]}t|�q4||jfS)z�Run the command args in cwd.

    :param args: The command to run e.g. ['git', 'status']
    :param cwd: The directory to run the comamnd in.
    :return: ((stdout, stderr), returncode)
    )rDrrr>css|]}|�d���VqdS)�latin1N)rM�strip)�.0�srrr	�	<genexpr>�sz_run_cmd.<locals>.<genexpr>)rFrKrG�tuplerLr#rJ)r9r>�pZstreamsZstream_contentrrr	r7�s�
r7cCs@tdddddgd�tdddddgd�tdddddgd�dS)	NZgitZconfigz--globalz
user.emailzexample@example.comz	user.namezOpenStack Developerzuser.signingkeyr6rrrr	�_config_git�s����rX)rrr(rFr2r$Z
testresourcesZ	testtoolsrrrZFixturerZTestCaseZResourcedTestCaserrCr7rXrrrr	�<module>(sT,