
    3~hS                        d Z ddlmZmZ 	 ddlmZ ddlmZ ddlmZ d	d
lmZmZ ed        ZeZed        Zed        Zed        Zed        Zed        Zed        Zy# e$ r ddlZdZ ej                  ee
        w xY w)au  
`pytest <https://pytest.org>`_ fixtures for easy use of Fabric test helpers.

To get Fabric plus this module's dependencies (as well as those of the main
`fabric.testing.base` module which these fixtures wrap), ``pip install
fabric[pytest]``.

The simplest way to get these fixtures loaded into your test suite so Pytest
notices them is to import them into a ``conftest.py`` (`docs
<http://pytest.readthedocs.io/en/latest/fixture.html#conftest-py-sharing-fixture-functions>`_).
For example, if you intend to use the `remote` and `client` fixtures::

    from fabric.testing.fixtures import client, remote

.. versionadded:: 2.1
    )patchMock)fixtureNzeYou appear to be missing some optional test-related dependencies;please 'pip install fabric[pytest]'.   )
Connection)Transfer   )
MockRemoteMockSFTPc               #      K   t        dd      } d| j                  j                  _        t	               | _        t	               | _        |  yw)a  
    Yields a `.Connection` object with mocked methods.

    Specifically:

    - the hostname is set to ``"host"`` and the username to ``"user"``;
    - the primary API members (`.Connection.run`, `.Connection.local`, etc) are
      replaced with ``mock.Mock`` instances;
    - the ``run.in_stream`` config option is set to ``False`` to avoid attempts
      to read from stdin (which typically plays poorly with pytest and other
      capturing test runners);

    .. versionadded:: 2.1
    hostuser)r   r   FN)r   configrun	in_streamr   local)cs    `/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/fabric/testing/fixtures.py
connectionr   &   s=       	V,A"AHHLLFAEfAG
 Gs   AAc               #   V   K   t        d      5 } |  ddd       y# 1 sw Y   yxY ww)a   
    Like `remote`, but with ``enable_sftp=True``.

    To access the internal mocked SFTP client (eg for asserting SFTP
    functionality was called), note that the returned `MockRemote` object has a
    ``.sftp`` attribute when created in this mode.
    T)enable_sftpN)r
   remotes    r   remote_with_sftpr   H   s+      
	%   s   )	)&)c               #   h   K   t               } |  | j                          | j                          yw)ac  
    Fixture allowing setup of a mocked remote session & access to sub-mocks.

    Yields a `.MockRemote` object (which may need to be updated via
    `.MockRemote.expect`, `.MockRemote.expect_sessions`, etc; otherwise a
    default session will be used) & calls `.MockRemote.safety` and
    `.MockRemote.stop` on teardown.

    .. versionadded:: 2.1
    N)r
   safetystopr   s    r   r   r   X   s&      \F
L
MMO
KKMs   02c               #      K   t        d      } | j                         \  }}t        t        d            }|||f yw)aC  
    Fixture allowing setup of a mocked remote SFTP session.

    Yields a 3-tuple of: Transfer() object, SFTPClient object, and mocked OS
    module.

    For many/most tests which only want the Transfer and/or SFTPClient objects,
    see `sftp_objs` and `transfer` which wrap this fixture.

    .. versionadded:: 2.1
    F)	autostartr   N)r   startr   r   )mockclientmock_ostransfers       r   sftpr%   j   s=      e$DjjlOFG
6*+H
FG
##s   <>c              #      K   | dd  yw)zf
    Wrapper for `sftp` which only yields the Transfer and SFTPClient.

    .. versionadded:: 2.1
    Nr    r%   s    r   	sftp_objsr)      s      r(N   	c              #      K   | d    yw)z^
    Wrapper for `sftp` which only yields the Transfer object.

    .. versionadded:: 2.1
    r   Nr'   r(   s    r   r$   r$      s      q'Mr*   c               #      K   t        d      5 } | j                  }t        d      |j                  _        | ddd       y# 1 sw Y   yxY ww)a  
    Mocks `~paramiko.client.SSHClient` for testing calls to ``connect()``.

    Yields a mocked ``SSHClient`` instance.

    This fixture updates `~paramiko.client.SSHClient.get_transport` to return a
    mock that appears active on first check, then inactive after, matching most
    tests' needs by default:

    - `.Connection` instantiates, with a None ``.transport``.
    - Calls to ``.open()`` test ``.is_connected``, which returns ``False`` when
      ``.transport`` is falsey, and so the first open will call
      ``SSHClient.connect`` regardless.
    - ``.open()`` then sets ``.transport`` to ``SSHClient.get_transport()``, so
      ``Connection.transport`` is effectively
      ``client.get_transport.return_value``.
    - Subsequent activity will want to think the mocked SSHClient is
      "connected", meaning we want the mocked transport's ``.active`` to be
      ``True``.
    - This includes `.Connection.close`, which short-circuits if
      ``.is_connected``; having a statically ``True`` active flag means a full
      open -> close cycle will run without error. (Only tests that double-close
      or double-open should have issues here.)

    End result is that:

    - ``.is_connected`` behaves False after instantiation and before ``.open``,
      then True after ``.open``
    - ``.close`` will work normally on 1st call
    - ``.close`` will behave "incorrectly" on subsequent calls (since it'll
      think connection is still live.) Tests that check the idempotency of
      ``.close`` will need to tweak their mock mid-test.

    For 'full' fake remote session interaction (i.e. stdout/err
    reading/writing, channel opens, etc) see `remote`.

    .. versionadded:: 2.1
    zfabric.connection.SSHClientT)activeN)r   return_valuer   get_transport)	SSHClientr"   s     r   r"   r"      sK     P 
,	- '',0,=)  s   A,A	AAA)__doc__unittest.mockr   r   pytestr   ImportErrorwarningswarningwarnImportWarning r   r$   r   baser
   r   r   cxnr   r   r%   r)   r"   r'       r   <module>r=      s   " &

   & 	 	:  	 	 	 	" 	$ 	$( 	 	 	 	 	* 	*}  
	/  HMM'=)	
s   A! ! B