
    g=                         d dl mZ d dlmZ d dlmZmZ d dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlmZmZmZmZ  G d de      Zy)    )contextmanager)BytesIO)TestCasemockN)FormatChecker
exceptions	protocols
validatorsc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestDeprecationsc                    d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                  j                  d             | j	                  j                  t               y# 1 sw Y   YxY w)zY
        As of v4.0.0, __version__ is deprecated in favor of importlib.metadata.
        z.Accessing jsonschema.__version__ is deprecatedr   )__version__N
jsonschema)
assertWarnsRegexDeprecationWarningr   r   assertEqual	importlibmetadataversionfilename__file__)selfmessagewr   s       W/var/www/openai/venv/lib/python3.12/site-packages/jsonschema/tests/test_deprecations.pytest_versionzTestDeprecations.test_version   sg    
 C""#5w?1. @ 	i&8&8&@&@&NOX.	 @?s   A88Bc                     d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                         | j	                  j                  t               y# 1 sw Y   JxY w)z
        As of v4.0.0, importing ErrorTree from jsonschema.validators is
        deprecated in favor of doing so from jsonschema.exceptions.
        z2Importing ErrorTree from jsonschema.validators is r   	ErrorTreeN)r   r   jsonschema.validatorsr   r   r   r   r   r   r   r   r   s       r   test_validators_ErrorTreez*TestDeprecations.test_validators_ErrorTree   s\     G""#5w?17 @ 	J$8$89X.	 @?   A))A2c                     d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                         | j	                  j                  t               y# 1 sw Y   JxY w)z
        As of v4.18.0, importing ErrorTree from the package root is
        deprecated in favor of doing so from jsonschema.exceptions.
        z9Importing ErrorTree directly from the jsonschema package r   r   N)r   r   r   r   r   r   r   r   r!   s       r   test_import_ErrorTreez&TestDeprecations.test_import_ErrorTree)   s\     N""#5w?1, @ 	J$8$89X.	 @?r#   c                 X   t        j                  ddg      }t        j                         }t        j                  |g      }d}| j                  t        |      5 }||d<   ddd       | j                  |d   |       | j                  j                  t               y# 1 sw Y   ?xY w)zM
        As of v4.20.0, setting items on an ErrorTree is deprecated.
        z
