3 F\H"@sdZddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z Gdddej Z Gdddej ejZGd d d ej Zd d Zd dZdS)z Common utilities used in testingN)content)optionscs(eZdZdZddZfddZZS)DiveDirzaDive into given directory and return back on cleanup. :ivar path: The target directory. cCs ||_dS)N)path)selfrrc/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/pbr/pbr/tests/base.py__init__=szDiveDir.__init__cs0tt|j|jtjtjtj|jdS)N)superrsetUp addCleanuposchdirgetcwdr)r) __class__rrr @sz DiveDir.setUp)__name__ __module__ __qualname____doc__r r __classcell__rr)rrr7srcsDeZdZfddZddZddZddZgd d fd d ZZS) BaseTestCasecs tt|jtjjdd}y t|}Wn tk rHtdd}YnX|dkrf|j t j |ddtjjdt j kr|j t jdj}|j t jd |tjjd t j kr|j t jd j}|j t jd ||j t jd |_|j t j|j t j|j t j|j t jdd|j t jj|_tjj|jd|_tjtjjtjjtd|j|jtj tj!tj |j|j|j"t#|dds|j t jdtjj|jd}t$|d}|j%}WdQRX|j&dd}t$|d}|j'|WdQRXdS)NZOS_TEST_TIMEOUTz=OS_TEST_TIMEOUT set to invalid value defaulting to no timeoutrT)ZgentleZOS_STDOUT_CAPTUREstdoutz sys.stdoutZOS_STDERR_CAPTUREstderrz sys.stderrpbrZ PBR_VERSIONz0.0Z testpackageZ preversionedz setup.cfgrtzversion = 0.1.devwt)(r rr r environgetint ValueErrorprintZ useFixturefixturesTimeoutrZ TRUE_VALUESZ StringStreamstreamZ MonkeyPatchZ FakeLoggerZ log_fixtureZ TempHomeDirZNestedTempfileZEnvironmentVariableZTempDirrtemp_dirjoin package_dirshutilcopytreedirname__file__r rr_discard_testpackagegetattropenreadreplacewrite)rZ test_timeoutrrZsetup_cfg_pathcfgr)rrrr HsH       zBaseTestCase.setUpcCs2x,ttjD]}|dks"|jdr tj|=q WdS)NZpbr_testpackagezpbr_testpackage.)listsysmodules startswith)rkrrrr-{s z!BaseTestCase._discard_testpackagecOs|jd|f|S)Nr)_run_cmd)rargskwargsrrrrun_pbrszBaseTestCase.run_pbrcOs|jtjd|f|S)Nsetup.py)r=)r9r5 executable)rr:r;rrr run_setupszBaseTestCase.run_setupTNcCsB|p|j}t|gt||d}|dr>| r>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. )cwdzCommand failed retcode=%s)r(r9r4 Exception)rcmdr:Z allow_failr@resultrrrr9s zBaseTestCase._run_cmd) rrrr r-r<r?r9rrr)rrrFs  3rcs,eZdZdZfddZfddZZS)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|j||_||_||_tj|jd<tj|jd<tj|jd<dS)zCreate 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. rstdinrN)r rEr labelr:r; subprocessPIPE)rrGr:r;)rrrr s  zCapturedSubprocess.__init__cstt|jtj|j|j}|j\}}|jdd|_ |jdd|_ |j |j dt j|j |j |j dt j|j |j|_|jrtd|j|jt|d|jt|d|jt|ddS) Nzutf-8r1z-stdoutz-stderrzFailed process %souterr returncode)r rEr rHPopenr:r; communicatedecoderJrKZ addDetailrGrZ text_contentrLAssertionErrorr delattr)rprocrJrK)rrrr s zCapturedSubprocess.setUp)rrrrr r rrr)rrrEs  rEcCsRtj|tjtjtj|d}tdd|jD}x|D] }t|q6W||jfS)zRun 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) )rFrrr@css|]}|jdjVqdS)latin1N)rOstrip).0srrr sz_run_cmd..)rHrMrItuplerNr"rL)r:r@pZstreamsZstream_contentrrrr9s    r9cCs@tdddddgdtdddddgdtdddddgddS) Ngitconfigz--globalz user.emailzexample@example.comz user.namezOpenStack Developerzuser.signingkey)r9rrrr _config_gits  r\)rr r)rHr5r#Z testresourcesZ testtoolsrrrZFixturerZTestCaseZResourcedTestCaserrEr9r\rrrr(s  T*