j7i{,<dZddlmZddlmZddlZddlZddlmZddl Z ddl m Z ddl Z ddl mZddl mZdd l mZd d lmZd d lmZd d lmZd dlmZd dlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*e*e+e,e-fZ.edZ/eej`GddZ1d+dZ2d,d Z3d-d!Z4e!d"#d.d$Z5d/d%Z6e! d0d&Z7d1d'Z8ed(d() d2d*Z9y)3z>Support for providing temporary directories to test functions.) annotations) GeneratorN)Path)rmtree)Any)final)Literal)cleanup_dead_symlinks) LOCK_TIMEOUT)make_numbered_dir)make_numbered_dir_with_cleanup)rm_rf) get_user_id)Config)ExitCode)hookimpl)Parser)check_ispytest)fixture)FixtureRequest) MonkeyPatch)Item) TestReport)StashKeyallfailednoneceZdZUdZded<ded<ded<ded<d ed < dd d  ddZed d  ddZddZdddZ ddZ y )TempPathFactoryzFactory for temporary directories under the common base temp directory, as discussed at :ref:`temporary directory location and retention`. Path | None_given_basetempr_trace _basetempint_retention_count RetentionType_retention_policyNF _ispytestct||d|_n6ttjj t ||_||_||_||_ ||_ yN) rr#rospathabspathstrr$r'r)r%)selfgiven_basetempretention_countretention_policytracebasetempr+s W/mnt/ssd/data/python-lab/ChefSystem/venv/lib/python3.12/site-packages/_pytest/tmpdir.py__init__zTempPathFactory.__init__6sY y!  !#'D $(N8K(L#MD  /!1!c0t|t|jd}|dkrtd|d|jd}|dvrtd|d||jj |j jd||d S) zTCreate a factory according to pytest configuration. :meta private: tmp_path_retention_countrz6tmp_path_retention_count must be >= 0. Current input: .tmp_path_retention_policyrzKtmp_path_retention_policy must be either all, failed, none. Current input: tmpdirT)r3r6r4r5r+)rr&getini ValueErroroptionr7r6get)clsconfigr+countpolicys r8 from_configzTempPathFactory.from_configMs y!FMM"<=> 19HqQ :; 2 2]^d]eefg !==11,,""8,!#   r:ctjj|}|j|z j j |jk7rt |d|S)Nz& is not a normalized and relative path)r.r/normpath getbasetempresolveparentrA)r2basenames r8_ensure_relative_to_basetempz,TempPathFactory._ensure_relative_to_basetempms\77##H-     ) 2 2 4 ; ;t?O?O?Q Qz)OPQ Qr:c|j|}|s3|jj|}|jd|St |j|d}|j d||S)aCreate a new temporary directory managed by the factory. :param basename: Directory base name, must be a relative path. :param numbered: If ``True``, ensure the directory is unique by adding a numbered suffix greater than any existing one: ``basename="foo-"`` and ``numbered=True`` means that this function will create directories named ``"foo-0"``, ``"foo-1"``, ``"foo-2"`` and so on. :returns: The path to the new directory. mode)rootprefixrSmktemp)rOrKjoinpathmkdirr r$)r2rNnumberedps r8rVzTempPathFactory.mktempssr44X>  "++H5A GGG "t'7'7'9(QVWA KK! $r:c|j |jS|jK|j}|jr t||j d|j }n$t jjd}t|xstjj }txsd}|jd|} |j ddt}|c|j!}|j"|k7rtd |d |j$d zd k7r#t j&||j$d z|j(}|j*dk(rd }t-d||t.d}|J|||_|j1d||S#t$r'|jd}|j ddYwxYw)zReturn the base temporary directory, creating it if needed. :returns: The base temporary directory. rQrRPYTEST_DEBUG_TEMPROOTunknownz pytest-of-T)rSexist_okzpytest-of-unknownzThe temporary directory z: is not owned by the current user. Fix this and try again.?rirzpytest-)rUrTkeep lock_timeoutrSz new basetemp)r%r#existsrrXrLr.environrCrtempfile gettempdirget_userrWOSErrorrstatst_uidst_modechmodr'r)rr r$) r2r7from_envtemprootuserrootdiruid rootdir_statr`s r8rKzTempPathFactory.getbasetemps >> %>> !    +++H h NNN &'')Hzz~~&=>HH=(;(;(=>FFHH:*D''*TF(; 09r:r!c` ddl}|jS#tttf$rYywxYw)zlReturn the current user name, or None if getuser() does not work in the current environment (see #1010).rN)getpassgetuser ImportErrorrgKeyError)r}s r8rfrfs0  ( +s --ct}|j|jtj |d}|j |d|dy)aCreate a TempPathFactory and attach it to the config object. This is to comply with existing plugins which expect the handler to be available at pytest_configure time, but ideally should be moved entirely to the tmp_path_factory session fixture. Tr*_tmp_path_factoryF)raisingN)r add_cleanupundor!rHsetattr)rEmprs r8pytest_configurersI B rww'33Fd3KJJv*,=uJMr:cX|jdddd|jdddd y) Nr<zfHow many sessions should we keep the `tmp_path` directories, according to `tmp_path_retention_policy`.3string)helpdefaulttyper>zvControls which directories created by the `tmp_path` fixture are kept around, based on test outcome. (all/failed/none)r)rrr)addini)parsers r8pytest_addoptionrs@ MM" u   MM#  r:session)scopec.|jjS)zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)rEr)requests r8tmp_path_factoryrs >> + ++r:c|jj}tjdd|}d}|d|}|j |dS)Nz[\W]_T)rY)nodenameresubrV)rfactoryrMAXVALs r8_mk_tmprsF <<  D 66'3 %D F =D >>$> ..r:c#Kt||}||j}|jjt}|dk(r|j ddr t |d|jjt=yw)a;Return a temporary directory (as :class:`pathlib.Path` object) which is unique to each test function invocation. The temporary directory is created as a subdirectory of the base temporary directory, with configurable retention, as discussed in :ref:`temporary directory location and retention`. rcallT ignore_errorsN)rr)rstashtmppath_result_keyrCr)rrr/rG result_dicts r8tmp_pathrsp 7, -D J / /F,,$$%78K koofd; t4( -.sA:A<c|jj}|j}|y|j}|dk(r.|dk(r)|j|j r t |d|j r t|yy)zAfter each session, remove base directory if all the tests passed, the policy is "failed", and the basetemp is not specified by a user. NrrTr)rErr%r)r#is_dirrr )r exitstatusrr7rGs r8pytest_sessionfinishrs})0(H(H))H  / /Fa h   , , 4 ??  84 0h'r:T)wrappertryfirstc#Kd}|jJi}|j|jjt||j<|Swr-)whenpassedr setdefaultr)itemrrepemptys r8pytest_runtest_makereportr3sK C 88  EADDJJ,e4SXX> JsAA)rsz str | None)rErrsrt)rrrsrt)rrrsr!)rrrr!rsr)rrrr!rszGenerator[Path])rzint | ExitCode)rrrsz'Generator[None, TestReport, TestReport]):rx __future__rcollections.abcr dataclassesr.pathlibrrshutilrrdtypingrrr r r r rr_pytest.compatr_pytest.configrrr_pytest.config.argparsingr_pytest.deprecatedr_pytest.fixturesrr_pytest.monkeypatchr _pytest.nodesr_pytest.reportsr _pytest.stashrdictr1rrrr( dataclassr!rfrrrrrrrr{r:r8rs6D"%  *!&3&!##,-$++&"/Xd39o.0/0  ZZZz  N$ y,, / / //>// /0(2 $& ,'r: