HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/jsonschema/tests/__pycache__/test_deprecations.cpython-39.pyc
a

�,�h�=�@s�ddlmZddlmZddlmZmZddlZddl	Z	ddl
Z
ddlZddlZ
ddlZddlmZmZmZmZGdd�de�ZdS)�)�contextmanager)�BytesIO)�TestCase�mockN)�
FormatChecker�
exceptions�	protocols�
validatorsc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/S)0�TestDeprecationscCsbd}|�t|��}ddlm}Wd�n1s20Y|�|tj�d��|�|jt	�dS)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�r�S/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/jsonschema/tests/test_deprecations.py�test_versions
*zTestDeprecations.test_versioncCs\d}|�t|��}ddlm}Wd�n1s20Y|�|tj�|�|jt�dS)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.validatorsrrrrr�rrrrrrr�test_validators_ErrorTrees
*z*TestDeprecations.test_validators_ErrorTreecCs\d}|�t|��}ddlm}Wd�n1s20Y|�|tj�|�|jt�dS)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 rrN)r
rrrrrrrrrrr�test_import_ErrorTree)s
*z&TestDeprecations.test_import_ErrorTreecCs�tjddgd�}t��}tj|gd�}d}|�t|��}||d<Wd�n1sT0Y|�|d|�|�|jt�dS)zM
        As of v4.20.0, setting items on an ErrorTree is deprecated.
        z
some error�foo)�path)�errorszErrorTree.__setitem__ is N)rZValidationErrorrr
rrrr)r�e�treeZsubtreerrrrr�test_ErrorTree_setitem6s&z'TestDeprecations.test_ErrorTree_setitemcCs\d}|�t|��}ddlm}Wd�n1s20Y|�|tj�|�|jt�dS)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
rrr'rrrr)rrrr'rrr�test_import_FormatErrorFs
*z(TestDeprecations.test_import_FormatErrorcCs\d}|�t|��}ddlm}Wd�n1s20Y|�|tj�|�|jt�dS)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
rrr)rrrr)rrrr)rrr�test_import_ValidatorSs
*z&TestDeprecations.test_import_ValidatorcCsVd}|�t|��}tj}Wd�n1s,0Y|�|tj�|�|jt�dS)za
        As of v4.0.0, accessing jsonschema.validators.validators is
        deprecated.
        z8Accessing jsonschema.validators.validators is deprecatedN)r
