OwlCyberSecurity - MANAGER
Edit File: monkeypatch.cpython-311.pyc
� ������h :����������������������������d�Z�ddlZddlZddlZddlZddlmZ�ddlmZ�ddlm Z �ddlm Z �ddlmZ�ddlmZ�dd lm Z �dd lmZ�ddlmZ�ddlmZ�dd lmZ�ddlmZ�ddlmZ�ddlmZ��ej��������d������������Z�ed������������Z�ed������������Zede d���������fd���������������Zdedefd�Zdedededefd�Z dede!deeef���������fd�Z"�G�d��d ������������Z#�e#��������������Z$e�G�d!��d"��������������������������Z%dS�)#z)Monkeypatching and mocking functionality.�����N)�contextmanager)�Any)� Generator)�List)�Mapping)�MutableMapping)�Optional)�overload)�Tuple)�TypeVar)�Union)�final)�fixture)� PytestWarningz^No module named (.*)$�K�V�return��MonkeyPatchNNc���������������#����V���K����t������������������������}�|�V���|�������������������������������������dS�)a ��A convenient fixture for monkey-patching. The fixture provides these methods to modify objects, dictionaries, or :data:`os.environ`: * :meth:`monkeypatch.setattr(obj, name, value, raising=True) <pytest.MonkeyPatch.setattr>` * :meth:`monkeypatch.delattr(obj, name, raising=True) <pytest.MonkeyPatch.delattr>` * :meth:`monkeypatch.setitem(mapping, name, value) <pytest.MonkeyPatch.setitem>` * :meth:`monkeypatch.delitem(obj, name, raising=True) <pytest.MonkeyPatch.delitem>` * :meth:`monkeypatch.setenv(name, value, prepend=None) <pytest.MonkeyPatch.setenv>` * :meth:`monkeypatch.delenv(name, raising=True) <pytest.MonkeyPatch.delenv>` * :meth:`monkeypatch.syspath_prepend(path) <pytest.MonkeyPatch.syspath_prepend>` * :meth:`monkeypatch.chdir(path) <pytest.MonkeyPatch.chdir>` * :meth:`monkeypatch.context() <pytest.MonkeyPatch.context>` All modifications will be undone after the requesting test function or fixture has finished. The ``raising`` parameter determines if a :class:`KeyError` or :class:`AttributeError` will be raised if the set/deletion operation does not have the specified target. To undo modifications done by the fixture in a contained scope, use :meth:`context() <pytest.MonkeyPatch.context>`. N)r����undo)�mpatchs��� �d/builddir/build/BUILD/cloudlinux-venv-1.0.8/venv/lib/python3.11/site-packages/_pytest/monkeypatch.py�monkeypatchr������s+����������2��]�]�F� �L�L�L� �K�K�M�M�M�M�M������namec�����������������������|�����������������������d������������}|���������������������d������������}t����������|������������}|D�]�}|d|z���z ��} �t����������||������������}�#�t����������$�r�Y�nw�xY�w �t����������|�������������nV#�t ����������$�rI}t ����������|������������������������������������������������d���������}||k����r��t����������d|��d|���������������|�d�}~ww�xY�wt����������|||������������}��|S�)N�.r������zimport error in z: )�split�pop� __import__�getattr�AttributeError�ImportError�str�annotated_getattr)r����parts�used�found�part�ex�expecteds��� r����resolver.���;���s ������J�J�s�O�O�E��9�9�Q�<�<�D��t�$�$�E���5��5����d� ��� ��E�4�(�(�E�� ����� �� �� ��D� ���� K��t�������� K�� K�� K��2�w�w�}�}���r�*�H��4����!�"A�T�"A�"A�R�"A�"A�B�B��J����� K�����"�%��t�4�4����Ls+����A� A%�$A%�)A9�9 C�AC�C�obj�annc����������������������� �t����������|�|������������}�nI#�t����������$�r<}t����������d���������������������t����������|�������������j��������||������������������������|�d�}~ww�xY�w|�S�)Nz'{!r} object at {} has no attribute {!r})r#���r$����format�type�__name__)r/���r���r0����es��� r���r'���r'���W���sx��������c�4� � ������������5�<�<��S� � �"�C�� �� � �� ��� �����������Js������ A�7A�A�import_path�raisingc������������������������t����������|�t����������������������rd|�vrt����������d|����������������|����������������������dd������������\��}}t ����������|������������}|rt����������|||��������������||fS�)Nr���z)must be absolute import path string, not ����)r0���)� isinstancer&���� TypeError�rsplitr.���r'���)r6���r7����module�attr�targets��� r����derive_importpathr@���c���s��������k�3�'�'��U�3�k�+A�+A��S�K�S�S�T�T�T��%�%�c�1�-�-�L�F�D� �V�_�_�F���4��&�$�F�3�3�3�3���<�r���c�������������������������e�Zd�Zdefd�ZdS�)�Notsetr���c�����������������������dS�)Nz<notset>����selfs��� r����__repr__zNotset.__repr__n���s�������zr���N)r4���� __module__�__qualname__r&���rG���rD���r���r���rB���rB���m���s/���������������#������������r���rB���c�������������������������e�Zd�ZdZdd�Zeeded���������fd�����������������������������Ze � �dde d ed ede ddf d���������������Ze �dded e d ede ddf d ���������������Zedfdee ef���������d eee f���������d ede ddf d�Zedfdeee f���������d ee ef���������de ddfd�Zdeeef���������d ed eddfd�Zddeeef���������d ede ddfd�Zd d e d e dee ���������ddfd�Zdd e de ddfd�Zdd�Zdee df���������ddfd�Zdd�ZdS�)!r���a���Helper to conveniently monkeypatch attributes/items/environment variables/syspath. Returned by the :fixture:`monkeypatch` fixture. .. versionchanged:: 6.2 Can now also be used directly as `pytest.MonkeyPatch()`, for when the fixture is not available. In this case, use :meth:`with MonkeyPatch.context() as mp: <context>` or remember to call :meth:`undo` explicitly. r���Nc������������������>�����g�|�_���������g�|�_��������d�|�_��������d�|�_��������d�S��N)�_setattr�_setitem�_cwd�_savesyspathrE���s��� r����__init__zMonkeyPatch.__init__����s%������:<�� �HJ�� �#'�� �15����r���r���c��������������#�������K�����|���������������} �|V���|�������������������������������������dS�#�|�������������������������������������w�xY�w)a]��Context manager that returns a new :class:`MonkeyPatch` object which undoes any patching done inside the ``with`` block upon exit. Example: .. code-block:: python import functools def test_partial(monkeypatch): with monkeypatch.context() as m: m.setattr(functools, "partial", 3) Useful in situations where it is desired to undo some patches before the test ends, such as mocking ``stdlib`` functions that might break pytest itself if mocked (for examples of this see :issue:`3290`). N)r���)�cls�ms��� r����contextzMonkeyPatch.context����sD����������*� �C�E�E�� ��G�G�G� �F�F�H�H�H�H�H��A�F�F�H�H�H�H���s����(��>.r?���r����valuer7���c�����������������������d�S�rL���rD����rF���r?���r���rV���r7���s��� r����setattrzMonkeyPatch.setattr����� ������� �r���c�����������������������d�S�rL���rD���rX���s��� r���rY���zMonkeyPatch.setattr����rZ���r���Tc������������������(����d}ddl�}t����������|t����������������������r:t����������|t����������������������st ����������d�������������|}t����������||������������\��}}n$t����������|t����������������������st ����������d�������������t ����������||t����������������������}|r|t����������u�rt����������|�d|���������������|� ��������������������|������������r |j �����������������������������|t����������������������}|�j��������� ��������������������|||f�������������t����������|||�������������dS�)a��� Set attribute value on target, memorizing the old value. For example: .. code-block:: python import os monkeypatch.setattr(os, "getcwd", lambda: "/") The code above replaces the :func:`os.getcwd` function by a ``lambda`` which always returns ``"/"``. For convenience, you can specify a string as ``target`` which will be interpreted as a dotted import path, with the last part being the attribute name: .. code-block:: python monkeypatch.setattr("os.getcwd", lambda: "/") Raises :class:`AttributeError` if the attribute does not exist, unless ``raising`` is set to False. **Where to patch** ``monkeypatch.setattr`` works by (temporarily) changing the object that a name points to with another one. There can be many names pointing to any individual object, so for patching to work you must ensure that you patch the name used by the system under test. See the section :ref:`Where to patch <python:where-to-patch>` in the :mod:`unittest.mock` docs for a complete explanation, which is meant for :func:`unittest.mock.patch` but applies to ``monkeypatch.setattr`` as well. Tr���Nzcuse setattr(target, name, value) or setattr(target, value) with target being a dotted import stringz|use setattr(target, name, value) with name being a string or setattr(target, value) with target being a dotted import stringz has no attribute )�inspectr:���rB���r&���r;���r@���r#����notsetr$����isclass�__dict__�getrM����appendrY���)rF���r?���r���rV���r7����__tracebackhide__r]����oldvals��� r���rY���zMonkeyPatch.setattr����s8�����T�!�������e�V�$�$�� ��f�c�*�*�� ��$������ ��E�,�V�W�=�=�L�D�&�&��d�C�(�(�� ��$����������v�.�.���� J�v��'�'� �F�!H�!H��!H�!H�I�I�I���?�?�6�"�"�� 7��_�(�(��v�6�6�F�� ���f�d�F�3�4�4�4����e�$�$�$�$�$r���c�����������������������d}ddl�}t����������|t����������������������r7t����������|t����������������������st ����������d�������������t����������||������������\��}}t ����������||������������s|rt����������|�������������dS�t����������||t����������������������}|� ��������������������|������������r |j�����������������������������|t����������������������}|�j �����������������������������|||f�������������t����������||�������������dS�)aK��Delete attribute ``name`` from ``target``. If no ``name`` is specified and ``target`` is a string it will be interpreted as a dotted import path with the last part being the attribute name. Raises AttributeError it the attribute does not exist, unless ``raising`` is set to False. Tr���NzUuse delattr(target, name) or delattr(target) with target being a dotted import string)r]���r:���rB���r&���r;���r@����hasattrr$���r#���r^���r_���r`���ra���rM���rb����delattr)rF���r?���r���r7���rc���r]���rd���s��� r���rg���zMonkeyPatch.delattr���s������!�������d�F�#�#�� >��f�c�*�*�� ��$������ �-�V�W�=�=�L�D�&��v�t�$�$�� "��� +�$�T�*�*�*� +�� +���V�T�6�2�2�F����v�&�&�� ;���,�,�T�6�:�:���M� � �&�$��!7�8�8�8��F�D�!�!�!�!�!r����dicc������������������|�����|�j������������������������������|||���������������������|t����������������������f�������������|||<���dS�)z'Set dictionary entry ``name`` to value.N)rN���rb���ra���r^���)rF���rh���r���rV���s��� r����setitemzMonkeyPatch.setitem&��s:������� ���c�4�����v�)>�)>�?�@�@�@���D� � � r���c�����������������������||vr|rt����������|�������������dS�|�j�����������������������������|||���������������������|t����������������������f�������������||=�dS�)z�Delete ``name`` from dict. Raises ``KeyError`` if it doesn't exist, unless ``raising`` is set to False. N)�KeyErrorrN���rb���ra���r^���)rF���rh���r���r7���s��� r����delitemzMonkeyPatch.delitem,��sc��������s�?�?��� %��t�n�n�$� %�� %�� �M� � �#�t�S�W�W�T�6�-B�-B�!C�D�D�D��D� � � r����prependc������������������v����t����������|t����������������������sZt����������j��������t ����������d���������������������||t ����������|������������j���������������������������������d��������������t����������|������������}|r&|t����������j ��������v�r||z���t����������j ��������|���������z���}|�� ��������������������t����������j ��������||�������������dS�)z�Set environment variable ``name`` to ``value``. If ``prepend`` is a character, read the current environment variable value and prepend the ``value`` adjoined with the ``prepend`` character. zvValue of environment variable {name} type should be str, but got {value!r} (type: {type}); converted to str implicitly)r���rV���r3�������)� stacklevelN)r:���r&����warnings�warnr���r2���r3���r4����os�environrj���)rF���r���rV���rn���s��� r����setenvzMonkeyPatch.setenv:��s���������%��%�%�� ��M��L�LR�F�!��T�%�[�[�5I��MS��M��M������ �� �� �� ����J�J�E��� 7�t�r�z�)�)��G�O�b�j��&6�6�E����R�Z��u�-�-�-�-�-r���c������������������N�����t�����������j��������}|����������������������|||��������������dS�)z�Delete ``name`` from the environment. Raises ``KeyError`` if it does not exist, unless ``raising`` is set to False. )r7���N)rt���ru���rm���)rF���r���r7���ru���s��� r����delenvzMonkeyPatch.delenvP��s)�������-/�J�����W�d�G��4�4�4�4�4r���c����������������������|�j����������t����������j��������dd����������|�_���������t����������j�����������������������������dt ����������|�������������������������dt����������j��������v�rddlm}��|t ����������|�������������������������ddlm }��|���������������dS�)z:Prepend ``path`` to ``sys.path`` list of import locations.Nr���� pkg_resources)�fixup_namespace_packages)�invalidate_caches) rP����sys�path�insertr&����modulesrz���r{���� importlibr|���)rF���r~���r{���r|���s��� r����syspath_prependzMonkeyPatch.syspath_prependY��s����������$� #������D�������3�t�9�9�%�%�%���c�k�)�)�>�>�>�>�>�>�$�$�S��Y�Y�/�/�/�� 0�/�/�/�/�/�������r���r~���zos.PathLike[str]c������������������l�����|�j����������t����������j����������������������|�_���������t����������j��������|�������������dS�)zChange the current working directory to the specified path. :param path: The path to change into. N)rO���rt����getcwd�chdir)rF���r~���s��� r���r����zMonkeyPatch.chdirr��s*��������9��� ���D�I� �������r���c�����������������������t����������|�j��������������������D�]1\��}}}|t����������urt����������|||��������������!t ����������||��������������2g�|�j��������dd�<���t����������|�j��������������������D�])\��}}}|t����������u�r �||=��#�t����������$�r�Y�� w�xY�w|||<����*g�|�j��������dd�<���|�j���������|�j��������t����������j ��������dd�<���d|�_��������|�j ���������"t����������j��������|�j ���������������������d|�_ ��������dS�dS�)a���Undo previous changes. This call consumes the undo stack. Calling it a second time has no effect unless you do more monkeypatching after the undo call. There is generally no need to call `undo()`, since it is called automatically during tear-down. .. note:: The same `monkeypatch` fixture is used across a single test function invocation. If `monkeypatch` is used both by the test function itself and one of the test fixtures, calling `undo()` will undo all of the changes made in both functions. Prefer to use :meth:`context() <pytest.MonkeyPatch.context>` instead. N) �reversedrM���r^���rY���rg���rN���rl���rP���r}���r~���rO���rt���r����)rF���r/���r���rV���� dictionary�keys��� r���r���zMonkeyPatch.undo|��s+�����$�!)��� 7� 7�� #�� #��C��u��F�"�"���T�5�)�)�)�)���T�"�"�"�"��� �a�a�a��&.�t�}�&=�&=�� (�� (�"�J��U������"�3������������D������#(� �3����� �a�a�a����(��+�C�H�Q�Q�Q�K� $�D���9� ��H�T�Y�����D�I�I�I��!� s����7A;�; B�B)r���N)..).)TrL���)r4���rH���rI����__doc__rQ����classmethodr���r���rU���r ���r&����objectrB����boolrY���r^���r ���rg���r���r���r���rj���rm���r ���rv���rx���r����r����r���rD���r���r���r���r���u���s������������� �� �6��6��6��6����� �";�<���������^���[��2�� ������������� � ���� � �������X���������������� � ���� � �������X�����F%��F%��c�6�k�"�F%���F�C�K� �F%��� F%� ��F%�� � F%��F%��F%��F%�V�$*�� $"��$"��f�c�k�"�$"���C��K� �$"��� $"� � �$"��$"��$"��$"�L�7�1�a�4�=������!���������������7�1�a�4�=������D���D���������.��.�3��.�s��.�X�c�]��.�d��.��.��.��.�,5��5�3��5���5���5��5��5��5��������2�%��%7� 7�8���T���������)��)��)��)��)��)r���r���)&r����rt����rer}���rr���� contextlibr����typingr���r���r���r���r���r ���r ���r���r���r ����_pytest.compatr����_pytest.fixturesr����_pytest.warning_typesr����compile�RE_IMPORT_ERROR_NAMEr���r���r���r&���r����r.���r'���r����r@���rB���r^���r���rD���r���r����<module>r�������s������/��/�� � � � �� � � � �� � � � �������%��%��%��%��%��%��������������������������������������������������!��!��!��!��!��!�������������������������������������������������������������� �� �� �� �� �� ��$��$��$��$��$��$��/��/��/��/��/��/�!�r�z�";�<�<�����G�C�L�L���G�C�L�L��� ��Y�8�9�������� ���:�#���&���������8 �6�� ��� �3�� �6�� �� �� �� ��3������%��V��:L������������������������ � �������o��o��o��o��o��o��o����o��o��or���