
    i                    	   % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJrJr  SSKJrJrJr  SSKJrJr  SSKJr  SSKJr  SSKJrJr  SS	K	Jr  SS
KJrJ r J!r!J"r"J#r#J$r$  SSK%r%SSK&J'r'J(r(J)r)J*r+  SSK,J-r-J.r.  SSK/J0r0  SSK1J2r2J3r3  SSK4J5r5  SSK6J7r7  SSK8J9r9  SSK:J;r;  SSK<J=r=  SSK>J?r?  SSK@JArAJBrB  SSKCJDrDJErEJFrFJGrG  SSKHJIrIJJrJ  SrKSrLSR                  5       rN\O\P   \Q\O\P   S4   -  rR\S\T\Q\T\T4   -     rU\)" SSS\'R                  S9rWS\Q\O\P   S4   S\Q\O\P   S4   4S  jrXS!\RS\Q\O\P   S4   4S" jrYS!\Q\O\P   S4   S\Q\U\T4   4S# jrZS$\TSS4S% jr[S&\TS\Q\O\P   S4   4S' jr\S(\TS\OS-  4S) jr]S* r^S+\R                  S,\TS\+R                  4S- jraS.rbS/rcS0rdS1reS2\TS\+R                  4S3 jrfS4\S\g\R                     4S5 jrhS4\S\g\R                     4S6 jriS4\S\j\T\R                  4   4S7 jrkS8\\R                     S\j\T\R                  4   4S9 jrl\R                  S: 5       rnS;S<.S=\S>\oS\j\T\+R                  4   4S? jjrpS$\TS@\TSA\TS\T4SB jrqSC rrSD rsSE rt0 ru\j\v\T4   \wSF'   SG rxSH ryS;SI.SJ\SK\oS\T4SL jjrz\PSMSN.S4\SO\TS!\RSP\TS\T4
SQ jjr{SR\TS\T4SS jr|SMSSST.S=\SU\TSV\TS!\Q\O\P   S4   SW\TS$\TSX\\T\T\+R                  -  4   S-  SY\US-  SZ\oS\Q\U\T4   4S[ jjr}S\\\T   S=\\   SY\US\\T   4S] jr~ " S^ S_\!5      rS`\\   S-  SY\US\TS-  4Sa jrSb\Q\T\S\T   4   S-  Sc\\S-     S\S-  4Sd jrSc\\S-     S\Q\g\T   \S\T   4   S-  4Se jrSf\S\S-  4Sg jrSh\S\o4Si jrSY\USj\TS\T4Sk jrSl rSmrSn\vS\j\T\4   4So jrSpSqSSr.Ss\\	GR                  -  S!\RS$\TSZ\oS-  S\T4
St jjrSpSqSSr.S4\S!\RS$\TSZ\oS-  S\T4
Su jjrSpSqSSr.S4\S!\RS$\TSZ\oS-  S\T4
Sv jjrSw rSpSqSSr.S=\S!\RS$\TSZ\oS-  S\T4
Sx jjrSy rSz rS{R                  5       rS|GR%                  5       rS} rS;SpSqSS~.S=\S\oS!\RS$\TSZ\oS-  S\T4S jjr\"" S5      r\"" S5      rSSSSSpSqSS.S4\\\/\4   S\oS\oS\\-  S-  S\\\/\4   S-  S!\RS$\TSZ\oS-  S\T4S jjrSSSSS.S4\\\/\4   S\oS\oS\\-  S-  S\\\/\4   S-  S!\Q\O\P   S4   S$\TSZ\oS\Q\U\T4   4S jjrSpSqSSr.S4\S!\RS$\TSZ\oS-  S\T4
S jjrS rg)a
  
Writing tests with Hypothesis frees you from the tedium of deciding on and
writing out specific inputs to test.  Now, the ``hypothesis.extra.ghostwriter``
module can write your test functions for you too!

The idea is to provide **an easy way to start** property-based testing,
**and a seamless transition** to more complex test code - because ghostwritten
tests are source code that you could have written for yourself.

So just pick a function you'd like tested, and feed it to one of the functions
below.  They follow imports, use but do not require type annotations, and
generally do their best to write you a useful test.  You can also use
:ref:`our command-line interface <hypothesis-cli>`::

    $ hypothesis write --help
    Usage: hypothesis write [OPTIONS] FUNC...

      `hypothesis write` writes property-based tests for you!

      Type annotations are helpful but not required for our advanced
      introspection and templating logic.  Try running the examples below to see
      how it works:

          hypothesis write gzip
          hypothesis write numpy.matmul
          hypothesis write pandas.from_dummies
          hypothesis write re.compile --except re.error
          hypothesis write --equivalent ast.literal_eval eval
          hypothesis write --roundtrip json.dumps json.loads
          hypothesis write --style=unittest --idempotent sorted
          hypothesis write --binary-op operator.add

    Options:
      --roundtrip                 start by testing write/read or encode/decode!
      --equivalent                very useful when optimising or refactoring code
      --errors-equivalent         --equivalent, but also allows consistent errors
      --idempotent                check that f(x) == f(f(x))
      --binary-op                 associativity, commutativity, identity element
      --style [pytest|unittest]   pytest-style function, or unittest-style method?
      -e, --except OBJ_NAME       dotted name of exception(s) to ignore
      --annotate / --no-annotate  force ghostwritten tests to be type-annotated
                                  (or not).  By default, match the code to test.
      -h, --help                  Show this message and exit.

.. tip::

    Using a light theme?  Hypothesis respects `NO_COLOR <https://no-color.org/>`__
    and ``DJANGO_COLORS=light``.

.. note::

    The ghostwriter requires :pypi:`black`, but the generated code only
    requires Hypothesis itself.

.. note::

    Legal questions?  While the ghostwriter fragments and logic is under the
    MPL-2.0 license like the rest of Hypothesis, the *output* from the ghostwriter
    is made available under the `Creative Commons Zero (CC0)
    <https://creativecommons.org/public-domain/cc0/>`__
    public domain dedication, so you can use it without any restrictions.
    N)OrderedDictdefaultdict)CallableIterableMapping)permutationszip_longest)	iskeyword)ascii_lowercase)dedentindent)EllipsisType)Any
ForwardRef
NamedTupleTypeVarget_args
get_origin)	Verbosityfindsettings
strategies)InvalidArgumentSmallSearchSpaceWarning)get_type_hints)get_signatureis_mock)
check_type)domains)ListStrategy)BuildsStrategy)DeferredStrategy)FlatMapStrategy)LazyStrategyunwrap_strategies)FilteredStrategyMappedStrategyOneOfStrategySampledFromStrategy)_global_type_lookupis_generic_typez
# This test code was written by the `hypothesis.extra.ghostwriter` module
# and is provided under the Creative Commons Zero public domain dedication.

{imports}
zd
@given({given_args})
def test_{test_kind}_{func_name}({arg_names}){return_annotation}:
{test_body}
z4
try:
{test_body}
except {exceptions}:
    reject()