rr	rZ_VALIDATORSrr�rrr�valuerrr�test_validators_validators`s
$z+TestDeprecations.test_validators_validatorscCsVd}|�t|��}tj}Wd�n1s,0Y|�|tj�|�|jt�dS)zc
        As of v4.0.0, accessing jsonschema.validators.meta_schemas is
        deprecated.
        z:Accessing jsonschema.validators.meta_schemas is deprecatedN)r
rr	Zmeta_schemasrZ
_META_SCHEMASrrr+rrr�test_validators_meta_schemasms
$z-TestDeprecations.test_validators_meta_schemasc	Csxtj�i�}d}|�t|��:}|�d��Wd�n1s>0YWd�n1s\0Y|�|jt�dS)zC
        As of v4.0.0, RefResolver.in_scope is deprecated.
        z.jsonschema.RefResolver.in_scope is deprecated r!N)	r	�_RefResolverZfrom_schemar
rZin_scoperrr)r�resolverrrrrr�test_RefResolver_in_scopezs<z*TestDeprecations.test_RefResolver_in_scopecCsft�i�}d}|�t|�� }|�dddi�}Wd�n1s@0Y|�|�|�|jt�dS)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_validZassertFalserrr)r�	validatorrr�resultrrr�%test_Validator_is_valid_two_arguments�s
.
z6TestDeprecations.test_Validator_is_valid_two_argumentscCslt�i�}d}|�t|��"}|�dddi�\}Wd�n1sB0Y|�|jd�|�|jt�dS)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!r2r3N)	r	r4r
rZiter_errorsrr6rr)rr6rr�errorrrr�(test_Validator_iter_errors_two_arguments�s
0z9TestDeprecations.test_Validator_iter_errors_two_argumentscCs\t�i�}d}|�t|�� }|�|jtj�Wd�n1s@0Y|�|jt	�dS)zL
        As of v4.18.0, accessing Validator.resolver is deprecated.
        z&Accessing Draft7Validator.resolver is N)
r	r4r
r�assertIsInstancer0r/rrr)rr6rrrrr�test_Validator_resolver�s

.z(TestDeprecations.test_Validator_resolvercCs�d}|�t|��}ddlm}Wd�n1s20Y|�|jt�|�t|��}ddlm}Wd�n1sx0Y|�|jt�dS)zA
        As of v4.18.0, RefResolver is fully deprecated.
        z$jsonschema.RefResolver is deprecatedr)�RefResolverN)r
rrr=rrrr)rrrr=rrr�test_RefResolver�s**z!TestDeprecations.test_RefResolvercCs�d}|�t|��}ddlm}Wd�n1s20Y|�|tj�|�|jt�|�t|��}ddl	m}Wd�n1s�0Y|�|tj�|�|jt�dS)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
rrr@rrZ_RefResolutionErrorrrZjsonschema.exceptions)rrrr@rrr�test_RefResolutionError�s**z(TestDeprecations.test_RefResolutionErrorcCstt�ddi�}|�tjj��}|�d�Wd�n1s<0Ytjjdd�}|�|jt	|j�f|df�dS)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)rr6r$�expectedrrr�#test_catching_Unresolvable_directly�s(�z4TestDeprecations.test_catching_Unresolvable_directlycCs�|�t��ddlm}Wd�n1s,0Yt�ddi�}|�tjj	��}|�
d�Wd�n1sr0Y|�|��}|�
d�Wd�n1s�0Y|�|jt
|j�f|jdf�dS)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.
        rr?NrBrCrDrF)�assertWarnsrrr@r	rGrHrIrrJrKrrLrM�rr@r6�ur$rrr�1test_catching_Unresolvable_via_RefResolutionError�s*((�zBTestDeprecations.test_catching_Unresolvable_via_RefResolutionErrorcCs�|�t��ddlm}Wd�n1s,0Yt�ddi�}|�tjj	��}|�
d�Wd�n1sr0Y|�|��}|�
d�Wd�n1s�0Y|�|j|jh�|�|j|jh�dS)zS
        Ensure the wrapped referencing errors are hashable when possible.
        rr?NrBrCrD)
rPrrr@r	rGrHrIrrJrK�assertInrLrQrrr�(test_WrappedReferencingError_hashability�s*((z9TestDeprecations.test_WrappedReferencingError_hashabilitycCs�d}|�t|��"}Gdd�dtj�}Wd�n1s80Y|�|jt�|�t|��(}Gdd�dtjid��}Wd�n1s�0YdS)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@seZdZdS)z=TestDeprecations.test_Validator_subclassing.<locals>.SubclassN��__name__�
__module__�__qualname__rrrr�SubclasssrZNc@seZdZdS)zDTestDeprecations.test_Validator_subclassing.<locals>.AnotherSubclassNrVrrrr�AnotherSubclasssr[)Zmeta_schema)r
rr	rGrrr�create)rrrrZr[rrr�test_Validator_subclassing
s0z+TestDeprecations.test_Validator_subclassingcCs^|�tjjdd�d}|�t|��}t�d�Wd�n1sB0Y|�|jt	�dS)zd
        As of v4.14.0, FormatChecker.cls_checks is deprecated without
        replacement.
        ZboomNzFormatChecker.cls_checks )
�
addCleanuprZcheckers�popr
rZ
cls_checksrrr)rrrrrr�test_FormatChecker_cls_checks!s
(z.TestDeprecations.test_FormatChecker_cls_checksc
Cs^d}|�t|��}ddlm}Wd�n1s20Y|�|tjj�|�|j	t
�d}|�t|��}ddlm}Wd�n1s�0Y|�|tjj�|�|j	t
�d}|�t|��}ddlm
}Wd�n1s�0Y|�|tjj�|�|j	t
�d	}|�t|��}dd
lm}Wd�n1�sB0Y|�|tjj�|�|j	t
�d}|�t|��}ddlm}Wd�n1�s�0Y|�|tjj�|�|j	t
�d
}|�t|��}ddlm}Wd�n1�s�0Y|�|tjj�|�|j	t
�|�t��ddlm}	Wd�n1�sP0YdS)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
rrraZassertIsr	rGZFORMAT_CHECKERrrrrbZDraft201909Validatorrcr4rdZDraft6ValidatorreZDraft4ValidatorrfZDraft3ValidatorrH�ImportErrorrg)
rrrrarbrcrdrerfrgrrr�test_draftN_format_checker/sd*�*�*�,�,�,�z+TestDeprecations.test_draftN_format_checkercCsXd}|�t|��$}ddl}t�|j�Wd�n1s:0Y|�|jtj�dS)zH
        As of v4.17.0, importing jsonschema.cli is deprecated.
        z5The jsonschema CLI is deprecated and will be removed rN)	r
rZjsonschema.clir�reload�clirrr)rrrrrrr�test_import_clits
*z TestDeprecations.test_import_clicCs*tjtjddgddd�}|�d|j�dS)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�
executablerT�stderr)r�processrrr�test_cli�s
�zTestDeprecations.test_clic	s�d}ddddiii�dtjvr6��tjjdtjd�dtjd<t��fdd	��}t�d
|i�}d}tjj	t
jd|d
�}|�X��t
|��,��|�i�|�d�fd�Wd�n1s�0YWd�n1s�0YdS)zW
        Automatic retrieval of remote references is deprecated as of v4.18.0.
        zhttp://bar#/$defs/bazz$defsZbazr2�integer�requestsNc3sb��|tjj���|jd�|��\\}}��|��d���|d�tt	�
���d��VdS)Nz
http://barz
user-agentz.python-jsonschema (deprecated $ref resolution)�utf8)r;�urllib�request�Requestr�full_url�header_items�lowerr�json�dumps�encode)rz�headerr,�Zschemarrr�fake_urlopen�s�zFTestDeprecations.test_automatic_remote_retrieval.<locals>.fake_urlopenrBz+Automatically retrieving remote references �urlopen)�new�%)FT)rq�modulesr^�__setitem__rr	rGr�patch�objectryrzr
rrr5)rrEr�r6rr�rr�r�test_automatic_remote_retrieval�s"
�

�z0TestDeprecations.test_automatic_remote_retrievalN)rWrXrYrrr r&r(r*r-r.r1r8r:r<r>rArOrSrUr]r`rirlrur�rrrrr
s.






Er
)�
contextlibr�ior�unittestrr�importlib.metadatarrrorq�urllib.requestryZreferencing.exceptionsrIrrrrr	r
rrrr�<module>s