Uo]ddlZddlZddlZddlmZddlmZmZddlZddl Z ddl m Z m Z mZmZejdZdZejdZdd Zd edefd Zd edefd ZGddZde jjdefdZdS)N)Path)ListUnion) shorten_pathget_valid_filename_pytest_expected_on_rightflatten_filesystem_dictz ^.*?\[(.*)]$c|d}|ddd|ddddS)Nsnapshotz--snapshot-update store_truez6Update snapshot files instead of testing against them.)actionhelpz--allow-snapshot-deletionz0Allow snapshot deletion when updating snapshots.)getgroup addoption)parsergroups h/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pytest_snapshot/plugin.pypytest_addoptionrsg OOJ ' 'E OO E  OO# ?c#Kt|j}t|jjj|jjj|5}|VddddS#1swxYwYdSN)_get_default_snapshot_dirnodeSnapshotconfigoptionsnapshot_updateallow_snapshot_deletion)requestdefault_snapshot_dirr s rr r s4W\BB '.'7.'?& ( (+3sAAAreturncFtr ||ksJdS||ksJdSr)r)valuer s r _assert_equalr$'s> ""!      5      rstringcd|vrtd|dtjS)z Returns the bytes that would be in a file created using ``path.write_text(string)``. See universal newlines documentation.  aNSnapshot testing strings containing "\r" is not supported. To snapshot test non-standard newlines you should convert the tested value to bytes. Warning: git may decide to modify the newlines in the snapshot file. To avoid this read https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings ) ValueErrorreplaceoslinesepencode)r%s r _file_encoder..sL  v~~jkk k >>$ + + 2 2 4 44rdatacz|ddddS)z Returns the string that would be read from a file using ``path.read_text(string)``. See universal newlines documentation. z r(r')decoder*)r/s r _file_decoder2>s2 ;;==  . . 6 6tT B BBrceZdZdZdZdZdZdZdZde de de fdZ dZ dZ edZejd Zd eee fd e fd Zd eeeffdZd eeefd eee ffdZdedeee ffdZdS)rNrr snapshot_dircZ||_||_||_g|_g|_g|_dSr)_snapshot_update_allow_snapshot_deletionr4_created_snapshots_updated_snapshots_snapshots_to_delete)selfrrr4s r__init__zSnapshot.__init__Ns8 /(?%("$"$$&!!!rc|Srr;s r __enter__zSnapshot.__enter__Vs rcjsjsjrUdt jdg}jr;|d|fdjDjr;|d|fdjDjrvjr4jD]}| |dn|d|fd jDtj d |d dSdS) Nz#Snapshot directory was modified: {}zR (verify that the changes are expected before committing them to version control)z Created snapshots:c3lK|].}dt|jzV/dSz Nstr relative_tor4.0sr;s r z$Snapshot.__exit__.._@$u$uXYVc!--@Q2R2R.S.S%S$u$u$u$u$u$urz Updated snapshots:c3lK|].}dt|jzV/dSrCrDrGs rrJz$Snapshot.__exit__..crKrz Deleted snapshots:z^ Snapshots that should be deleted: (run pytest with --allow-snapshot-deletion to delete them)c3lK|].}dt|jzV/dSrCrDrGs rrJz$Snapshot.__exit__..ns@$w$wXYVc!--@Q2R2R.S.S%S$w$w$w$w$w$wrr(F)pytrace) r8r9r:formatrr4appendextendr7unlinkpytestfailjoin)r;exc_typeexc_valexc_tb message_linespaths` r__exit__zSnapshot.__exit__Ys  " Ad&= AAZ ABII,W[WhJiJijjqsM& v$$%;<<<$$$u$u$u$u]a]t$u$u$uuuu& v$$%;<<<$$$u$u$u$u]a]t$u$u$uuuu( x0g $ 9&& !(()?@@@@!((*fggg$$$w$w$w$w]a]v$w$w$wwww K -00% @ @ @ @ @ @- A Arc|jSr) _snapshot_dirr?s rr4zSnapshot.snapshot_dirrs !!rcRt||_dSr)rabsoluter]r;r#s rr4zSnapshot.snapshot_dirvs"!%[[1133r snapshot_namer!c.t|tr|}n|j|}|j|jvrBt dt|t|j|S)zB Returns the absolute path to the given snapshot. zSnapshot path {} is not in {}) isinstancerr_r4joinpathparentsr)rOr)r;ra snapshot_paths r_snapshot_pathzSnapshot._snapshot_pathzs mT * * F)2244MM -66}EEM  M$9 9 9<CC]++\$:K-L-LNNOO Orr#ct|trtttfSt|t r tddfSt d)a Returns a 3-tuple of a compare function, an encoding function, and a decoding function. * The compare function should compare the object to the value of its snapshot, raising an AssertionError with a useful error message if they are different. * The encoding function should encode the value into bytes for saving to a snapshot file. * The decoding function should decode bytes from a snapshot file into a object. c|Srr>xs rz5Snapshot._get_compare_encode_decode..sArc|Srr>rjs rrlz5Snapshot._get_compare_encode_decode..srzvalue must be str or bytes)rcrEr$r.r2bytes TypeErrorr`s r_get_compare_encode_decodez#Snapshot._get_compare_encode_decodesU eS ! ! : , < < u % % : ++{{: :899 9rc tjdt}||\}}}||}|r|}nE|r/tdt|d}|j r||} || |kr|| } | |krtd|j dd|| ||j|dS|j|dSdS|w||} ||| d} n&#t$r} t%| } Yd} ~ nd} ~ wwxYw| 2dt|| } t| dStdt|) a( Asserts that ``value`` equals the current value of the snapshot with the given ``snapshot_name``. If pytest was run with the --snapshot-update flag, the snapshot will instead be updated to ``value``. The test will fail if there were any changes to the snapshot. errisinstancez%snapshot exists but is not a file: {}Nz7value is not supported by pytest-snapshot's serializer.T)reexist_okzsvalue does not match the expected value in snapshot {} (run pytest with --snapshot-update to update snapshots) {}zKsnapshot {} doesn't exist. (run pytest with --snapshot-update to create it))operator methodcallerAssertionErrorrprgis_file read_bytesexistsrOrr6r)parentmkdir write_bytesr8rPr9rE)r;r#ra__tracebackhide__comparer-r1rfencoded_expected_value encoded_valuedecoded_encoded_valueexpected_valuesnapshot_diff_msges r assert_matchzSnapshot.assert_matchsp%1/>RR"&"A"A%"H"H++M::  " " *%2%=%=%?%? " "  ! ! # # * !H!O!OP\]jPkPk!l!lmm m%) "   6"F5MMM%-BX1X1X(.}(=(=%(E11$%^___$**4$*GGG))-888)1+22=AAAAA+22=AAAAA2Y1X&1!'(>!?!?-GE>222)-%%&///(+A%%%%%%/ %0)hhnhn,8,G,GIZi\i\&)):;;; 10 %ahh$]3355666s, E;; FFFdir_dictsnapshot_dir_namect tjdt}t|tst d|| t|} r" fd dD}nQ r/td t t}t|}||z }||z }|jr4|j fdt#|Dn|s|rd t dg} |r4| d | d |D|r4| d | d |Dtd | |D].\} } || | /dS)a Asserts that the values in dir_dict equal the current values in the given snapshot directory. If pytest was run with the --snapshot-update flag, the snapshots will be updated. The test will fail if there were any changes to the snapshots. rrzdir_dict must be a dictionarych|]=}||>Sr>)rwrFas_posix)rHpsnapshot_dir_paths r z,Snapshot.assert_match_dir..sUTTT"#qyy{{Tamm,=>>GGIITTTr*z*snapshot exists but is not a directory: {}c3BK|]}|VdSr)rd)rHnamers rrJz,Snapshot.assert_match_dir..s3,p,pRV->-G-G-M-M,p,p,p,p,p,prz#Values do not match snapshots in {}zF (run pytest with --snapshot-update to update the snapshot directory)z Values without snapshots:c3 K|] }d|zV dSrCr>rHrIs rrJz,Snapshot.assert_match_dir..s&(I(I!(I(I(I(I(I(Irz Snapshots without values:c3 K|] }d|zV dSrCr>rs rrJz,Snapshot.assert_match_dir..s&(K(K!(K(K(K(K(K(Krr(N)rtrurvrcdictrorgr is_dirrglobryrOrsetr6r:rQsortedrPrUitemsrrd) r;rrr}values_by_filenameexisting_namesnames added_names removed_namesrYrr#rs @rassert_match_dirzSnapshot.assert_match_dirs%1/>RR(D)) =;<< < //0ABB4X>>  # # % % #TTTT'8'>'>s'C'CTTTNN  % % ' ' # !M!T!TUabsUtUt!u!uvv v UUN&''n, &.  ?  % , ,,p,p,p,pZ`anZoZo,p,p,p p p p p ?m ?!F!M!Ml[lNmNm!n!n!i!k J!(()FGGG!(((I(I[(I(I(IIII L!(()FGGG!(((K(K](K(K(KKKK$TYY}%=%=>>>.3355 G GKD%   e%6%?%?%E%E F F F F G Gr)__name__ __module__ __qualname__r6r7r8r9r:r]boolrr<r@r[propertyr4setterrrErgrnrprrrr>rrrrFss#M''t'[_''''AAA2""X"444E#t),< :c5j0A:::: 16%U "316E#t)DT16161616f(G(G%T BR(G(G(G(G(G(Grrrc|j}|jj}d|jvr |j}d}nV|j}t |j}| Jd|d}t|}| d||}|| |}tt|S)zE Returns the default snapshot directory for the pytest test. [Nz@Expected request.node.name to be of format TEST_FUNCTION[PARAMS] snapshots) fspathdirpath purebasenamer originalnamePARAMETRIZED_TEST_REGEXmatchrrrUrrE)rtest_module_dir test_module test_nameparametrize_nameparametrize_matchr s rrrsk))++O+*K $)I % 399$)DD ,,.p,,,,22155-.>??*// [)TT#3889IJJ ()) * **r)r!N)rtr+repathlibrtypingrrrS_pytest.python_pytestpytest_snapshot._utilsrrrr compilerrfixturer r$rErnr.r2rpythonFunctionrr>rrrs  wwwwwwwwwwww$"*_55   !!!! 5 5 5 5 5 5 CuCCCCCoGoGoGoGoGoGoGoGd+GN$;+++++++r