.T)databasedeadlinederandomize	verbosityexcreturnc                     [        U 5      n[        U S5       H/  u  p#X!;   d  M  [        X#5      (       d  M  UR                  U5        M1     [	        [        US S95      $ )N   c                     U R                   $ N)__name__)es    [/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/hypothesis/extra/ghostwriter.py<lambda>$_dedupe_exceptions.<locals>.<lambda>   s    qzz    key)listr   
issubclassremovetuplesorted)r0   uniquesabs       r8   _dedupe_exceptionsrF      sP     3iGS!$<Jq,,NN1 % %9:;;r;   except_c                    [        U [        5      (       ah  [        U 5       HW  u  p[        U[        5      (       a  [	        U[
        5      (       a  M1  [        SU SU< S[        [        U5      5       S35      e   U $ [        U [        5      (       a  [	        U [
        5      (       d%  [        SU < S[        [        U 5      5       S35      eU 4$ )Nz&Expected an Exception but got except_[]=z (type=)z>Expected an Exception or tuple of exceptions, but got except_=)
isinstancerA   	enumeratetyper?   	Exceptionr   _get_qualname)rG   ir7   s      r8   _check_exceptrQ      s    '5!!g&DAa&&jI.F.F%<QCr!mDG45Q8  ' gt$$Jw	,J,JLktG}!= >aA
 	
 :r;   c                    U (       d  [        5       S4$ / n[        5       n[        U 5       Hq  nUR                  [        [        5      ;   a  UR                  UR                  5        M=  UR                  UR                  5        UR                  [        USS95        Ms     U[        U5      S:  a  SSR                  U5      -   S-   4$ US   4$ )	N Tinclude_module   (, rJ   r   )setrF   __qualname__dirbuiltinsappendadd
__module__rO   lenjoin)rG   
exceptionsimportsexs       r8   _exception_stringre      s    ubyJG )??c(m+boo.KK&mBtDE * -0_q-@dii
##c) FPQRm r;   stylec                 .    U S;  a  [        SU < 35      eg )N)pytestunittestz-Valid styles are 'pytest' or 'unittest', got )r   )rf   s    r8   _check_stylerj      s#    ** MeYWXX +r;   docc                    [        U [        5      (       d   U 5       e/ n[        R                  " S[        R                  5      R                  U 5       HS  n[        [        US5      n[        U[        5      (       d  M+  [        U[        5      (       d  MB  UR                  U5        MU     [        [        [        U5      5      5      $ )zReturn a tuple of exceptions that the docstring says may be raised.

Note that we ignore non-builtin exception types for simplicity, as this is
used directly in _write_call() and passing import sets around would be really
really annoying.
z\:raises\s+(\w+)\:N)rK   strrecompile	MULTILINEfindallgetattrr\   rM   r?   rN   r]   rA   rF   )rk   raisesexcnameexc_types       r8   _exceptions_from_docstringrv      s     c3$$F::3R\\BJJ3O8Wd3h%%*Xy*I*IMM(# P #E&M233r;   tokenc                    U S:X  a  [         $ S[        R                  ;   a\  [        R                  " SU 5      (       a  [        R                  S   R
                  $ U S:X  a  [        R                  S   R                  $ [        R                  " SU 5      nUba  UR                  5       u  p#[        U5      nUc$  UR                  S5      (       a  [        US S 5      nUb  US;   a	  [        U   $ [        U5      $ S	U ;  a  [        [        U S 5      $ U R                  S	S
S9u  pV[        [        R                  R                  US 5      US 5      $ )Nintegernumpyz[Aa]rray[-_ ]?likedtypez(\w+) of (\w+)s)r>   sequence
collection.rV   maxsplit)intsysmodulesrn   	fullmatchndarrayr{   groups_type_from_doc_fragmentendswithr>   rr   r\   rsplitget)rw   
coll_match
coll_token
elem_tokenelemsmodnames          r8   r   r      s$   	
#++<<-u55;;w'///g;;w'---/7J!+!2!2!4
'
3=Z0055+JsO<E/Q!Q; 'z22
%x--S1-IC3;;??3-tT::r;   c                     [         R                  " [        5         [        U 5       Vs1 s H  n[	        U5      iM     sn[
        1:X  a  [        U 5      sS S S 5        $  S S S 5        U $ s  snf ! , (       d  f       U $ = fr5   )
contextlibsuppressrN   r   rM   r   r   )type_rD   s     r8   _strip_typevarsr      se    			Y	'%e_-_DG_-':e$ 
(	': 
( L . 
(	' Ls   A.A)A.)A..
A=param	docstringc           	         SU R                    S3SU R                    S3SU R                    S34 GH+  n[        R                  " X![        R                  S9nUc  M,  UR	                  S5      nUR                  S5      R                  S	5      n/ n/ n[        R                  " S
U5       HL  nS H  nUR                  U5      nM     U(       d  M&   UR                  [        R                  " U5      5        MN     U R&                  [(        R*                  R,                  La  U R&                  U;  a  [        U R&                  [/        S U 5       5      5      (       ds  [0        R2                  " [        5         [5        [7        [8        R:                  " U R&                  5      5      SS5        UR=                  SU R&                  5        S S S 5        U(       d
  U(       d  GM  U(       a  [8        R>                  " U5      O[8        R@                  " 5       U(       a/  [8        RB                  " [E        [8        RF                  U5      6 -  s  $ [8        R@                  " 5       -  s  $    [        U R&                  [H        5      (       a  [8        RJ                  " 5       $ [        U R&                  [L        RN                  5      (       a)  [8        R>                  " [!        U R&                  5      5      $ U R&                  [(        R*                  R,                  La   [8        R:                  " U R&                  5      $ [Q        U R                   RS                  5       S9$ ! [        [        4 aY    [        U5      n	[        U	[         5      (       d  [#        U	5      (       a$  U	c   eUR                  " [%        U	5      5         GM
   GM  f = f! , (       d  f       GN= f)Nz^\s*\:type\s+z	\:\s+(.+)z^\s*z
 \((.+)\):z \: (.+))flagsrV   z
, optionalz}{z,? +or +| *, *)zdefault zpython c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr5   )rK   rM   ).0ts     r8   	<genexpr> _strategy_for.<locals>.<genexpr>!  s     $M1At9LQQs   (	(<string>evalr   )r   )*r   rn   searchrp   groupremovesuffixstripsplitremoveprefixr]   astliteral_eval
ValueErrorSyntaxErrorr   rK   rM   r+   r   defaultinspect	ParameteremptyrA   r   r   ro   reprstjustinsertsampled_fromnothingone_ofmap	from_typeboolbooleansenumEnum_guess_strategy_by_argnamelower)
r   r   patternmatchdoc_typeelementstypesrw   prefixr   s
             r8   _strategy_forr      s    I.

|:&

|8$
 		'BLLA=;;q>((6<<TBXX/:E1**62 2 5 0 0 78 ;  MM!2!2!8!88X-u$M$MM  $$[1RWWU]]34j&I5==1 2 uu19BOOH-rzz|8=		3r||U34 CE::< MX %--&&{{}%--++tEMM233}}G--333 wwu}}%%%5::+;+;+=>>? , 5+E2a&&/!*<*<=(=LL!344 +=5 21s    %M4AN:A N76N7:
O		)keepdimsverbosedebugforcetraintraining	trainablebiasshuffleshowload
pretrainedsave	overwrite	normalizereversesuccessenabledstrictcopyquietrequiredinplace	recursiveenableactivecreatevalidaterefreshuse_bias)widthsizelengthlimitidxstrideepochepochsdepthpidsteps	iteration
iterations
vocab_sizettlcount)realimagalphathetabetasigmagammaanglerewardtautemperature)texttxtpasswordlabelr   suffixdescdescriptionrm   r   subjectreasoncommentpromptsentencesepr   c                 6   U S;   a  [         R                  " 5       $ U S;   a(  [         R                  " [         R                  " 5       SS9$ U S;   aS  [         R                  " [         R                  " 5       5      [         R                  " [         R
                  " 5       5      -  $ U S;   a)  [         R                  " [         R                  " 5       5      $ U S;   a  [         R                  " [        5      $ SU ;   a(  [         R                  " 5       R                  [        5      $ U R                  S	5      (       d
  U [        ;   a  [         R                  " 5       $ U S
;   a+  [         R                  " 5       [         R                  " 5       -  $ U S;   a  [         R                  " SS5      $ U R!                  S5      (       dB  U R!                  S5      (       a  SU ;  d&  ["        R$                  " SU 5      (       d
  U [&        ;   a  [         R                  " SS9$ U S;   a  [         R                  " 5       $ U S;   a  [         R                  " SS5      $ U S;   a  [         R                  " SS5      $ U S;   a  [         R                  " SS5      $ U S;   a  [         R                  " SS9$ U [(        ;   a  [         R                  " 5       $ U S;   a
  [+        5       $ U S;   a  [         R,                  " 5       $ U S;   a  [         R.                  " S SS!9$ U S";   a  [         R0                  " 5       $ S#U ;   d"  S$U ;   d  U R!                  S%5      (       d  U S&;   a  [         R                  " 5       $ U R!                  S'5      (       d2  U R!                  S(5      (       a  SU ;  d  S)U ;   a  S*U ;  d
  U [2        ;   a  [         R
                  " 5       $ ["        R$                  " S+U 5      (       a5  [5        U S,S- 5      nUR6                  (       d  [         R                  " U5      $ [         R                  " 5       $ ).a^  
If all else fails, we try guessing a strategy based on common argument names.

We wouldn't do this in builds() where strict correctness is required, but for
the ghostwriter we accept "good guesses" since the user would otherwise have
to change the strategy anyway - from `nothing()` - if we refused to guess.

A "good guess" is _usually correct_, and _a reasonable mistake_ if not.
The logic below is therefore based on a manual reading of the builtins and
some standard-library docs, plus the analysis of about three hundred million
arguments in https://github.com/HypothesisWorks/hypothesis/issues/3311
)functionfuncf)pred	predicateT)returnspure)iterable)r>   lstls)objectuuidis_)amount	thresholdnumbernum)portr   i  _sizer   _zn(um)?_[a-z_]*s)	min_value)offsetseeddimtotalpriority)learning_ratedropoutdropout_rateepsilonepsprobrV   )latlatitudeiZ   )lon	longitudeiL   )radiustol	tolerancerate)hosthostname)email)wordslugapi_keyz\w+)r   )char	characterfilepath_dir)fnamer[   dirname	directoryfolder)_namer  r   stringasz\w*[^s]sNr}   )r   	functionsr   	iterablesintegersr   listsr   buildsr  uuidsr   rm   
startswith
BOOL_NAMESfloatsr   rn   r   POSITIVE_INTEGER_NAMESFLOAT_NAMESr   emails
from_regex
charactersSTRING_NAMESr   is_empty)r   r   s     r8   r   r   P  s    ((||~$$||BKKM==}||BKKM*R\\"'')-DDD$$xx

%%{yy  ~xxz~~c"" u!3{{} 77{{}ryy{**y{{1i((gMM&!!co<<*D11)){{Q''=={{}UUyyA""yyb!!##yys##55yy1%%{yy{ ##yzyy{**}}Vt44$$}} 	$T>==  EE zz| 	())MM&!!coT!1<wwy 
||K&&*495~~88E?" ::<r;   r  c                    [        U [        R                  [        R                  45      (       Ga  [	        U S5      (       Ga  [        U R
                  [        5      (       Ga  [        R                  " SU R                   S3U R
                  5      nUc  / $ UR                  S5      R                  SS5      R                  SS5      n/ n[        R                  R                  nUR                  S5       H  nUR!                  S	5      tpVUR#                  5       nUS
:X  a  [        R                  R$                  nMG  UR'                  S5      (       d  US:X  a  [        R                  R(                  nM  [+        UR-                  S5      5      (       d$  UR-                  S5      R/                  5       (       d    U$ UR1                  [        R                  " XTS95        M     U$ / $ )N__doc__^z	\((.+?)\)rV   [rS   ]rX   =/*z...r   kind)rK   r   BuiltinFunctionTypeBuiltinMethodTypehasattrr[  rm   rn   r   r6   r   replacer   r   POSITIONAL_ONLYr   	partitionr   POSITIONAL_OR_KEYWORDrP  KEYWORD_ONLY
_iskeywordlstripisidentifierr]   )r  r   argsparamsrc  argr!  s          r8   _get_params_builtin_fnrr    sr   4%33U5L5LMNND)$$t||S)) Admm_I6E=I{{1~%%c2.66sB? (/'8'8'H'H::d#CmmC(GC))+Ccz((>>~~c""cUl((55#**S/**#**S/2N2N2P2P MM'++@A $ Ir;   c                     [        U 5      (       aO  [        S U R                    Vs/ s H0  n[        R                  " U[        R                  R
                  S9PM2     sn$ / $ s  snf )Nrb  )_is_probably_ufuncr   ninr   r   rh  )r  r   s     r8   _get_params_ufuncrv    s_    $ (
$((3
3 4g.?.?.O.OP3
 	
 I	
s   7A"c                     [        [        U 5      R                  R                  5       5      n[        R
                  nSUR                  4SUR                  4/n[        U 5      =n(       a  UnO@U Vs/ s H  oUR                  UR                  4PM     snU:X  a  [        U 5      =(       d    Un[        U5      $ s  snf ! [         a*    [        U 5      =n(       a   N.[        U 5      =n(       a   NBe f = f)z7Get non-vararg parameters of `func` as an ordered dict.ro  kwargs)r>   r   
parametersvaluesr   r   VAR_POSITIONALVAR_KEYWORDrv  r   rc  rr  rN   _params_to_dict)r  rp  Pplaceholderufunc_paramsps         r8   _get_paramsr    s    <mD)44;;=>  0 01Hamm3LM,T22<2 "F(./1vvqvv/;>+D1;VF6"" 0#  &t,,6,-d33V3 s   ,B? 3!B:?C3C31C3rp  c                    ^ [         R                  R                  [         R                  R                  4m[	        U4S jU  5       5      $ )Nc              3   b   >#    U  H$  oR                   T;  d  M  UR                  U4v   M&     g 7fr5   )rc  r   )r   r  var_param_kindss     r8   r   "_params_to_dict.<locals>.<genexpr>  s$     TFqffO6S{{Fs   //)r   r   r{  r|  r   )rp  r  s    @r8   r}  r}    s8     ((779J9J9V9VWOTFTTTr;   c               #   4  #    [         [        ;   a  S v   g  [        R                  " [        5      [        [         '   S v   [        [         	 [        R
                  R                  5         g ! [        [         	 [        R
                  R                  5         f = f7fr5   )r   r*   r   rN  r  r   __clear_cache r;   r8   _with_any_registeredr    sb      !!	)')yy'8$#C(LL&&( $C(LL&&(s   B)A*  *B*+BBF)pass_result_to_next_funcfuncsr  c           
         U(       d   S5       e0 n[        U5       GHH  u  p4[        U5      nU (       a  US:  a  U[        [        U5      5      	 [	        U5      n[        USS5      =(       d    SnUR                  5        VV	s0 s H  u  pXU;   a  SO
[        X5      _M     n
nn	[        5          [        R                  " U40 U
D6R                  nSSS5        WR                  (       a  [        S5      eUR                  R                  5        HQ  u  p[        U	5      S   S:X  a#  X;   a  [!        [        R"                  Xh   40 5      n	X;   a  X(==   U	-  ss'   MM  XU'   MS     GMK     [%        U5      S:X  a  [        W5       Vs0 s H  oX,   _M	     sn$ ['        [)        UR                  5       5      5      $ s  sn	nf ! , (       d  f       N= fs  snf )	a8  Return a dict of strategies for the union of arguments to `funcs`.

If `pass_result_to_next_func` is True, assume that the result of each function
is passed to the next, and therefore skip the first argument of all but the
first function.

This dict is used to construct our call to the `@given(...)` decorator.
zMust pass at least one functionrV   r[  NrS   .z%Expected to pass everything as kwargs	nothing())rL   r  nextiterr   rr   itemsr   r  r   rN  wrapped_strategyro  NotImplementedErrorrx  _valid_syntax_reprr$   r   r`   dictrB   )r  r  given_strategiesrP   r  rp  hintsr   kvbuilder_argsstratr   s                r8   _get_strategiesr    s    333557% Q#QtDL)*q!Ay$/52	 
& 5jsmA&AA& 	 
 "#IIa0<0AAE $ ::%&MNNLL&&(DA!!$Q';61: {B?$ #q(#&'# )! !6 5zQ9DQH&,,HH'--/011/
 $#$ Is   F8/"F>G>
G	rD   rE   c           	          U S:X  a	  SU SU S3$ U S:X  d   eUR                  5       (       a$  UR                  5       (       a  SU SU SU SU S3	$ SU SU 3$ )	Nri   zself.assertEqual(rX   rJ   rh   zassert z == z, ()rn  )rf   rD   rE   s      r8   
_assert_eqr  B  sz    
"1#Rs!,,H~~ANN,,4s#aS1#Q//QCtA3r;   c                 4   [        U 5      [        [        S[        5       5      L aD  [	        5       R
                  " [        [        U R                  5      6  VVs1 s H  u  pUiM	     snn$ [        U [        R                  [        R                  45      (       a  S1$ [        U [        R                  5      (       a  [        U 5      $ [        U [        [         R"                  R%                  S5      SS5      5      (       a  S1$  ['        U 5      (       a  [        U [(        5      (       a  U R*                  U R,                  41$ [.        R0                  " [2        5         [	        5       R
                  " [        [        U R                  5      6 sSSS5        $ [5        U 5      (       a  U R,                  S:X  a
  [	        5       $ [7        U 5      R9                  S	5      S
   n[;        U 5      U41$ s  snnf ! , (       d  f       Ni= f! [2         a    [	        5       s $ f = f)zAReturn the imports for `obj`, which may be empty for e.g. lambdas	UnionTypern   rz   r{   r  )rz   r{   Nz<lambda>r   r   )rM   rr   r   r  rY   unionr   _imports_for_object__args__rK   rn   PatternMatchr   SearchStrategy_imports_for_strategyr   r   r   r+   r   r_   r6   r   r   rN   callablerO   r   _get_module)objr   r!  r   s       r8   r  r  K  s   CyGE;99"%%++s3F/U"VW"V"VWW#

BHH-..v#r(())$S))#ws{{w7"EFF"##3#w''677$$Y/u{{C(;S\\$JK 0/#,,*"<5LS!'',Q/S!4())! X 0/  usB   G)=H  H  /G/
	H  )H  >*H  /
G=9H   HHc           	         [        U [        5      (       a  [        U R                  5      [        U R                  R                  5       5      -   VVs1 s H!  n[        [        U5      5        H  nUiM     M#     nnn[        R                  " S[        U 5      5      (       a  U$ [        U R                  5      R                  S5      (       a@  [        U R                  5      R                  SS5      nX@R                  R                  41U-  $ [        5       n[         R"                  " 5          [         R$                  " S[&        5        [)        U 5      n S S S 5        [        U [*        5      (       a0  U[-        U R.                  5      -  nU[        U R0                  5      -  n[        U [2        5      (       a9  U[-        U R4                  5      -  nU R6                   H  nU[        U5      -  nM     [        U [8        5      (       a0  U[-        U R:                  5      -  nU[        U R<                  5      -  n[        U [>        5      (       a!  U R@                   H  nU[-        U5      -  nM     [        U [B        5      (       ah  U[        U RD                  5      -  nU RF                   H  nU[-        U5      -  nM     U RH                  R                  5        H  nU[-        U5      -  nM     [        U [J        5      (       a!  U RL                   H  nU[        U5      -  nM     [        U [N        5      (       a  U[-        U RP                  5      -  nU$ s  snnf ! , (       d  f       GN= f)Nzfrom_(type|regex)\(zhypothesis.extra.z._array_helpersz.numpyignore))rK   r$   rY   _LazyStrategy__args_LazyStrategy__kwargsrz  r  r   rn   r   r   r  r  rP  rg  r6   warningscatch_warningssimplefilterr   r%   r'   r  mapped_strategypackr&   filtered_strategyflat_conditionsr#   baseexpandr(   element_strategiesr!   targetro  rx  r)   r   r    element_strategy)strategyrq  imprc   moduler  r|   r  s           r8   r  r  c  s    (L)) 8778(00779:;
;*?3+?@  A ; 	 
 88*DN;;N**+667JKK !2!23;;<MxXF..7789GCCeG		 	 	"h(?@$X. 
#
 (N++()A)ABB&x}}55(,--()C)CDD))A*1--G *(O,,(77&x77 (M**,,A,Q//G - (N++&x77A,Q//G '')A,Q//G * (/00$$C*3//G % (L))()B)BCCNc
 
#	"s   (M,'M
M c                    [        U [        5      (       a  [        5       U 4$  [        U [        5      (       a  U R                  n [        U [
        5      (       Ga  [        5       n/ n[        R                  " 5          [        R                  " S[        5        U R                    S S S 5        U R                   Hu  n[        U[        5      (       a!  UR                  [        R                  4:X  a  M9  [        U5      U;  d  MJ  UR!                  U5        UR#                  [        U5      5        Mw     [$        R&                  " U=(       d    [$        R(                  " 5       5      n U [$        R*                  " 5       R                  :X  a  [        5       S4$ U [$        R,                  " [.        5      :X  a  [        5       S4$ [        U [0        5      (       a`  U R2                  R4                  [$        R,                  R4                  :X  a.  U R6                  c!  [9        S U R:                   5       5      U l        [        U 5      R=                  SS5      R=                  SS5      n[>        R@                  " SS	U5      n[C        US
S5        [E        U 5       Vs1 s H  oUS   U;   d  M  UiM     nnXd4$ ! , (       d  f       GN= fs  snf ! [F        [H        [J        4 a    [        5       S4s $ f = f)Nr  ztext()zfrom_type(type)c              3   8   #    U  H  n[        U5      v   M     g 7fr5   )r   )r   rD   s     r8   r   %_valid_syntax_repr.<locals>.<genexpr>  s      1,Hq"",H   z.filter(_can_hash)rS   hypothesis.strategies.z(lambda.*?: )(<unknown>)([,)])z\1...\3r   r   rV   r  )&rK   rm   rY   r"   r  r(   r  r  r  r   r  r)   r   osenvironr   r]   r^   r   r   r   r   r   rM   r$   r  r6   _LazyStrategy__representationrA   r  rg  rn   subro   r  r   RecursionErrorr   )r  seenr   r|   rrP   rc   s          r8   r  r    s4   (C  uh."h 01100Hh..5DE((*%%h0GH++ + 00a!455!**:U7$&LLOHHT!W% 1 yy!6"**,7Hrwwy1115(?"r||D))5+++ x..!!**bll.C.CC66>+0 1,4,H,H1 ,H( NW)2.W-r2 	
 FF4j!D:v& 4H=K=11=KzM +*J L9 "uk!!"sQ   AJ? ;(J(#AJ? BJ? )J? ;CJ? J:J:#J? (
J72J? ?!K#"K#KNOWN_FUNCTION_LOCATIONSc                 p   U R                   nUS:X  a  U$ [        U5       VVs/ s H  u  p#US:X  d  M  UPM     snnS /-   nU Hi  nUS U R                  S5      US U 4 HI  n[        [        R
                  R                  U5      U R                  S 5      U L d  M<  U[        U '   Us  s  $    Mk     U$ s  snnf )Nzcollections.abcr   r!  )	r_   rL   rm  rr   r   r   r   r6   r  )r  module_namerP   cdotsr   	candidates          r8   _get_module_helperr    s    
 ..K ''#K0=0$!AHA0=FD%ds+2237Tc9JKIs{{y13<<F#M09(-   L 
  >s
   B2B2c                 j   U [         ;   a	  [         U    $  [        U 5      $ ! [         a    [        U 5      (       d  e  Of = f[	        [
        R                  S S9 H;  nU [        [
        R                  U   U R                  S 5      L d  M0  U[         U '   Us  $    [        SU R                   SU < 35      e)Nc                 6    [        U R                  S5      5      $ )Nr   )rA   r   )ns    r8   r9   _get_module.<locals>.<lambda>  s    qwws|9Lr;   r<   z Could not find module for ufunc z ()
r  r  AttributeErrorrt  rB   r   r   rr   r6   RuntimeError)r  r  s     r8   r  r    s    
&&',,!#&& !#&& ' ckk/LM'#++k2CLL$GG,7$S) N 9#,,r#Q
RRs   
  >>rT   r  rU   c                    [        U SU R                  5      nUR                  SS5      R                  SS5      R                  SS5      nU(       a  [        U 5      S-   U-   $ U$ )NrZ   <r!  > rS   r   )rr   r6   rg  r  )r  rU   qnames      r8   rO   rO     s[    C6EMM#s#++C5==c2FE3#%--Lr;   rS   )rG   assignpass_variablesr  c          	         SR                  S [        U[        U 5      R                  5       5       5       5      n[	        U SS9 SU S3nU(       a  U SU 3n[        [        U SS	5      =(       d    S	5      nU Vs/ s H!  n[        Xq5      (       a  M  UR                  PM#     nnU(       d  U$ [        R                  [        US
S9[        U5      S:  a  SSR                  U5      -   S-   S9$ US   S9$ s  snf )a  Write a call to `func` with explicit and implicit arguments.

>>> _write_call(sorted, "my_seq", "func")
"builtins.sorted(my_seq, key=func, reverse=reverse)"

>>> write_call(f, assign="var1")
"var1 = f()"

The fancy part is that we'll check the docstring for any known exceptions
which `func` might raise, and catch-and-reject on them... *unless* they're
subtypes of `except_`, which will be handled in an outer try-except block.
rX   c              3      #    U  Hg  u  pUR                   [        R                  R                  L a  U=(       d    UR                  O#UR                   S U=(       d    UR                   3v   Mi     g7fr_  N)rc  r   r   rh  r   )r   r  r  s      r8   r   _write_call.<locals>.<genexpr>  sa       LDA vv**::: [!&&FF81Q[!&&M*+ Ls   A/A1TrT   rW   rJ    = r[  rS       r   rV   r   	test_bodyrb   )ra   r	   r  rz  rO   rv   rr   r?   r6   SUPPRESS_BLOCKformatr   r`   )	r  rG   r  r  ro  callrs   rd   exnamess	            r8   _write_callr    s    99   D0A0H0H0JK D D67qa@DTF#'i(D(JKF%+KVr:b3J{r{{VGK  f-58\A5E37++c1 !  KRST: !   Ls   ;C5C5r|   c                     SR                  [        [        R                  [        SS95      n[
        R                  " SU S3SU S9$ )zyReplace strategy name() with st.name().

Uses a tricky re.sub() to avoid problems with frozensets() matching
sets() too.
|T)r=   r   z\b(?:z)\b[^= ]zst.\g<0>)r   replrH  )ra   rB   r   __all__r`   rn   r  )r|   namess     r8   _st_strategy_namesr  '  s;     HHVBJJC>?E66U5'2QOOr;   )
assertionsr  rc   ghostr  r  r  rc   annotatec                 4   U=(       d
    [        5       U V	s1 s H  n	[        U	5      iM     sn	-  n[        5          U=(       d    [        USU S;   06nUR	                  5        V
Vs/ s H  u  pU
/[        U5      Q7PM     nn
nUR                  " S U 5       6 nSR                  S U 5       5      nS S S 5        [        W5      nU(       a:  [        U5      u  pUR                  U5        [        R                  [        USS9US9nU(       a  U S	U 3nUS
:X  a  S/O/ nU(       a  UR                  [        XXU5      5        OUR                  U5        [         R                  UU SR                  S U 5       5      SR                  U5      U(       a  SOS[        USS9S9nUS
:X  aR  UR#                  S
5        SR                  U R%                  5       SR                  S U 5       5      [        US5      5      nUU4$ s  sn	f s  snn
f ! , (       d  f       GN]= f)Nr  )
idempotent	roundtripc              3   *   #    U  H	  u  pov   M     g 7fr5   r  )r   r!  r  s      r8   r   "_make_test_body.<locals>.<genexpr>G  s     !=u)!!#u   rX   c              3   4   #    U  H  u  po1 S U 3v   M     g7fr  r  )r   r  r!  r  s       r8   r   r  H  s     ?gaAAaSzs   r  r  r  
ri   selfr!  c              3   X   #    U  H   n[        U5      R                  S S5      v   M"     g7f)r   r!  N)rO   rg  r   r  s     r8   r   r  c  s%     Mu!=+33C==us   (*z -> NonerS   )
given_args	test_kind	func_name	arg_namesreturn_annotationr  z%class Test{}{}(unittest.TestCase):
{}c              3   t   #    U  H.  n[        U5      R                  S S5      R                  5       v   M0     g7f)r   rS   N)rO   rg  titler  s     r8   r   r  n  s.     Mu!M!$,,S"5;;==us   68)rY   r  r  r  r  r  r  ra   r  re   updater  r  r   extend_annotate_argsTEMPLATEr^   r  )r  r  rG   r  rf   r  rc   r  r  r  r  r  reprsr   r  
exc_stringargnamesbodys                     r8   _make_test_bodyr  1  s    #%E#BEqKNE#BBG 
	+ 
0
-26Q-Q0
 <L;Q;Q;ST;S411-)!,-;ST--!=u!=>YY???
 
  $J/J+G4s #))Yv6! * 
	
  kJ<0	 !J.xBH'7HI()??((MuMM))H%(0*b62  D 
J7>>KKMGGMuMM4 
 D=g $C U	 
 	s"   G=+H&H1HH
Hr  c              #     #    [        [        5      nU H  n [        [        USS9R                  R                  5       5      n[        U5      R                  5        HL  u  pgUR                  [        R                  R                  :w  d  M/  X6   R                  UR                  5        MN     M     U  H1  nUR                  U5      n	[        X5      n
U
c  Uv   M(  U SU
 3v   M3     g ! [         a     M  f = f7f)NT)eval_strz: )r   rY   rA   r   ry  rz  r}  r  
annotationr   r   r   r^   rN   r   _parameters_to_annotation_name)r  r  rc   arg_parametersr  rp  r=   r   argnamery  r  s              r8   r	  r	  u  s      2=S1AN	>==HHOOQRF
 .f5;;=
##w'8'8'>'>>"'++E,<,<= >  #''0
3JH
MIR
|,,   		s0   C9+C(AC9AC9(
C62C95C66C9c                   0    \ rS rSr% \\S'   \\   \S'   Srg)_AnnotationDatai  	type_namerc   r  N)r6   r_   rZ   __firstlineno__rm   __annotations__rY   __static_attributes__r  r;   r8   r  r    s    NXr;   r  ry  c                     U c  g [        S [        [        U 5       5       5      nU(       d  g [        U5      S:X  a  US   u  p4UR	                  U5        U$ [        SS14U5      nUc  g UR	                  UR                  5        UR                  $ )Nc              3   0   #    U  H  nUc  M  Uv   M     g 7fr5   r  r   r  s     r8   r   1_parameters_to_annotation_name.<locals>.<genexpr>  s      CJ 	
Cs   	rV   r   typing.Uniontyping)rA   r   _parameter_to_annotationr`   r  _join_genericsrc   r  )ry  rc   annotationsr  new_importsjoineds         r8   r  r    s      6
C K
 
;1!,Q	{#^hZ8+FF~NN6>>"r;   origin_type_datar$  c                     U c  g U b  U S   S:X  a	  S U 5       nU u  p#[        U5      nUb
  US   (       d  g Uu  pVUR                  U5        [        SR                  USR	                  U5      5      U5      $ )Nr   ztyping.Optionalc              3   P   #    U  H  nUb  UR                   S:w  d  M  Uv   M     g 7f)NNone)r  r  s     r8   r   !_join_generics.<locals>.<genexpr>  s,      
)
!Z%9%9V%C J)s   &	&z{}[{}]rX   )_join_argument_annotationsr  r  r  ra   )r'  r$  origin_typerc   r&  	arg_typesr%  s          r8   r#  r#    s      #(8(;?P(P
)
 ,K'4F~VAY#INN;8??;		)8LMwWWr;   c                     [        5       n/ nU  H>  nUc    g UR                  UR                  5        UR                  UR                  5        M@     X!4$ r5   )rY   r]   r  r  rc   )r$  rc   r.  r  s       r8   r,  r,    sT     GI!
--.z))*	 " r;   	parameterc           
      @   [        U [        5      (       a  g [        U [        5      (       aD  [        R                  S S S:  a  U R
                  nUc  g O U R                  5       n[        U5      $ [        U [        5      (       aD  [        S U  5       5      nUc  g Uu  p4[        SR                  SR                  U5      5      U5      $ [        U [        5      (       a^  U R                  S:X  a0  [        U R                   S:X  a  SOU R                   [#        5       5      $ [%        U S	S
9nUS:X  a  [        SS15      $ O8['        U S5      (       a  ['        U S5      (       a  [%        U S	S
9nO[        U 5      nUR)                  S5      (       a$  [        UR+                  SS5      [#        5       5      $ [-        U 5      nUb  X`:X  a&  [        U[#        UR/                  SSS9S S 5      5      $ [1        U 5      nU Vs1 s H  n[        U5      iM     sn[2        1:X  a  SnUR)                  S5      (       a#   US UR5                  S5       n	[        U	S15      n
O[        U5      n
U(       a  [9        U
S U 5       5      $ U
$ ! [         a     g f = fs  snf ! [6         a    Un	 NXf = f)Nr3   )      c              3   8   #    U  H  n[        U5      v   M     g 7fr5   r"  r   r   s     r8   r   +_parameter_to_annotation.<locals>.<genexpr>  s      ,
9B$U++r  z[{}]rX   r\   NoneTyper*  TrT   ztypes.UnionTyper   r!  r_   r6   r  hypothesis.strategiesr   r   rV   r   r}   r  ztyping.r]  c              3   8   #    U  H  n[        U5      v   M     g 7fr5   r5  )r   arg_types     r8   r   r7  !  s     J	H%h//	r  )rK   rm   r   r   version_info__forward_value__evaluaterN   r"  r>   r,  r  r  ra   rM   r_   r6   rY   rO   rf  rP  rg  r   r   r   r   indexr   r#  )r0  forwarded_valuer&  arg_type_namesr%  r  r-  r.  rD   new_type_nameorigin_annotations              r8   r"  r"    s   )S!!)Z((BQ')'99O& '"+"4"4"6 (88 )T""+ ,
9B,
 
 >&,#v}}TYY~-FGUU)T"":-"#,,
:	@R@R 
 ")DA	 ))">H:>> * 9l++	:0N0N%iEIII455y001H$OQTQVWWY'K k6y#i.>.>sQ.>.OPSQS.T*UVV#I"#AQ#y0	 I&&	&%&<	(<=M ,MH:F4[AJ	J
 	
 {  T $  	&%M	&s*   I9 6J	0J 9
JJJJrJ  c                      U  H@  n [        U5      R                  R                  5       n[        S U 5       5      (       a    gMB     g! [         a     MR  f = f)Nc              3   n   #    U  H+  oR                   [        R                  R                  :g  v   M-     g 7fr5   )r  r   r   r   r6  s     r8   r   (_are_annotations_used.<locals>.<genexpr>-  s%     SF5##w'8'8'>'>>Fs   35TF)r   ry  rz  anyrN   )rJ  r  rp  s      r8   _are_annotations_usedrH  &  s_    	"8,77>>@F SFSSS T    		s   #A
AAr  c                    UR                  SS5      R                  SS5      nU SS1-  n SU;   a  U R                  S5        1 SknX-
   Vs1 s H  n[        U[        5      (       d  M  S	U 3iM!     nn[	        [
        5      nU  Vs1 s H  n[        U[        5      (       d  M  UiM     sn HD  u  pgUR                  S
5      (       a  U[        R                  ;   a  M1  XV   R                  U5        MF     UR                  5        VVs1 s HM  u  ph[        U[        5      (       d  M  Xb;  d  M#  SR                  USR                  [        U5      5      5      iMO     n	nn[        R                  SR                  [        U5      [        U	5      -   5      S9n
UR                  S5      nUS:X  a  U
S-  n
OUS:  a  U
S-  n
[         R"                  " X-   [         R$                  " 5       S9$ s  snf s  snf s  snnf )Nz	builtins.rS   z	__main__.)
hypothesisgiven)rJ  zstrategies as stz        reject()
)rJ  reject>   __main__r\   r9  zimport r9  zfrom {} import {}rX   r  )rc   zst.nothing()rV   z;# TODO: replace st.nothing() with an appropriate strategy

z:# TODO: replace st.nothing() with appropriate strategies

)mode)rg  r^   rK   rm   r   rY   rA   rP  r   r  r  r  ra   rB   IMPORT_SECTIONr   black
format_strMode)rc   r  do_not_importrP   directfrom_importsr  r   r  from_headernothingss               r8   
_make_testrY  2  s    <<R(00bAD')KLLGt#,-EM%,%<S%<
1c@Rmsm%<FSs#L$+DGqz!U/CGD!!"9::trzz?Q $$T* E
 *//11MFfc" 	E'-'B 	E""6499VE]+CD1 
 
 ""499VF^fUm5S+T"UFzz.)H1}QQ	QPPFM

==! TDs*   G'(	G'G,#G,G1&G1-.G1c                 Z   ^  / SQn[        T 5      =(       a    [        U 4S jU 5       5      $ )N)ru  noutnargsntypesr   identity	signaturec              3   <   >#    U  H  n[        TU5      v   M     g 7fr5   )rf  )r   r   r  s     r8   r   %_is_probably_ufunc.<locals>.<genexpr>Z  s      Od!3!3s   )r  all)r  has_attributess   ` r8   rt  rt  N  s&    N C=OS O OOOr;   ))z	write(.+)zread{})zsave(.+)load{})zdump(.+)rd  )zto(.+)zfrom{})z
(.*)en(.+)z{}de{})z(.+)zde{})z(?!safe)(.+)zun{})z(.+)2(.+?)(_.+)?z
{1}2{0}{2})z(.+)_to_(.+)z
{1}_to_{0})z(inet|if)_(.+)to(.+)z{0}_{2}to{1})z(\w)to(\w)(.+)z{1}to{0}{2})send(.+)zrecv{})re  z	receive{}thingc           
        ^ 0 n[        U 5      (       a  U /nGO_[        U [        R                  5      (       Ga0  [	        U S5      (       a(  U R
                   Vs/ s H  n[        XS 5      PM     nnGO[	        U S5      (       a  U R                  m[        U 5      R                  5        VVs/ s Hm  u  pE[        U5      (       d  M  [        U5      (       a  M)  T(       a#  [        UST5      R                  T5      (       d  MS  UR                  S5      (       a  Mk  UPMo     nnnT(       a?  [        U4S jU 5       5      (       a%  U Vs/ s H  n[        UST5      T:X  d  M  UPM     nnO[        SU < 35      e[        W5       H  n[        R                   " U5      (       d  M   U[        U5      R                  5        VVs/ s HS  u  pE[	        US5      (       d  M  [        U5      (       a  M*  UR                  S5      (       a  MB  UR#                  U5      PMU     snn-  nM     U H  n [        U5      (       d  [        U5      (       a  [%        U5      (       a  [        U[&        R(                  5      (       d  [        U SS 5      (       a`  [        R                   " U 5      (       a  [+        U 5      [,        U'   O2[        U [        R                  5      (       a  U R.                  [,        U'    [%        U5        Xa[1        US	S
9'   M  M  M  M  M     U$ s  snf s  snnf s  snf s  snnf ! [2         a     GM  f = f! [4        [6        4 a     GM'  f = f)Nr  __package__r_   r!  c              3   D   >#    U  H  n[        US T5      T:H  v   M     g7f)r_   N)rr   )r   r  pkgs     r8   r   *_get_testable_functions.<locals>.<genexpr>  s     OA71lC8C?    z#Can't test non-module non-callable __func__r6   TrT   )r  rK   r   
ModuleTyperf  r  rr   rh  varsr  r   rP  rG  r   r>   r   isclass__get__r  r   EnumMetar  r  r6   rO   rN   	TypeErrorr   )rf  by_namer  r   r  r  r  rj  s          @r8   _get_testable_functionsru  x  s   G#('	E5++	,	,5)$$<AMMJMDWU$/MEJEUM**##C !K--//DAA;   
  '!\3"?"J"J3"O	 
 S) /   sOOOO$)REqWQc-Jc-QER CE9MNN%[??1 GMMO+DA1j) 29!* EF\\RUEV 		!+ E  	QZZQKKNN"1dmm445*d33u--6H6O03#E5+;+;<<6;nn03NEFM!DAB 5 #     , N[ K S* !   :& 		sy   L+LL&LLLL L L!
L!
-L!
L!
*CL9,L''
L61L95L66L99MMr  rh   rG   rf   r  modules_or_functionsc                 p  ^ ^^ ^!^" [        T 5      m [        T5        U(       d  [        S5      e/ m"0 n[        5       m U GHg  nUR	                  [        U5      =n5        U(       a  M)  [        U[        R                  5      (       d  MJ  SUR                   SUR                  < S3n/ n[        [        R                  [        S9 H  n	U	R                  UR                   S35      (       d  M(  SU	R!                  UR                  5      ;  d  MI  U	R                  [#        S U 5       5      5      (       a  Mq  [        [        R                  U	   5      (       d  M  UR%                  U	5        M     U(       a   US	S
R'                  [        U5      5       3-  nT"R%                  U5        GMj     U(       d  SR'                  T"5      $ Uc  [)        UR+                  5       6 nU U U"U4S jn
[,         GH   u  p[        U5       H  n[.        R0                  " XR3                  S5      S   5      nU(       d  M4  UR4                  " UR7                  5       6 m![        U!4S jU 5       5       H0  nU
" [8        UR;                  U5      UR;                  U5      4US9    M      [=        [        R                  [?        XM   5         T!5      n[A        U5        U
" [8        UR;                  U5      U4US9  M     GM     [E        [F        5      n[        URI                  5       5       H#  u  nnU[K        U5         R%                  U5        M%     UR+                  5        H  n[        U5      S:  d  M  [        U Vs1 s H  n[M        [A        U5      5      iM     sn5      S:X  d  MH  [O        5       nU Vs1 s H  n[Q        U5      RS                  SU5      iM      nn[        UU1-
  5      S::  d  M  U
" [T        UUS9  U H  nUR;                  [K        USS95        M     M     [        URI                  5       5       GHA  u  nn[Q        U5      nUR;                  SS5        [A        U5      n[        U5      [        U5      s=:X  a  S:X  d6  O  [?        U5      S:X  d  Ma  SUR                  ;  d  Ms  [#        U5      S;   d  M  UR+                  5       =(       d    [V        [V        /u  nnUu  nnUU:X  d  M  [        U5      [        U5      s=:X  a  S::  d  M  O  M  SSSSS.RS                  UR                  S5      n[=        [        R                  [?        U5         US5      nU
" [X        UUR                  S:g  UUS 9  XM	 GMD     S![        R                  ;   aC  [        URI                  5       5       H&  u  nn[[        U5      (       d  M  U
" [\        UUS9  XM	 M(     [        URI                  5       5       H  u  nnU
" [^        U[a        UT S"9S#US$9  M     [c        T S%R'                  T"5      5      $ ! [B         a     GM/  f = fs  snf s  snf )&a  Guess which ghostwriters to use, for a module or collection of functions.

As for all ghostwriters, the ``except_`` argument should be an
:class:`python:Exception` or tuple of exceptions, and ``style`` may be either
``"pytest"`` to write test functions or ``"unittest"`` to write test methods
and :class:`~python:unittest.TestCase`.

After finding the public functions attached to any modules, the ``magic``
ghostwriter looks for pairs of functions to pass to :func:`~roundtrip`,
then checks for :func:`~binary_operation` and :func:`~ufunc` functions,
and any others are passed to :func:`~fuzz`.

For example, try :command:`hypothesis write gzip` on the command line!
z2Must pass at least one function or module to test.z!# Found no testable functions in z (from rJ   r<   r   z._c              3   *   #    U  H	  o S 3v   M     g7f)r   Nr  )r   ms     r8   r   magic.<locals>.<genexpr>  s     .E1Awr  zK
# Try writing tests for submodules, e.g. by using:
#     hypothesis write r  z

Nc                 h   > U " U0 UDTTS.D6u  p4TR                  U5        TR                  U5        g )N)rG   rf   )r  r]   )	howro  rx  r  r  rG   rc   partsrf   s	        r8   make_magic.<locals>.make_  s3    FFF	sTr;   r}   c              3   Z   >#    U  H   oR                  S 5      S   T:X  d  M  Uv   M"     g7f)r   r}   N)r   )r   r  inverse_names     r8   r   r{    s(      $&!''#,r*:l*JAAws   +	+)r  r3   rV   r1   TrT   operatoritem))rD   rE   )xyr2  r^   and_or_)mulmatmulr  r  rS   r  )commutativedistributes_overr  rz   rG   fuzz)r  r  r  r  )2rQ   rj   r   rY   r  ru  rK   r   rn  r6   __file__rB   r   r   r`   rP  r   rA   r]   ra   rH  rz  ROUNDTRIP_PAIRSrn   r   r   r  r   _make_roundtrip_bodypoprr   r  r  rN   r   r>   r  rO   	frozensetr  r   r   _make_equiv_bodyr   _make_binop_bodyrt  _make_ufunc_bodyr  r  rY  )#rG   rf   r  rw  rt  rf  foundmsgmodsr  r  	writenamereadnamer   r   other
other_funcr  r!  r  r   sentinelr  r  r  rp  rD   rE   arg1arg2knownr  rc   r  r~  s#   ``                              @@@r8   magicr    s1   ( G$GRSSEGeG% 7 >>u?:eU-=-=>>5enn5EWU^^L^^_`CDCKKS1LLENN#31!566ANN5>>$BBLL.E.E)EFF/A??KKN 2 ..1hhvd|.D-EG LL% &( {{5!!('..*:;   /	7ODLLJJsOB,?@Eu'?# $&$ E , T*GKK,>?!)
 %,KKGM(BC(&
 $J/ 0$[[.
;%-/ $  /@ Ew}}'1mA&&q) (u:?su#Mu!Ik!n$=u#MNRSSxHJOP%Q~a(,,Xx@%GP7hZ'(A-&AAKKa EF    W]]_-
dt$		(D!T"J#f+**+dmm+f!99<<>/c3ZDAqJD$Av#d)s4y5A55 !#!!	
 #dmmR(  $+3;;{47H+I5RV#W $ $ 9%5% M7 .< #++ 1JD$!$''&x@M 2 w}}'1!!W5	
 ( gtyy/00Q %  $NPs   3X+X.
$%X3
X+*X+c          	          [        U 5      (       d  [        SU < 35      e[        U5      n[        U5        Uc  [	        U 5      n[        U [        XS9USUUS9u  pE[        XE5      $ )ac  Write source code for a property-based test of ``func``.

The resulting test checks that valid input only leads to expected exceptions.
For example:

.. code-block:: python

    from re import compile, error

    from hypothesis.extra import ghostwriter

    ghostwriter.fuzz(compile, except_=error)

Gives:

.. code-block:: python

    # This test code was written by the `hypothesis.extra.ghostwriter` module
    # and is provided under the Creative Commons Zero public domain dedication.
    import re

    from hypothesis import given, reject, strategies as st

    # TODO: replace st.nothing() with an appropriate strategy


    @given(pattern=st.nothing(), flags=st.just(0))
    def test_fuzz_compile(pattern, flags):
        try:
            re.compile(pattern=pattern, flags=flags)
        except re.error:
            reject()

Note that it includes all the required imports.
Because the ``pattern`` parameter doesn't have annotations or a default argument,
you'll need to specify a strategy - for example :func:`~hypothesis.strategies.text`
or :func:`~hypothesis.strategies.binary`.  After that, you have a test!
Got non-callable func=r  r  r  rG   r  rf   r  )r  r   rQ   rj   rH  r  r  rY  r  rG   rf   r  rc   r  s         r8   r  r  K  ss    Z D>> 7$9::G$G(.#d4MG g$$r;   c                   [        U 5      (       d  [        SU < 35      e[        U5      n[        U5        Uc  [	        U 5      n[        U SR                  [        XS9[        U SUS95      U[        USS5      SUUS9u  pE[        XE5      $ )a|  Write source code for a property-based test of ``func``.

The resulting test checks that if you call ``func`` on it's own output,
the result does not change.  For example:

.. code-block:: python

    from typing import Sequence

    from hypothesis.extra import ghostwriter


    def timsort(seq: Sequence[int]) -> Sequence[int]:
        return sorted(seq)


    ghostwriter.idempotent(timsort)

Gives:

.. code-block:: python

    # This test code was written by the `hypothesis.extra.ghostwriter` module
    # and is provided under the Creative Commons Zero public domain dedication.

    from hypothesis import given, strategies as st


    @given(seq=st.one_of(st.binary(), st.binary().map(bytearray), st.lists(st.integers())))
    def test_idempotent_timsort(seq):
        result = timsort(seq=seq)
        repeat = timsort(seq=result)
        assert result == repeat, (result, repeat)
r  zresult = {}
repeat = {}r  resultrepeatr  r  rG   r  r  rf   r  )
r  r   rQ   rj   rH  r  r  r  r  rY  r  s         r8   r  r    s    R D>> 7$9::G$G(.#,33.h8
 eXx8MG g$$r;   c                   ^ [        [        [        U S   5      5      5      n[        U S   STS9/U4S j[	        U SS  5       5       Qn[        U SR                  U5      T[        X$S[        U 5      S-
   35      SUUS	.6$ )
Nr   value0r  rG   c              3   R   >#    U  H  u  p[        US U 3S US-    3TS9v   M     g7f)valuerV   r  N)r  )r   rP   r  rG   s      r8   r   '_make_roundtrip_body.<locals>.<genexpr>  s5      

, U1#;q1ugP,s   $'rV   r  r  r  r  )	r  r  r  r  rL   r  ra   r  r`   )r  rG   rf   r  first_param
test_liness    `    r8   r  r    s    tKa123KE!HXw?

!%),

J 	))J'eE#e*q.9I2JK r;   c                     U(       d  [        S5      e[        U5       H'  u  pE[        U5      (       a  M  [        SU SU< 35      e   [        U 5      n [	        U5        Uc  [        U6 n[        [        X0X5      6 $ )a  Write source code for a property-based test of ``funcs``.

The resulting test checks that if you call the first function, pass the result
to the second (and so on), the final result is equal to the first input argument.

This is a *very* powerful property to test, especially when the config options
are varied along with the object to round-trip.  For example, try ghostwriting
a test for :func:`python:json.dumps` - would you have thought of all that?

.. code-block:: shell

    hypothesis write --roundtrip json.dumps json.loads
z,Round-trip of zero functions is meaningless.Got non-callable funcs[rI   )r   rL   r  rQ   rj   rH  rY  r  )rG   rf   r  r  rP   r  s         r8   r  r    s}    & LMM% {{!$;A3b"FGG ! G$G(%0+EELMMr;   c           	         U  Vs/ s H  nSUR                    3PM     nn[        [        U5      5      [        U5      :  a+  U  Vs/ s H  nSUR                    S[        U5       3PM      nn[        [        U5      5      [        U5      :  a/  [	        U 5       VVs/ s H  u  p1SU SUR                    3PM     nnnU$ s  snf s  snf s  snnf )Nresult_r!  )r6   r`   rY   r  rL   )r  r  	var_namesrP   s       r8   _get_varnamesr     s    167A71::,'I7
3y>S^+FKLewqzzl!KN+;<e	L
3y>S^+<Ee<LM<LDAwqc1::,/<L	M 8LMs   B>%CCc           
         ^^ [        U 5      m[        TU SS9 VVs/ s H  u  pE[        XTUS9PM     nnnSR                  UU4S jTSS   5       5      n[	        U SR                  U5      UUSTUS.6$ s  snnf )	NTr   r  r  c              3   D   >#    U  H  n[        TTS    U5      v   M     g7f)r   N)r  )r   vnamerf   r  s     r8   r   #_make_equiv_body.<locals>.<genexpr>  s$      <I5
5)A,..Mrl  rV   
equivalentr  )r  zipr  ra   r  )	r  rG   rf   r  r  r  r  r  r  s	     `     @r8   r  r  	  s    e$I IuT::HE 	AW5:    <EabM J 	))J' s   A3zx
try:
{}
    exc_type = None
    target(1, label="input was valid")
{}except Exception as exc:
    exc_type = type(exc)
zN
if exc_type:
    with {ctx}(exc_type):
{check_raises}
else:
{call}
{compare}
c                 Z   [        U 5      nU tpV[        XTS   US9n[        U5      u  pUR                  S5        U	(       a  SU	 S3OSn
[        R                  [        USS9U
5      /n[        US	S  US
S9 H  u  pUS:X  a  SnUR                  S5        O
US:X  d   eSn[        R                  U[        [        USS9S5      [        [        XSS9S5      [        [        X$S   U5      S5      S9nUR                  U5        M     [        U SR                  U5      SSUUS.6u  nnUU-  U4$ )Nr   r  )rJ  r  zexcept z:
    reject()
rS   r  r  rV   Tr  rh   zpytest.raisesri   zself.assertRaisesr  r  z        )ctxcheck_raisesr  comparer  r  r  )r  r  re   r^   EQUIV_FIRST_BLOCKr  r   r  EQUIV_CHECK_BLOCKr  r]   r  ra   )r  rG   rf   r  r  firstrest
first_callextra_importsr   catchr  r  r  r  blockrc   source_codes                     r8   _make_equiv_errors_bodyr  1  sT   e$ILEUQ<IJ/8M./5=ghZ012E#**6*V+LeTUJ	!"tD9H!Ch'J&&&%C!((Ar :JGAR@&I:eq\5A6J	 ) 
 	%  : +	))J'G[ ]"K//r;   )allow_same_errorsrG   rf   r  r  c                    [        U5      S:  a  [        S5      e[        U5       H'  u  pV[        U5      (       a  M  [        SU SU< 35      e   [	        [
        U S5        [        U5      n[        U5        Uc  [        U6 nU (       a&  [        S U 5       5      (       d  [        XAX#5      u  pxO[        XAX#5      u  px[        Xx5      $ )a  Write source code for a property-based test of ``funcs``.

The resulting test checks that calling each of the functions returns
an equal value.  This can be used as a classic 'oracle', such as testing
a fast sorting algorithm against the :func:`python:sorted` builtin, or
for differential testing where none of the compared functions are fully
trusted but any difference indicates a bug (e.g. running a function on
different numbers of threads, or simply multiple times).

The functions should have reasonably similar signatures, as only the
common parameters will be passed the same arguments - any other parameters
will be allowed to vary.

If allow_same_errors is True, then the test will pass if calling each of
the functions returns an equal value, *or* if the first function raises an
exception and each of the others raises an exception of the same type.
This relaxed mode can be useful for code synthesis projects.
r3   z'Need at least two functions to compare.r  rI   r  c              3   B   #    U  H  n[        [        U5      v   M     g 7fr5   )r?   rN   )r   rd   s     r8   r   equivalent.<locals>.<genexpr>y  s     $Q2Z	2%>%>s   )r`   r   rL   r  r   r   rQ   rj   rH  rG  r  r  rY  )	r  rG   rf   r  r  rP   r  rc   r  s	            r8   r  r  T  s    2 5zA~GHH% {{!$;A3b"FGG ! t&(;<G$G(%0$Q$Q!Q!Q6uuW/Pg++r;   XYassociativer  r^  r  rG   rf   r  r  r  r^  r  c                   [        U 5      (       d  [        SU < 35      e[        U5      n[        U5        [	        [
        US5        [	        [
        US5        Ub,  [        U5      (       d  [        SU< SU R                   35      e[        XX4/5      (       d  [        S5      eUc  [        U 5      n[        U UUUUUUUS9u  p[        X5      $ )a:  Write property tests for the binary operation ``func``.

While :wikipedia:`binary operations <Binary_operation>` are not particularly
common, they have such nice properties to test that it seems a shame not to
demonstrate them with a ghostwriter.  For an operator ``f``, test that:

- if :wikipedia:`associative <Associative_property>`,
  ``f(a, f(b, c)) == f(f(a, b), c)``
- if :wikipedia:`commutative <Commutative_property>`, ``f(a, b) == f(b, a)``
- if :wikipedia:`identity <Identity_element>` is not None, ``f(a, identity) == a``
- if :wikipedia:`distributes_over <Distributive_property>` is ``+``,
  ``f(a, b) + f(a, c) == f(a, b+c)``

For example:

.. code-block:: python

    ghostwriter.binary_operation(
        operator.mul,
        identity=1,
        distributes_over=operator.add,
        style="unittest",
    )
r  r  r  zdistributes_over=z- must be an operation which distributes over zFYou must select at least one property of the binary operation to test.r  )r  r   rQ   rj   r   r   r6   rG  rH  r  rY  )
r  r  r  r^  r  rG   rf   r  rc   r  s
             r8   binary_operationr    s    F D>> 7$9::G$Gt[-0t[-0#H5E,F,F ! "  $0
 	
 (EFFT
 	
 (.$)	MG g$$r;   )r  r  r^  r  c                  ^ ^^^^^^^ [        T 5      mU4S j[        [        T 5      5      S S  5       u  p[        U5      [        U	5      :w  a  X-  nT R                  S-   m[        5       m/ m S$S[        S[        S[        S[        S -  SS 4
UUUU UUUU4S	 jjjn
U(       a5  U
" S
S[        T S[        T SS5      SS9[        T [        T SS5      SSS95        U(       a  U
" SS[        T SSSS9[        T SSSS95        Ub{  USL a   [        US [        S9n [        [        U5      SS5        SU< 3[        TS[        T SS5      5      [        TS[        T SS5      5      /nU
" SSSR                  U5      5        U(       a  Un[        T S[        USS5      SS9[        U[        T SS5      [        T SS5      SS9[        TSS5      S[        T [        USS5      SSS9[        U[        T SS5      [        T SS5      SS9[        TSS5      /nU
" UR                  S-   SSR                  U5      5        [        U5      u  pTR!                  U5        [#        U5      nSnTS :X  a  S!T R                   S"3nTUT S#U S3-   SR                  T5      -   4$ ! [         a    Sn GNf = f! [         a    [        U5      n GNf = f)%Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7fr5   )r  )r   r  r   s     r8   r   #_make_binop_body.<locals>.<genexpr>  s     J.I:>>!$$.Is   !r3   	_operandssub_propertyro  r  rightr1   c                 0  > Uc  SnOU SU 3n[        TSS5      n[        TUU S-   T
UT0 TEU Vs0 s H  oUT_M     snET	S9u  pbTR                  U5        TS:X  a$  SnX"R                  U5      [	        U5      -   S	-   S  nTR                  U5        g s  snf )
NrS   r  leftr  _binary_operation)r  r  rG   r  rf   r  r  ri   z(unittest.TestCase):
rV   )r  r  r  r?  r`   r]   )r  ro  r  r  r  r  rc   endlineall_importsr  rG   r  operands_namer~  r   rf   s           r8   maker_make_binop_body.<locals>.maker  s     =JV2eW%D#E67;J'!44!O
O.NA-/?.NO	
 	7#J.G

7+c'l:Q>@ADT /Os   Br  abcrD   rE   r  r  )r  r  ab.c                     g)NTr  )r  s    r8   r9   "_make_binop_body.<locals>.<lambda>  s    Dr;   )r   zidentity element herer   execzidentity = r^  r  ldistrdist_distributes_overrS   ri   zclass TestBinaryOperationz(unittest.TestCase):
    r  r5   )r  r>   r  r   r6   rY   rm   r  r   _quietly_settingsrN   ro   r   r  ra   r  r  r  )r  r  r  r^  r  rG   rf   r  operandsrE   r  identity_partsdo
dist_partsoperands_importsoperands_reprclassdefr  r  r~  r   s   `    ```         @@@@r8   r  r    s     !&JJd;t3D.Ebq.IJKHH~a MMK/M%KE !	  Tz	
 
 6 c;tS##>vND#s+		
	
 c3v6c3w7		
  s?3.CTU	&
 DNJ7 xmD#z2
 D*c2
 	j#tyy89c;r3#<VLD#s+D#s+	 ugv.k"c37WMD#s+D#s+	 ugw/#

& 	bkk//		*8MN&8&B#'(&}5MH
.t}}o=WXm_Cb99DIIe<LL q  323  	&H~H	&s$   J J( J%$J%(K Kc          	          [        U 5      (       d  [        SU < S35      e[        U5      n[        U5        Uc  [	        U 5      n[        [        XX#S96 $ )a  Write a property-based test for the :doc:`array ufunc <numpy:reference/ufuncs>` ``func``.

The resulting test checks that your ufunc or :doc:`gufunc
<numpy:reference/c-api/generalized-ufuncs>` has the expected broadcasting and dtype casting
behaviour.  You will probably want to add extra assertions, but as with the other
ghostwriters this gives you a great place to start.

.. code-block:: shell

    hypothesis write numpy.matmul
zfunc=z does not seem to be a ufuncrv  )rt  r   rQ   rj   rH  rY  r  )r  rG   rf   r  s       r8   ufuncr  N  s]    $ d##'CDEEG$G(.	$u	P r;   c                   SS K Js  Jn  U R                  c  UR	                  U R
                  S9nOUR	                  U R                  S9nUR                  UR                  l        SR                  SR                  [        S U R
                   5      [        U /[        S U R
                   Q7SU06S9nSR                  [        US	S
5      [        USS5      S9n[        U SS9nU R                   V	s/ s H  n	SU	;   PM
     n
n	[!        U
5      (       d  [#        U
5      (       d  SU S3nOSU S3n[%        U ['        U5      R)                  5       UUU R                  c  SOSU[*        R,                  " 5       X[S.S1US9	$ s  sn	f )Nr   )
num_shapes)r_  aI  
    input_shapes, expected_shape = shapes
    input_dtypes, expected_dtype = types.split("->")
    array_strats = [
        arrays(dtype=dtp, shape=shp, elements={{"allow_nan": True}})
        for dtp, shp in zip(input_dtypes, input_shapes)
    ]

    {array_names} = data.draw(st.tuples(*array_strats))
    result = {call}
    rX   rG   )array_namesr  z
{shape_assert}
{type_assert}zresult.shapeexpected_shapezresult.dtype.charexpected_dtype)shape_asserttype_assertTrT   Ozsampled_from(z.types)zsampled_from([sig for sig in z.types if 'O' not in sig])r  gufunc)datashapesr   )zhypothesis.extra.numpyarrays)r  rG   r  r  rf   r  rc   r  )hypothesis.extra.numpyextrarz   r_  mutually_broadcastable_shapesru  r6   r  r_   r  ra   r   r  r  rO   r   rb  rG  r  r   r   r   r  )r  rG   rf   r  npstr  r  r  r  sigobj_sigsr   s               r8   r  r  m  s|   ))~~33txx3H33dnn3M!%FOO
 	IIoj9:M
$(( ;MWM 	 	 	 399~7GHu&9;KL : J
 $t4E&*jj1jss
jH1
8}}CMMwg./w6PQ,$$&/gX"$'')vN56
 
 2s   1E=)r[  r   r\   r   r   r   r  rn   r   r   r  collectionsr   r   collections.abcr   r   r   	itertoolsr   r	   keywordr
   rl  rH  r   textwrapr   r   r   r!  r   r   r   r   r   r   rP  rJ  r   r   r   r   r   hypothesis.errorsr   r   hypothesis.internal.compatr   hypothesis.internal.reflectionr   r   hypothesis.internal.validationr   hypothesis.provisionalr   +hypothesis.strategies._internal.collectionsr    $hypothesis.strategies._internal.corer!   (hypothesis.strategies._internal.deferredr"   *hypothesis.strategies._internal.flatmappedr#   $hypothesis.strategies._internal.lazyr$   r%   *hypothesis.strategies._internal.strategiesr&   r'   r(   r)   %hypothesis.strategies._internal.typesr*   r+   rO  r
  r   r  rM   rN   rA   ExceptrY   rm   	ImportSetr   r  rF   rQ   re   rj   rv   r   r   r   r  r   rQ  rS  rT  rX  r   r>   rr  rv  r  r  r}  contextmanagerr  r   r  r  r  r  r  r  r  r  r  r  rO   r  r  r  r	  r  r  r#  r,  r"  rH  rY  rt  r  ru  rn  r  r  r  r  r  r  r  r  rstripr  r  r  r  r  r  r  r  r  r  r;   r8   <module>r     s>	  =~      	 	 
   0 7 7 / + " #    B B F 5 A 5 * D ? E F P  W
 
EG  
i5i#!56	6eCHo%&	oo	 <E$y/3"67 <E$y/SVBV<W <6 eDOS,@&A "uT)_c%9: uYPS^?T  Y Y Y
4C 4E$y/32F,G 4$;3 ;4$; ;8:?** :?s :?r?P?P :?|
 ^S ^R->-> ^B d73D3D.E @H g.?.?)@ #h #4W->->(>#? #6UW&&'U	#w  
 !U ) )& 8=*2*204*2	#r  
 !*2Z c  c  c  c  05p4"r /1 $vs{+ 0(S 7< s t   =FUW!
!%(!39!OR!!HP# P# P EI $AAA A 4	?C'(	A
 A A c3):):#::;dBA A A 9c>AH-sm-$,X$6-AJ-c]-0j 
$/84Z.XCSM*T1X/D01X tX4/D01
49c#h$&Q Q$0F Qh	h 	4 	>	 > > >8P$036 3d3=.A 3p  	Z1#e&6&66Z1Z1 Z1 Tk	Z1
 	Z1@  =%
=% =% 	=%
 Tk=% 	=%F  =%
=% =% 	=%
 Tk=% 	=%@,  	NNN N Tk	N
 	NB* 
EG  FH  0J $ ),),), ), 	),
 Tk), 	),X CLCL (+37 @%
Aq619
@% @% 	@%
 ,%@% 1vqy)D0@% @% @% Tk@% 	@%L (+37D
Aq619
D D 	D
 ,%D 1vqy)D0D 4	?C'(D D D 9c>DT  
  	
 Tk 	>-r;   