some errorfoo)path)errorszErrorTree.__setitem__ is N)r   ValidationErrorr   r   r   r   r   r   )r   etreesubtreer   r   s         r   test_ErrorTree_setitemz'TestDeprecations.test_ErrorTree_setitem6   s    
 &&|5'B##%&&qc2-""#5w?1!DK @ 	eg.X.	 @?s   B  B)c                     d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                         | j	                  j                  t               y# 1 sw Y   JxY w)z
        As of v4.18.0, importing FormatError from the package root is
        deprecated in favor of doing so from jsonschema.exceptions.
        z;Importing FormatError directly from the jsonschema package r   )FormatErrorN)r   r   r   r0   r   r   r   r   )r   r   r   r0   s       r   test_import_FormatErrorz(TestDeprecations.test_import_FormatErrorF   s\     P""#5w?1. @ 	j&<&<=X.	 @?r#   c                     d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                         | j	                  j                  t               y# 1 sw Y   JxY w)z
        As of v4.19.0, importing Validator from the package root is
        deprecated in favor of doing so from jsonschema.protocols.
        z9Importing Validator directly from the jsonschema package r   )	ValidatorN)r   r   r   r3   r   r	   r   r   )r   r   r   r3   s       r   test_import_Validatorz&TestDeprecations.test_import_ValidatorS   s\     N""#5w?1, @ 	I$7$78X.	 @?r#   c                     d}| j                  t        |      5 }t        j                  }ddd       | j                  t        j                         | j                  j
                  t               y# 1 sw Y   JxY w)za
        As of v4.0.0, accessing jsonschema.validators.validators is
        deprecated.
        z8Accessing jsonschema.validators.validators is deprecatedN)r   r   r
   r   _VALIDATORSr   r   r   r   r   values       r   test_validators_validatorsz+TestDeprecations.test_validators_validators`   sd     M""#5w?1))E @ 	
 6 67X.	 @?   A33A<c                     d}| j                  t        |      5 }t        j                  }ddd       | j	                  t        j
                         | j	                  j                  t               y# 1 sw Y   JxY w)zc
        As of v4.0.0, accessing jsonschema.validators.meta_schemas is
        deprecated.
        z:Accessing jsonschema.validators.meta_schemas is deprecatedN)r   r   r
   meta_schemasr   _META_SCHEMASr   r   r7   s       r   test_validators_meta_schemasz-TestDeprecations.test_validators_meta_schemasm   sd     O""#5w?1++E @ 	
 8 89X.	 @?r:   c                 *   t         j                  j                  i       }d}| j                  t        |      5 }|j                  d      5  	 ddd       ddd       | j                  j                  t               y# 1 sw Y   2xY w# 1 sw Y   6xY w)zC
        As of v4.0.0, RefResolver.in_scope is deprecated.
        z.jsonschema.RefResolver.in_scope is deprecated r'   N)	r
   _RefResolverfrom_schemar   r   in_scoper   r   r   )r   resolverr   r   s       r   test_RefResolver_in_scopez*TestDeprecations.test_RefResolver_in_scopez   sw    
 **66r:B""#5w?1""5) * @ 	X. *) @?s#   B	
A=B	=B	B		Bc                    t        j                  i       }d}| j                  t        |      5 }|j	                  dddi      }ddd       | j                         | j                  j                  t               y# 1 sw Y   ;xY w)zz
        As of v4.0.0, calling is_valid with two arguments (to provide a
        different schema) is deprecated.
        z5Passing a schema to Validator.is_valid is deprecated r'   typenumberN)	r
   Draft7Validatorr   r   is_validassertFalser   r   r   )r   	validatorr   r   results        r   %test_Validator_is_valid_two_argumentsz6TestDeprecations.test_Validator_is_valid_two_arguments   sw     ..r2	I""#5w?1''/ABF @ 	 X.	 @?s   A==Bc                 ,   t        j                  i       }d}| j                  t        |      5 }|j	                  dddi      \  }ddd       | j                  j                  d       | j                  j                  t               y# 1 sw Y   FxY w)z}
        As of v4.0.0, calling iter_errors with two arguments (to provide a
        different schema) is deprecated.
        z8Passing a schema to Validator.iter_errors is deprecated r'   rF   rG   N)	r
   rH   r   r   iter_errorsr   rK   r   r   )r   rK   r   r   errors        r   (test_Validator_iter_errors_two_argumentsz9TestDeprecations.test_Validator_iter_errors_two_arguments   s     ..r2	L""#5w?1**5682DEFE @ 	&1X.	 @?s   B

Bc                    t        j                  i       }d}| j                  t        |      5 }| j	                  |j
                  t         j                         ddd       | j                  j                  t               y# 1 sw Y   *xY w)zL
        As of v4.18.0, accessing Validator.resolver is deprecated.
        z&Accessing Draft7Validator.resolver is N)
r
   rH   r   r   assertIsInstancerC   r@   r   r   r   )r   rK   r   r   s       r   test_Validator_resolverz(TestDeprecations.test_Validator_resolver   sn    
 ..r2	:""#5w?1!!)"4"4j6M6MN @ 	X. @?s   +BBc                 L   d}| j                  t        |      5 }ddlm} ddd       | j	                  j
                  t               | j                  t        |      5 }ddlm} ddd       | j	                  |j
                  t               y# 1 sw Y   oxY w# 1 sw Y   6xY w)zA
        As of v4.18.0, RefResolver is fully deprecated.
        z$jsonschema.RefResolver is deprecatedr   )RefResolverN)r   r   r   rV   r   r   r   r    )r   r   r   rV   s       r   test_RefResolverz!TestDeprecations.test_RefResolver   s}    
 9""#5w?1. @X.""#5w?19 @X. @? @?s   BBBB#c                    d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                         | j	                  j                  t               | j                  t        |      5 }ddl	m} ddd       | j	                  |t
        j                         | j	                  |j                  t               y# 1 sw Y   xY w# 1 sw Y   VxY w)z
        As of v4.18.0, RefResolutionError is deprecated in favor of directly
        catching errors from the referencing library.
        z6jsonschema.exceptions.RefResolutionError is deprecatedr   RefResolutionErrorN)
r   r   r   rZ   r   r   _RefResolutionErrorr   r   jsonschema.exceptions)r   r   r   rZ   s       r   test_RefResolutionErrorz(TestDeprecations.test_RefResolutionError   s     K""#5w?15 @ 	+Z-K-KLX.""#5w?1@ @ 	+Z-K-KLX. @? @?s   C>CCC#c                 v   t        j                  ddi      }| j                  t        j                  j
                        5 }|j                  d       ddd       t        j                  j                  d      }| j                  j                  t        |j                        f|df       y# 1 sw Y   ]xY w)a  
        This behavior is the intended behavior (i.e. it's not deprecated), but
        given we do "tricksy" things in the iterim to wrap exceptions in a
        multiple inheritance subclass, we need to be extra sure it works and
        stays working.
        $refurn:nothing   N)refUnresolvable: urn:nothing)
r
   Draft202012ValidatorassertRaisesreferencingr   Unresolvablevalidater   	exceptionstr)r   rK   r+   expecteds       r   #test_catching_Unresolvable_directlyz4TestDeprecations.test_catching_Unresolvable_directly   s     33V]4KL	{55BBCqr" D ))66=6I[[#akk*+23	
	 DCs   B//B8c                    | j                  t              5  ddlm} ddd       t	        j
                  ddi      }| j                  t        j                  j                        5 }|j                  d       ddd       | j                        5 }|j                  d       ddd       | j                  j                  t        |j                        fj                  df       y# 1 sw Y   xY w# 1 sw Y   ~xY w# 1 sw Y   _xY w)z
        Until RefResolutionError is removed, it is still possible to catch
        exceptions from reference resolution using it, even though they may
        have been raised by referencing.
        r   rY   Nr_   r`   ra   rc   )assertWarnsr   r   rZ   r
   rd   re   rf   r   rg   rh   r   ri   rj   r   rZ   rK   ur+   s        r   1test_catching_Unresolvable_via_RefResolutionErrorzBTestDeprecations.test_catching_Unresolvable_via_RefResolutionError   s     015 2 33V]4KL	{55BBCqr" D 12ar" 3 	[[#akk*+[[56	
 21
 DC 32s#   C(%C4D (C14C= D	c                 :   | j                  t              5  ddlm} ddd       t	        j
                  ddi      }| j                  t        j                  j                        5 }|j                  d       ddd       | j                        5 }|j                  d       ddd       | j                  j                  j                  h       | j                  |j                  |j                  h       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   pxY w)zS
        Ensure the wrapped referencing errors are hashable when possible.
        r   rY   Nr_   r`   ra   )rn   r   r   rZ   r
   rd   re   rf   r   rg   rh   assertInri   ro   s        r   (test_WrappedReferencingError_hashabilityz9TestDeprecations.test_WrappedReferencingError_hashability   s     015 2 33V]4KL	{55BBCqr" D 12ar" 3 	akkAKK=1akkAKK=1 21
 DC 32s#   C9%DD9DDDc                 d   d}| j                  t        |      5 } G d dt        j                        }ddd       | j	                  j
                  t               | j                  t        |      5 } G d dt        j                  i             }ddd       y# 1 sw Y   hxY w# 1 sw Y   yxY w)ac  
        As of v4.12.0, subclassing a validator class produces an explicit
        deprecation warning.

        This was never intended to be public API (and some comments over the
        years in issues said so, but obviously that's not a great way to make
        sure it's followed).

        A future version will explicitly raise an error.
        z!Subclassing validator classes is c                       e Zd Zy)=TestDeprecations.test_Validator_subclassing.<locals>.SubclassN__name__
__module____qualname__     r   Subclassrw         r}   r~   Nc                       e Zd Zy)DTestDeprecations.test_Validator_subclassing.<locals>.AnotherSubclassNrx   r|   r}   r   AnotherSubclassr     r   r}   r   )meta_schema)r   r   r
   rd   r   r   r   create)r   r   r   r~   r   s        r   test_Validator_subclassingz+TestDeprecations.test_Validator_subclassing
  s     6""#5w?1:::  @ 	X.""#5w?1*"3"3"C  @? @? @?s   B1 B&B#&B/c                    | j                  t        j                  j                  dd       d}| j	                  t
        |      5 }t        j                  d       ddd       | j                  j                  t               y# 1 sw Y   *xY w)zd
        As of v4.14.0, FormatChecker.cls_checks is deprecated without
        replacement.
        boomNzFormatChecker.cls_checks )

addCleanupr   checkerspopr   r   
cls_checksr   r   r   )r   r   r   s      r   test_FormatChecker_cls_checksz.TestDeprecations.test_FormatChecker_cls_checks!  sl     	..22FDA-""#5w?1$$V, @ 	X. @?s   BBc                 J   d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                  j                         | j                  j                  t               d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                  j                         | j                  |j                  t               d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j                  j                         | j                  |j                  t               d	}| j                  t        |      5 }dd
lm} ddd       | j	                  t
        j                   j                         | j                  |j                  t               d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j$                  j                         | j                  |j                  t               d}| j                  t        |      5 }ddlm} ddd       | j	                  t
        j(                  j                         | j                  |j                  t               | j+                  t,              5  ddlm}	 ddd       y# 1 sw Y   xY w# 1 sw Y   JxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)z
        As of v4.16.0, accessing jsonschema.draftn_format_checker is deprecated
        in favor of Validator.FORMAT_CHECKER.
        z3Accessing jsonschema.draft202012_format_checker is r   )draft202012_format_checkerNz3Accessing jsonschema.draft201909_format_checker is )draft201909_format_checkerz.Accessing jsonschema.draft7_format_checker is )draft7_format_checkerz.Accessing jsonschema.draft6_format_checker is )draft6_format_checkerz.Accessing jsonschema.draft4_format_checker is )draft4_format_checkerz.Accessing jsonschema.draft3_format_checker is )draft3_format_checker)draft1234_format_checker)r   r   r   r   assertIsr
   rd   FORMAT_CHECKERr   r   r   r   Draft201909Validatorr   rH   r   Draft6Validatorr   Draft4Validatorr   Draft3Validatorre   ImportErrorr   )
r   r   r   r   r   r   r   r   r   r   s
             r   test_draftN_format_checkerz+TestDeprecations.test_draftN_format_checker/  sn    H""#5w?1= @ 	&++::	
 	X.G""#5w?1= @ 	&++::	
 	X.B""#5w?18 @ 	!&&55	
 	X.B""#5w?18 @ 	!&&55	
 	X.B""#5w?18 @ 	!&&55	
 	X.B""#5w?18 @ 	!&&55	
 	X.{+; ,+w @? @? @? @? @? @? ,+sS   K
K;K&,K3L L<LKK#&K03K= L
LL"c                     d}| j                  t        |      5 }ddl}t        j                  |j
                         ddd       | j                  j                  t        j                         y# 1 sw Y   4xY w)zH
        As of v4.17.0, importing jsonschema.cli is deprecated.
        z5The jsonschema CLI is deprecated and will be removed r   N)	r   r   jsonschema.clir   reloadclir   r   r   )r   r   r   r   s       r   test_import_cliz TestDeprecations.test_import_clit  s^    
 J""#5w?1!Z^^, @ 	Y%7%78	 @?s   $A00A9c                     t        j                  t        j                  ddgdd      }| j	                  d|j
                         y)zB
        As of v4.17.0, the jsonschema CLI is deprecated.
        z-mr   T)capture_outputchecks!   The jsonschema CLI is deprecated N)
subprocessrunsys
executablers   stderr)r   processs     r   test_clizTestDeprecations.test_cli  s;    
 ..^^T<0

 	:GNNKr}   c                 v    d}ddddiiidt         j                  v r< j                  t         j                  j                  dt         j                  d          dt         j                  d<   t         fd       }t        j                  d	|i      }d
}t        j                  j                  t        j                  d|      }|5   j                  t        |      5   j                  |j                  i       |j                  d      fd       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)zW
        Automatic retrieval of remote references is deprecated as of v4.18.0.
        zhttp://bar#/$defs/bazz$defsbazrF   integerrequestsNc              3     K   j                  | t        j                  j                         j	                  | j
                  d       | j                         \  \  }}j	                  |j                         d       j	                  |d       t        t        j                        j                  d             y w)Nz
http://barz
user-agentz.python-jsonschema (deprecated $ref resolution)utf8)rS   urllibrequestRequestr   full_urlheader_itemslowerr   jsondumpsencode)r   headerr8   schemar   s      r   fake_urlopenzFTestDeprecations.test_automatic_remote_retrieval.<locals>.fake_urlopen  s     !!'6>>+A+ABW--|<  '335OVUV\\^\:G $**V,33F;<<s   B>Cr_   z+Automatically retrieving remote references urlopen)new%   )FT)r   modulesr   __setitem__r   r
   rd   r   patchobjectr   r   r   r   r   rI   )r   rb   r   rK   r   r   r   s   `     @r   test_automatic_remote_retrievalz0TestDeprecations.test_automatic_remote_retrieval  s    &EFI#678$OO''S[[5L #'J		= 
	= 33VSMB	?

!!&..)!ND))*<gF##B'););B)?@ GUUFFUUs$   D/3D#D/#D,	(D//D8N)ry   rz   r{   r   r"   r%   r.   r1   r4   r9   r>   rD   rM   rQ   rT   rW   r]   rl   rq   rt   r   r   r   r   r   r   r|   r}   r   r   r      sx    
//// ///////
///&
$
,2$./C<J
9
L$r}   r   )
contextlibr   ior   unittestr   r   importlib.metadatar   r   r   r   urllib.requestr   referencing.exceptionsrf   r   r   r   r	   r
   r   r|   r}   r   <module>r      s4    %  #    
   G Gax ar}   