'L iddlmZddlZddlmZddlmZddlmZddlZddlm Z ddl m Z ddl m Z dd l m Z dd l mZddlZdd lmZdd lmZdd lmZddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!mZ"ddl#Z#ddl$Z$ddl%Z%ddl%m&Z&ddl'm(Z(ddl'm)Z)ddl*Z*ddl+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1e$jddkrddl3m4Z5nddlm5Z5dZ6e)de Z7e ee e fZ8d Z9dWd!Z:dXd"Z; dYd#Zd\d&Z?d]d'Z@d^d(ZAd_d)ZBd`d*ZCdad+ZDdbdcd,ZEddd-ZFejf ded.ZHd\d/ZIdfd0ZJdgd1ZKdhd2ZLdid3ZM djd4ZN dkd5ZOdld6ZPdmd7ZQdnd8ZR dod9ZSGd:d;e ZTGd<d=eUZVeTjd> dpd?ZX dqd@ZYdrdAZZe$jjdBrdsdCZ]ndsdDZ]dtdEZ^dudFZ_dvdGZ`dHdI dwdJZadxdKZbdydLZcGdMdNedZedOf dzdPZf d{dQZgd|dRZhd}dSZid~dTZjddUZkddVZly)) annotationsN)Callable)Iterable)Iterator)Enum)EBADF)ELOOP)ENOENT)ENOTDIR)partial) ModuleSpec) PathFinder) expanduser) expandvars)isabs)sep)Path)PurePath) ModuleType)Any)TypeVar) assert_never)skip) PytestWarning) )_NamespaceLoader)NamespaceLoaderi _AnyPurePath)bound)icRt|ddtvxst|ddtvS)Nerrnowinerror)getattr_IGNORED_ERRORS_IGNORED_WINERRORS) exceptions U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/_pytest/pathlib.py _ignore_errorr*>s0 7D)_< F 9j$ /3E Ec$|jdS)Nz.lock)joinpathpaths r) get_lock_pathr0Es == !!r+c t|tr|}n|d}t|tryt|ts1t j t d|dt|d|y|tjtjtjfvrG|tjfvr3t j t d|d|dt|d|yd d l d fd }t|}|jr)|j D]}|t#|||k(sn|t#|||y )zhHandle known read-only errors during rmtree. The returned value is used only by our own tests. Fz(rm_rf) error removing  z: z(rm_rf) unknown function z when removing z: rNctj|j}tj||jzj zyN)osstatst_modechmodS_IRUSRS_IWUSR)pmoder7s r)chmod_rwz on_rm_rf_error..chmod_rwqs6wwqz!! D4<<'$,,67r+T)r<strreturnNone) isinstance BaseExceptionFileNotFoundErrorPermissionErrorwarningswarnrtyper6rmdirremoveunlinkopenr7ris_fileparentsr?) funcr/excinfo start_pathexcr>r<parentr7s @r)on_rm_rf_errorrTIs.'=)aj#() c? + 3D6DI;bN O  BHHbii33 z ! MM/v_TF#dSVi[XZ[^Z_`  8 T Ayy{ii F S[ !#    SYJ r+ctjjdr-|j}t t t |}|S)a0Get the extended-length version of a path (Windows). On Windows, by default, the maximum length of a path (MAX_PATH) is 260 characters, and operations on paths longer than that fail. But it is possible to overcome this by converting the path to "extended-length" form before performing the operation: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation On Windows, this function returns the extended-length absolute version of path. On other platforms it returns path unchanged. win32)sysplatform startswithresolverget_extended_length_path_strr?r.s r)ensure_extended_length_pathr\s: ||w'||~0T;< Kr+cpd}d}|j||fr|S|jdr||ddzS||zS)z1Convert a path to a Windows extended length path.z\\?\z\\?\UNC\z\\N)rY)r/long_path_prefixunc_long_path_prefixs r)r[r[sN ) (*>?@  v#d12h.. d ""r+ct|}tt|}tjdk\r!t j t||yt j t||y)zNRemove the path contents recursively, even if some elements are read-only.)rQ)r )onexc)onerrorN)r\r rTrW version_infoshutilrmtreer?)r/rds r)rm_rfrhsL 't ,Dn6G 7" c$iw/ c$i1r+c#K|j}tj|D]0}|jjj |s-|2yw)zGFind all elements in root that begin with the prefix, case-insensitive.N)lowerr6scandirnamerY)rootprefixl_prefixxs r) find_prefixedrqsF||~H ZZ  66<<> $ $X .Gs AAAc#RKt|}|D]}|j|dyw)zReturn the parts of the paths following the prefix. :param iter: Iterator over path names. :param prefix: Expected prefix of the path names. N)lenrl)iterrnp_lenentrys r)extract_suffixesrws1 KE!jj  !s%'c.tt|||S)z+Combine find_prefixes and extract_suffixes.)rwrq)rmrns r) find_suffixesrys M$7 @@r+c8 t|S#t$rYywxYw)z0Parse number path suffixes, returns -1 on error.)int ValueError) maybe_nums r) parse_numrs#9~ s c|j|} |j |j|y#t$rYwxYw#t$rYywxYw)aHelper to create the current symlink. It's full of race conditions that are reasonably OK to ignore for the context of best effort linking to the latest test run. The presumption being that in case of much parallelism the inaccuracy is going to be acceptable. N)r-rKOSError symlink_to Exception)rmtargetlink_tocurrent_symlinks r)_force_symlinkrs]mmF+O   ""7+        s 6A AA AAc .tdD]g}tttt ||d}|dz}|j ||} |j |t||dz||cStd|d|d #t$rYwxYw) zKCreate a directory with an increased number as suffix for the given prefix. r{defaultr2r=currentz*could not create numbered dir with prefix z in z after 10 tries) rangemaxmaprryr-mkdirrrr)rmrnr=i max_existing new_numbernew_paths r)make_numbered_dirrs 2Y 3y-f*EFPRS !A% ==F8JO  8hd4& 1     sB BBct|} tjt|tjtj ztj zd}tj}t|j}tj||tj||js td|S#t$r}td||d}~wwxYw)z2Create a lock to prevent premature folder cleanup.iz/lock path got renamed after successful creationzcannot create lockfile in N)r0r6rLr?O_WRONLYO_CREATO_EXCLgetpidencodewritecloserMrFileExistsError)r< lock_pathfdpidspides r)create_cleanup_lockrsa I  WWS^R[[2::%= %I5 Qiik3x  T    "KL L ?21#67Q>?sAC C/C**C/cHtj}||fdd}||S)zFRegister a cleanup function for removing a lock, by default on atexit.cxtj}||k7ry |jy#t$rYywxYwr5)r6rrKr)r original_pid current_pids r)cleanup_on_exitz6register_cleanup_lock_removal..cleanup_on_exit s;iik , &         s - 99)rrrr|r@rA)r6r)rregisterrrs r)register_cleanup_lock_removalrs& ))+C*3 O $$r+ct|}d} t|}|j}|jdt j }|j |t| | |jyy#t$r&Y|! |jy#t$rYywxYwywxYw#t$rYywxYw#|! |jw#t$rYwwxYwwxYw)z^Remove a numbered directory if its lock can be obtained and it does not seem to be in use.Nzgarbage-) r\rrSr-uuiduuid4renamerhrrK)r/rrSgarbages r)maybe_delete_a_numbered_dirrs 't ,DI'- //HTZZ\N";< G g     " !       "   !       "   !slAA>,B0> B-B? B B('B(,B--B?0 B<;B<?C$CC$ C C$C  C$c^|jryt|} |jsy |j j }||kr4t jt5|j dddyy#t$rYywxYw#1swYyxYw#t$rYywxYw)zGCheck if `path` is deletable based on whether the lock file is expired.FTN) is_symlinkr0rMrr7st_mtime contextlibsuppressrKr)r/$consider_lock_dead_if_created_beforelock lock_times r)ensure_deletabler6s   D||~ IIK((  ; ; $$W-    #   s.BB )B BBB B,+B,c4t||r t|yy)z8Try to cleanup a folder if we can ensure it's deletable.N)rr)r/rs r) try_cleanuprRsBC#D)Dr+c #.Ktttt||d}||z }t ||}t j |\}}ttt||}t||dD]\}} | |ks t|yw)zIList candidates for numbered directories to be removed - follows py.path.r{rT)strictN) rrrryrq itertoolsteerwzipr) rmrnkeepr max_deleteentriesentries2numbersrvnumbers r)cleanup_candidatesrXss9mD&&ABBOL$JD&)G! g.GX)-h?@GWgd; v Z u+ s BBBc|jD]B}|js|jjr3|j Dyr5)iterdirrrZexistsrK)rmleft_dirs r)cleanup_dead_symlinksrdsBLLN"    ##%,,.!"r+c|jsyt|||D]}t|||jdD]}t||t |y)z-Cleanup for lock driven numbered directories.Nz garbage-*)rrrglobr)rmrnrrr/s r)cleanup_numbered_dirrksd ;;="46@D>?@ +&@D>?@$r+c.d}tdD]h} t|||}|dk7rt|}t||j j |z } t jt|||| |cS|J|#t$r } | }Yd} ~ d} ~ wwxYw)z>Create a numbered dir with a cleanup lock and remove old ones.Nrr) rrrrr7ratexitrrr) rmrnr lock_timeoutr=rrr<rrrRs r)make_numbered_dir_with_cleanuprys A 2Y !$5Aqy/2 -i8456683D3D|3S 0 OO$4  H'( == G A s(A?? BBBc|t|}t|}t|r t|S|j |Sr5)rrrrr-)inputrootpaths r)resolve_from_strrs8 u E u E U|E{  ''r+ct|}tjjd}|r*t|vr"t |vr|j t t}t|vr |j}nOt|}|jr4tjj|sdtj|}tj||S)aA port of FNMatcher from py.path.common which works with PurePath() instances. The difference between this algorithm and PurePath.match() is that the latter matches "**" glob expressions for each part of the path, while this algorithm uses the whole path instead. For example: "tests/foo/bar/doc/test_foo.py" matches pattern "tests/**/doc/test*.py" with this algorithm, but not with PurePath.match(). This algorithm was ported to keep backward-compatibility with existing settings which assume paths match according this logic. References: * https://bugs.python.org/issue29249 * https://bugs.python.org/issue34731 win*)rrWrXrYr posix_sepreplacerlr? is_absoluter6r/rfnmatch)patternr/iswin32rls r) fnmatch_exrs$ D>Dll%%e,G3g%)w*>//)S1 'yy4y    bggmmG&<"&&'+G ??4 ))r+c |jt}tt|Dchc]%}tj|d|dzxst'c}Scc}w)Nr2)splitrrrsjoin)spartsrs r)rrsG GGCLE5:3u:5F GCHHU7QU^ $ + + GG Gs*Ac | tj||fi|y#t$r}td|Yd}~yd}~wwxYw)zDMake a symlink, or skip the test in case symlinks are not supported.zsymlinks not supported: N)r6symlinkrr)srcdstkwargsrs r)symlink_or_skiprs= - 3&v& - 's +,,-s ;6;ceZdZdZdZdZdZy) ImportModez6Possible values for `mode` parameter of `import_path`.prependappend importlibN)__name__ __module__ __qualname____doc__rrrr+r)rrs@G FIr+rceZdZdZy)ImportPathMismatchErroraRaised on import_path() if there is a mismatch of __file__'s. This can happen when `import_path` is called multiple times with different filenames that has the same basename but reside in packages (for example "/tests1/test_foo.py" and "/tests2/test_foo.py"). Nrrrrrr+r)rrsr+rrcft|}t|}|js t||tjurG t ||\}}t jt5tj|cdddS t ||\}}|tj urDt#|tj$vrtj$j!t#|nf|tj&urIt#|tj$dk7r5tj$j)dt#|n t+|t j,|tj|}|j.d k(r|St0j2j5d d }|d k7r|j6}| t9||||j;d r|dd}|j;t0j<d zr |dt?t0j<d z } tAt#||} | s t9||||S#1swYnxYwt|||d}||S#t$rYnwxYwt||}t jt5tj|cdddS#1swYnxYwt|||jd}|td|d||S#t$r|j|j}}YwxYw#tB$rd} YwxYw)aq Import and return a module from the given path, which can be a file (a module) or a directory (a package). :param path: Path to the file to import. :param mode: Controls the underlying import mechanism that will be used: * ImportMode.prepend: the directory containing the module (or package, taking `__init__.py` files into account) will be put at the *start* of `sys.path` before being imported with `importlib.import_module`. * ImportMode.append: same as `prepend`, but the directory will be appended to the end of `sys.path`, if not already in `sys.path`. * ImportMode.importlib: uses more fine control mechanisms provided by `importlib` to import the module, which avoids having to muck with `sys.path` at all. It effectively allows having same-named test modules in different places. :param root: Used as an anchor when mode == ImportMode.importlib to obtain a unique name for the module being imported so it can safely be stored into ``sys.modules``. :param consider_namespace_packages: If True, consider namespace packages when resolving module names. :raises ImportPathMismatchError: If after importing the given `path` and the module `__file__` are different. Only raised in `prepend` and `append` modes. consider_namespace_packagesNFinsert_modulesTzCan't find module z at location r __init__.pyPY_IGNORE_IMPORTMISMATCH1)z.pycz.pyor{)"rrr ImportErrorr resolve_pkg_root_and_module_namerrKeyErrorrWmodules_import_module_using_specCouldNotResolvePathErrormodule_name_from_pathrSstemrr?r/rinsertr import_modulerlr6environget__file__rendswithrrs_is_samerD) r/r=rmrpkg_root module_namemodignore module_fileis_sames r) import_pathrsP :D d D ;;=$ z### $D2M% !Hk$$X. 0{{;/ 0 0,7 @ .I! + z   x= ( HHOOCM * ## # x=CHHQK ' HHOOAs8} -T K( ++k "C yyM! ZZ^^6 ;F }ll  )+{DI I    0 1%cr*K    6 7%&F#bff}.D*E(FGK s4y+6G)+{DI I JE 0 0,T8EC (   ,D$7   * ,;;{+ , , ,( t{{4  ; 2;-}TFST T $7 $ TYY+7D! G sNI/.I K:*L"I/ I;:I;#KK :!LL" L0/L0c|jd\}}}d}|rtjj|}t |d }||rc|j dk(r|j j } n |j } | dz jr| dz } t|| | j |}tjD]q} t| jdd} | dk(r'|jrt|t|g} n t|g} | j|| } t| |sqnSd}|jrt!||t#}t$j&j)|t|| } t| |r~| Jt$j&j+| }|tj|<| j,j/|| t1||||rt3tj||Sy) a Tries to import a module by its canonical name, path, and its parent location. :param module_name: The expected module name, will become the key of `sys.modules`. :param module_path: The file path of the module, for example `/foo/bar/test_demo.py`. If module is a package, pass the path to the `__init__.py` of the package. If module is a namespace package, pass directory path. :param module_location: The parent location of the module. If module is a package, pass the directory containing the `__init__.py` file. :param insert_modules: If True, will call `insert_missing_modules` to create empty intermediate modules with made-up module names (when importing test files not reachable from `sys.path`). Example 1 of parent_module_*: module_name: "a.b.c.demo" module_path: Path("a/b/c/demo.py") module_location: Path("a/b/c/") if "a.b.c" is package ("a/b/c/__init__.py" exists), then parent_module_name: "a.b.c" parent_module_path: Path("a/b/c/__init__.py") parent_module_location: Path("a/b/c/") else: parent_module_name: "a.b.c" parent_module_path: Path("a/b/c") parent_module_location: Path("a/b/") Example 2 of parent_module_*: module_name: "a.b.c" module_path: Path("a/b/c/__init__.py") module_location: Path("a/b/c/") if "a.b" is package ("a/b/__init__.py" exists), then parent_module_name: "a.b" parent_module_path: Path("a/b/__init__.py") parent_module_location: Path("a/b/") else: parent_module_name: "a.b" parent_module_path: Path("a/b/") parent_module_location: Path("a/") .N__path__rrrrz_pytest.assertion.rewrite)loader) rpartitionrWrrhasattrrlrSrMr  meta_pathr% __class__r? find_specspec_matches_module_pathis_dirrrrutilspec_from_file_locationmodule_from_specr exec_modulesetattrinsert_missing_modules)r module_pathmodule_locationrparent_module_name_rl parent_module need_reimportparent_module_path meta_importermodule_name_of_metafind_spec_pathspecrrs r)r r gsh#."8"8"=4'+M (:; $M:>>  M=0&1%7%7%>%>"%0%7%7""]2;;=%7-%G"5"""))- M %m&=&=|RP "= =+BUBUBW"/2C 4DEN!/23N&&{NC #D+ 6      %T; EF~~55 [)&6  k2nn--d3#& K  $  $ M4 -  "3;; < r+c|y|jrt|j|k(S|jr!|jD]}t||k(syy)zPReturn true if the given ModuleSpec can be used to import the given module path.FT)originrsubmodule_search_locations) module_specr,r/s r)r$r$s^K&&';66 --:: DDz[(  r+rctt|t|k(xs tjj||Sr5)rr6r/samefilef1f2s r)rrs+Bx48#?rww'7'7B'??r+cBtjj||Sr5)r6r/r<r=s r)rrswwB''r+c|jd} |j|}|j}t |dk\r |ddk(r|dd}t d|D}dj |S#t$r|jdd}YXwxYw) z Return a dotted module name based on the given path, anchored on root. For example: path="projects/src/tests/test_foo.py" and root="/projects", the resulting module name will be "src.tests.test_foo". rr2Nr^r{__init__c3@K|]}|jddyw)rr/N)r).0rps r) z(module_name_from_path..s?qqyyc*?sr) with_suffix relative_torr}rstupler)r/rm relative_path path_partss r)r r s   B D)((. #((  :! 2* <_ ?J??J 88J % $ZZ^ $sA..B B c|jd}|r|jd\}}}|r`|j|}|1 tjst t j|}|||<t||st|||||jddj|}|ryy#t $rt|d}Y`wxYw)aM Used by ``import_path`` to create intermediate modules when using mode=importlib. When we want to import a module as "src.tests.test_foo" for example, we need to create empty modules "src" and "src.tests" after inserting "src.tests.test_foo", otherwise "src.tests.test_foo" is not importable by ``__import__``. rNz6Empty module created by pytest's importmode=importlib.)docr{) rrrrWr!ModuleNotFoundErrorrrrr r*popr)rr module_partsr.r/ child_namer0s r)r+r+!s$$S)L ,7,B,B3,G)Az #KK(:;M$  ==11$-$;$;K}[$?$  )(D9 [( ( "%;D6#B CCr+c tjj|}t||S#tt t f$rYywxYw)a Return if the given module path could be imported normally by Python, akin to the user entering the REPL and importing the corresponding module name directly, and corresponds to the module_path specified. :param module_name: Full module name that we want to check if is importable. For example, "app.models". :param module_path: Full path to the python module/package we want to check if is importable. For example, "/projects/src/app/models.py". F)rr&r#r$rr} ImportWarning)rr,r6s r)rXrXsG ; ~~'' 4(k:: ] 3s-AAc |jd} |j|}t|j}|sy|ddk(r|j dj |S#t$rYywxYw#t$rYywxYw)z8Compute a module name based on a path and a root anchor.rNr{rBr)rFr}rGlistrrNr)rmr,path_without_suffixrelativenamess r)rWrWs)55b9 &2248  E  RyJ 88E?  s"A&A5& A21A25 BBceZdZdZy)r zres 5::r+cBg} tj|}|5}|D]$} |j|j |& ddd|j||S#t$rgcYSwxYw#t$r}t |rYd}~nd}~wwxYw#1swYPxYw)zScan a directory recursively, in breadth-first order. The returned entries are sorted according to the given key. The default is to sort by name. If the directory does not exist, return an empty list. N)key)r6rkrDrMrr*rsort)r/sort_keyr scandir_iterrrverrs r)rkrksGzz$'  " "E   NN5 ! " " LLXL N    %   " "sJA"BA3B" A0/A03 B< B B B  BBBc#Kt|}|Ed{|D]:}|js||st|j|Ed{<y7D7 w)zWalk a directory recursively, in breadth-first order. The `recurse` predicate determines whether a directory is recursed. Entries at each directory level are sorted. N)rkr%visitr/)r/recurserrvs r)rmrmsWdmG2 <<>genUZZ1 1 12 2s+AAAAAAAAcRttjj|S)zConvert a path to an absolute path using os.path.abspath. Prefer this over Path.resolve() (see #6523). Prefer this over Path.absolute() (not public, doesn't normalize). )rr6r/abspathr.s r) absolutepathrqs % &&r+c ttjjt |t |fS#t $rYywxYw)zReturn the common part shared with the other path, or None if there is no common part. If one path is relative and one is absolute, returns None. N)rr6r/ commonpathr?r})path1path2s r)rsrss@ BGG&&E CJ'?@AA s;> A  A ct|tsJt|tsJ||k(rtjSt ||}|s t |S|j |}|j |}tjjgtjgt|jz|jS)zReturn a string which is a relative path from directory to dest such that directory/bestrelpath == dest. The paths must be either both absolute or both relative. If no such path can be determined, returns dest. ) rBrr6curdirrsr?rGr/rpardirrsr) directorydestbase reldirectoryreldests r) bestrelpathr~s i && & dD !! ! yyy i &D 4y((.Lt$G 77<<  99+L../ /    r+cN |jS#ttf$rYywxYw)zTLike Path.exists(), but account for input arguments that might be too long (#11394).F)rr}r)r<s r) safe_existsrs,xxz  s $$cztjj|j|jS)zTest whether two paths reference the same actual file or directory. Unlike Path.samefile(), does not resolve symlinks. )r6r/samestatlstat)p1p2s r)samefile_nofollowr"s' 77  BHHJ 33r+)r(rr@bool)r/rr@r) rOzCallable[..., Any] | Noner/r?rPzUBaseException | tuple[type[BaseException], BaseException, types.TracebackType | None]rQrr@r)r/rr@r)r/r?r@r?)r/rr@rA)rmrrnr?r@Iterator[os.DirEntry[str]])rtzIterable[os.DirEntry[str]]rnr?r@ Iterator[str])rmrrnr?r@r)r~r?r@r|)rmrrzstr | PurePathrz str | Pathr@rA)i)rmrrnr?r=r|r@r)r<rr@r)rrrrr@r)r/rrfloatr@r)r/rrrr@rA)rmrrnr?rr|r@zIterator[Path])rmrr@rA) rmrrnr?rr|rrr@rA) rmrrnr?rr|rrr=r|r@r)rr?rrr@r)rr?r/str | os.PathLike[str]r@r)rr?r@zset[str])ros.PathLike[str] | strrrrrr@rA) r/rr=zstr | ImportModermrrrr@r) rr?r,rr-rrrr@zModuleType | None)r:zModuleSpec | Noner,rr@r)r>r?r?r?r@r)r/rrmrr@r?)rzdict[str, ModuleType]rr?r@rA)r/rr@ Path | None)r/rrrr@ztuple[Path, str])rr?r,rr@r)rmrr,rr@z str | None)r/rriz$Callable[[os.DirEntry[str]], object]r@zlist[os.DirEntry[str]])r/rrnz"Callable[[os.DirEntry[str]], bool]r@r)r/rr@r)rtrrurr@r)ryrrzrr@r?)r<rr@r)rrrrr@r)m __future__rrcollections.abcrrrrenumrr#rr r r r functoolsr importlib.machineryr rimportlib.utilrrr6os.pathrrrrpathlibrr posixpathrrfrWtypesrtypingrrrrF_pytest.compatr_pytest.outcomesr_pytest.warning_typesrreimportlib._bootstrap_externalrr LOCK_TIMEOUTrr&r'r*r0rTr\r[rhrqrwryrrrrrrrrrrrrrrrrrrrrrrr r$rXrYrr r+rUrrXrWrr rkrmrqrsr~rrrr+r)rsh" $$$** &  '!/gQ3 ~X6 7E51 "8 #8 8L8  8 8v$ #2!A  ( *$&,__%%"%%&88* "      #&  NS                B(!*HH -  -  - - -k(//{ { {  { "& {  {|xx#'x:>xSWxxv*<<5!@ ( >#-L$8=)D )D04)D)DX;4(GyG 6N 2@ 2  2+M 2 2 ' :4r+