1
0
Fork 0
python-docs-fr/library/unittest.mock.po

2622 lines
96 KiB
Plaintext
Raw Normal View History

2018-07-04 09:06:45 +00:00
# Copyright (C) 2001-2018, Python Software Foundation
2018-07-04 09:08:42 +00:00
# For licence information, see README file.
2016-10-30 09:46:26 +00:00
#
msgid ""
msgstr ""
2019-12-05 22:15:54 +00:00
"Project-Id-Version: Python 3\n"
2016-10-30 09:46:26 +00:00
"Report-Msgid-Bugs-To: \n"
2023-04-14 11:20:40 +00:00
"POT-Creation-Date: 2023-04-14 13:19+0200\n"
"PO-Revision-Date: 2019-04-22 12:07+0200\n"
"Last-Translator: Bousquié Pierre <pierre.bousquie@gmail.com>\n"
2018-07-04 09:14:25 +00:00
"Language-Team: FRENCH <traductions@lists.afpy.org>\n"
2017-05-23 22:40:56 +00:00
"Language: fr\n"
2016-10-30 09:46:26 +00:00
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:3
2016-10-30 09:46:26 +00:00
msgid ":mod:`unittest.mock` --- mock object library"
msgstr ":mod:`unittest.mock` — Bibliothèque d'objets simulacres"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:13
2016-10-30 09:46:26 +00:00
msgid "**Source code:** :source:`Lib/unittest/mock.py`"
msgstr "**Code source :** :source:`Lib/unittest/mock.py`"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:17
2016-10-30 09:46:26 +00:00
msgid ""
":mod:`unittest.mock` is a library for testing in Python. It allows you to "
"replace parts of your system under test with mock objects and make "
"assertions about how they have been used."
msgstr ""
":mod:`unittest.mock` est une bibliothèque pour tester en Python. Elle permet "
"de remplacer des parties du système sous tests par des objets simulacres et "
"faire des assertions sur la façon dont ces objets ont été utilisés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:21
2016-10-30 09:46:26 +00:00
msgid ""
":mod:`unittest.mock` provides a core :class:`Mock` class removing the need "
"to create a host of stubs throughout your test suite. After performing an "
"action, you can make assertions about which methods / attributes were used "
"and arguments they were called with. You can also specify return values and "
"set needed attributes in the normal way."
msgstr ""
":mod:`unittest.mock` fournit une classe :class:`Mock` pour ne pas avoir "
"besoin de créer manuellement des objets factices dans la suite de tests. "
"Après avoir effectué une action, on peut faire des assertions sur les "
"méthodes / attributs utilisés et les arguments avec lesquels ils ont été "
"appelés. On peut également spécifier des valeurs renvoyées et définir les "
"attributs nécessaires aux tests."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:27
2016-10-30 09:46:26 +00:00
msgid ""
"Additionally, mock provides a :func:`patch` decorator that handles patching "
"module and class level attributes within the scope of a test, along with :"
"const:`sentinel` for creating unique objects. See the `quick guide`_ for "
"some examples of how to use :class:`Mock`, :class:`MagicMock` and :func:"
"`patch`."
msgstr ""
"De plus, *mock* fournit un décorateur :func:`patch` qui est capable de "
"*patcher* les modules et les classes dans la portée d'un test, ainsi que :"
"const:`sentinel` pour créer des objets uniques. Voir le guide rapide `quick "
"guide`_ pour quelques exemples d'utilisation de :class:`Mock`, :class:"
"`MagicMock` et :func:`patch`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:33
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"Mock is designed for use with :mod:`unittest` and is based on the 'action -> "
"assertion' pattern instead of 'record -> replay' used by many mocking "
"frameworks."
2016-10-30 09:46:26 +00:00
msgstr ""
"*Mock* est très facile à utiliser et est conçu pour être utilisé avec :mod:"
"`unittest`. *Mock* est basé sur le modèle *action -> assertion* au lieu de "
"*enregistrement -> rejouer* utilisé par de nombreux cadriciels d'objets "
"simulacres."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:37
2016-10-30 09:46:26 +00:00
msgid ""
"There is a backport of :mod:`unittest.mock` for earlier versions of Python, "
2018-06-10 09:32:30 +00:00
"available as `mock on PyPI <https://pypi.org/project/mock>`_."
2016-10-30 09:46:26 +00:00
msgstr ""
"Il y a un portage de :mod:`unittest.mock` pour les versions antérieures de "
"Python, disponible `sur PyPI <https://pypi.org/project/mock>`_."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:42
2016-10-30 09:46:26 +00:00
msgid "Quick Guide"
msgstr "Guide rapide"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:60
2016-10-30 09:46:26 +00:00
msgid ""
":class:`Mock` and :class:`MagicMock` objects create all attributes and "
"methods as you access them and store details of how they have been used. You "
"can configure them, to specify return values or limit what attributes are "
"available, and then make assertions about how they have been used:"
msgstr ""
"Les classes :class:`Mock` et :class:`MagicMock` créent tous les attributs et "
"méthodes au fur et à mesure des accès et stockent les détails de la façon "
"dont ils ont été utilisés. On peut les configurer, pour spécifier des "
"valeurs de renvoi ou limiter les attributs utilisables, puis faire des "
"assertions sur la façon dont ils ont été utilisés :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:72
2016-10-30 09:46:26 +00:00
msgid ""
":attr:`side_effect` allows you to perform side effects, including raising an "
"exception when a mock is called:"
msgstr ""
"L'attribut :attr:`side_effect` permet de spécifier des effets de bords, y "
"compris la levée d'une exception lorsqu'un objet simulacre est appelé :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:92
2016-10-30 09:46:26 +00:00
msgid ""
"Mock has many other ways you can configure it and control its behaviour. For "
"example the *spec* argument configures the mock to take its specification "
"from another object. Attempting to access attributes or methods on the mock "
"that don't exist on the spec will fail with an :exc:`AttributeError`."
msgstr ""
"Il existe beaucoup d'autres façons de configurer et de contrôler le "
"comportement de *Mock*. Par exemple, l'argument *spec* configure le *mock* "
"pour qu'il utilise les spécifications d'un autre objet. Tenter d'accéder à "
"des attributs ou méthodes sur le *mock* qui n'existent pas sur l'objet "
"*spec* lève une :exc:`AttributeError`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:97
2019-09-04 09:35:23 +00:00
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"The :func:`patch` decorator / context manager makes it easy to mock classes "
"or objects in a module under test. The object you specify will be replaced "
"with a mock (or other object) during the test and restored when the test "
2019-09-04 09:35:23 +00:00
"ends::"
2016-10-30 09:46:26 +00:00
msgstr ""
"Le décorateur / gestionnaire de contexte :func:`patch` permet de simuler "
"facilement des classes ou des objets dans un module sous tests. L'objet "
"spécifié est remplacé par un objet simulacre (ou autre) pendant le test et "
"est restauré à la fin du test ::"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:116
2016-10-30 09:46:26 +00:00
msgid ""
"When you nest patch decorators the mocks are passed in to the decorated "
2018-09-15 20:37:31 +00:00
"function in the same order they applied (the normal *Python* order that "
2016-10-30 09:46:26 +00:00
"decorators are applied). This means from the bottom up, so in the example "
"above the mock for ``module.ClassName1`` is passed in first."
msgstr ""
"Lorsque l'on imbrique des décorateurs de patchs, les *mocks* sont transmis à "
"la fonction décorée dans le même ordre qu'ils ont été déclarés (l'ordre "
"normal *Python* des décorateurs est appliqué). Cela signifie du bas vers le "
"haut, donc dans l'exemple ci-dessus, l'objet simulacre pour ``module."
"ClassName1`` est passé en premier."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:121
2016-10-30 09:46:26 +00:00
msgid ""
"With :func:`patch` it matters that you patch objects in the namespace where "
"they are looked up. This is normally straightforward, but for a quick guide "
"read :ref:`where to patch <where-to-patch>`."
msgstr ""
"Avec :func:`patch`, il est important de *patcher* les objets dans l'espace "
"de nommage où ils sont recherchés. C'est ce qui se fait normalement, mais "
"pour un guide rapide, lisez :ref:`où patcher <where-to-patch>`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:125
2016-10-30 09:46:26 +00:00
msgid ""
"As well as a decorator :func:`patch` can be used as a context manager in a "
"with statement:"
msgstr ""
"Comme tout décorateur, :func:`patch` peut être utilisé comme gestionnaire de "
"contexte avec une instruction *with* :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:135
2016-10-30 09:46:26 +00:00
msgid ""
"There is also :func:`patch.dict` for setting values in a dictionary just "
"during a scope and restoring the dictionary to its original state when the "
"test ends:"
msgstr ""
"Il existe également :func:`patch.dict` pour définir des valeurs d'un "
"dictionnaire au sein d'une portée et restaurer ce dictionnaire à son état "
"d'origine lorsque le test se termine :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:146
2016-10-30 09:46:26 +00:00
msgid ""
"Mock supports the mocking of Python :ref:`magic methods <magic-methods>`. "
"The easiest way of using magic methods is with the :class:`MagicMock` class. "
"It allows you to do things like:"
msgstr ""
"*Mock* gère le remplacement des :ref:`méthodes magiques <magic-methods>` de "
"Python. La façon la plus simple d'utiliser les méthodes magiques est la "
"classe :class:`MagicMock`. Elle permet de faire des choses comme :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:156
2016-10-30 09:46:26 +00:00
msgid ""
"Mock allows you to assign functions (or other Mock instances) to magic "
"methods and they will be called appropriately. The :class:`MagicMock` class "
"is just a Mock variant that has all of the magic methods pre-created for you "
"(well, all the useful ones anyway)."
msgstr ""
"*Mock* permet d'assigner des fonctions (ou d'autres instances *Mock*) à des "
"méthodes magiques et elles seront appelées correctement. La classe :class:"
"`MagicMock` est juste une variante de *Mock* qui a toutes les méthodes "
"magiques pré-créées (enfin, toutes les méthodes utiles)."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:161
2016-10-30 09:46:26 +00:00
msgid ""
"The following is an example of using magic methods with the ordinary Mock "
"class:"
msgstr ""
"L'exemple suivant est un exemple de création de méthodes magiques avec la "
"classe *Mock* ordinaire :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:169
2016-10-30 09:46:26 +00:00
msgid ""
"For ensuring that the mock objects in your tests have the same api as the "
"objects they are replacing, you can use :ref:`auto-speccing <auto-"
"speccing>`. Auto-speccing can be done through the *autospec* argument to "
"patch, or the :func:`create_autospec` function. Auto-speccing creates mock "
"objects that have the same attributes and methods as the objects they are "
"replacing, and any functions and methods (including constructors) have the "
"same call signature as the real object."
msgstr ""
"Pour être sûr que les objets simulacres dans vos tests ont la même API que "
"les objets qu'ils remplacent, utilisez :ref:`l'auto-spécification <auto-"
"speccing>`. L'auto-spécification peut se faire via l'argument *autospec* de "
"patch ou par la fonction :func:`create_autospec`. L'auto-spécification crée "
"des objets simulacres qui ont les mêmes attributs et méthodes que les objets "
"qu'ils remplacent, et toutes les fonctions et méthodes (y compris les "
"constructeurs) ont les mêmes signatures d'appel que l'objet réel."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:177
2016-10-30 09:46:26 +00:00
msgid ""
"This ensures that your mocks will fail in the same way as your production "
"code if they are used incorrectly:"
msgstr ""
"Ceci garantit que vos objets simulacres échouent de la même manière que "
"votre code de production s'ils ne sont pas utilisés correctement :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:193
2016-10-30 09:46:26 +00:00
msgid ""
":func:`create_autospec` can also be used on classes, where it copies the "
"signature of the ``__init__`` method, and on callable objects where it "
"copies the signature of the ``__call__`` method."
msgstr ""
"La fonction :func:`create_autospec` peut aussi être utilisée sur les "
"classes, où elle copie la signature de la méthode ``__init__``, et sur les "
"objets appelables où elle copie la signature de la méthode ``__call__``."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:200
2016-10-30 09:46:26 +00:00
msgid "The Mock Class"
msgstr "La classe *Mock*"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:211
2016-10-30 09:46:26 +00:00
msgid ""
":class:`Mock` is a flexible mock object intended to replace the use of stubs "
"and test doubles throughout your code. Mocks are callable and create "
"attributes as new mocks when you access them [#]_. Accessing the same "
"attribute will always return the same mock. Mocks record how you use them, "
"allowing you to make assertions about what your code has done to them."
msgstr ""
"La classe :class:`Mock` est un objet simulacre flexible destiné à remplacer "
"l'utilisation d'objets bouchons et factices dans votre code. Les Mocks sont "
"appelables et créent des attributs comme de nouveaux *Mocks* lorsque l'on y "
"accède [#]_. L'accès au même attribut renvoie toujours le même *mock*. Les "
"simulacres enregistrent la façon dont ils sont utilisés, ce qui permet de "
"faire des assertions sur ce que le code leur a fait."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:217
2016-10-30 09:46:26 +00:00
msgid ""
":class:`MagicMock` is a subclass of :class:`Mock` with all the magic methods "
"pre-created and ready to use. There are also non-callable variants, useful "
"when you are mocking out objects that aren't callable: :class:"
"`NonCallableMock` and :class:`NonCallableMagicMock`"
msgstr ""
"La classe :class:`MagicMock` est une sous-classe de :class:`Mock` avec "
"toutes les méthodes magiques pré-créées et prête à l'emploi. Il existe "
"également des variantes non appelables, utiles lorsque l'on simule des "
"objets qui ne sont pas appelables : :class:`NonCallableMock` et :class:"
"`NonCallableMagicMock`"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:222
2016-10-30 09:46:26 +00:00
msgid ""
"The :func:`patch` decorators makes it easy to temporarily replace classes in "
"a particular module with a :class:`Mock` object. By default :func:`patch` "
"will create a :class:`MagicMock` for you. You can specify an alternative "
"class of :class:`Mock` using the *new_callable* argument to :func:`patch`."
msgstr ""
"Le décorateur :func:`patch` facilite le remplacement temporaire de classes "
"d'un module avec un objet :class:`Mock`. Par défaut :func:`patch` crée un :"
"class:`MagicMock`. On peut spécifier une classe alternative de :class:`Mock` "
"en utilisant le paramètre *new_callable* de :func:`patch`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:230
2016-10-30 09:46:26 +00:00
msgid ""
"Create a new :class:`Mock` object. :class:`Mock` takes several optional "
"arguments that specify the behaviour of the Mock object:"
msgstr ""
"Crée un nouvel objet :class:`Mock`. :class:`Mock` prend plusieurs arguments "
"optionnels qui spécifient le comportement de l'objet *Mock* :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:233
2016-10-30 09:46:26 +00:00
msgid ""
"*spec*: This can be either a list of strings or an existing object (a class "
"or instance) that acts as the specification for the mock object. If you pass "
"in an object then a list of strings is formed by calling dir on the object "
"(excluding unsupported magic attributes and methods). Accessing any "
"attribute not in this list will raise an :exc:`AttributeError`."
msgstr ""
"*spec* : une liste de chaînes de caractères ou un objet existant (une classe "
"ou une instance) qui sert de spécification pour l'objet simulacre. Si on "
"passe un objet, alors une liste de chaînes de caractères est formée en "
"appelant la fonction *dir* sur l'objet (à l'exclusion des attributs et "
"méthodes magiques non pris en charge). L'accès à un attribut qui n'est pas "
"dans cette liste entraîne la levée d'une exception :exc:`AttributeError`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:239
2016-10-30 09:46:26 +00:00
msgid ""
"If *spec* is an object (rather than a list of strings) then :attr:`~instance."
"__class__` returns the class of the spec object. This allows mocks to pass :"
"func:`isinstance` tests."
msgstr ""
"Si *spec* est un objet (plutôt qu'une liste de chaînes de caractères) alors :"
"attr:`~instance.__class__` renvoie la classe de l'objet spécifié. Ceci "
"permet aux *mocks* de passer les tests :func:`isinstance`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:243
2016-10-30 09:46:26 +00:00
msgid ""
"*spec_set*: A stricter variant of *spec*. If used, attempting to *set* or "
"get an attribute on the mock that isn't on the object passed as *spec_set* "
"will raise an :exc:`AttributeError`."
msgstr ""
"*spec_set* : variante plus stricte de *spec*. S'il est utilisé, essayer "
"d'utiliser la fonction *set* ou tenter daccéder à un attribut sur le *mock* "
"qui n'est pas sur l'objet passé comme *spec_set* lève une exception :exc:"
"`AttributeError`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:247
2016-10-30 09:46:26 +00:00
msgid ""
"*side_effect*: A function to be called whenever the Mock is called. See the :"
"attr:`~Mock.side_effect` attribute. Useful for raising exceptions or "
"dynamically changing return values. The function is called with the same "
"arguments as the mock, and unless it returns :data:`DEFAULT`, the return "
"value of this function is used as the return value."
msgstr ""
"*side_effect* : fonction à appeler à chaque fois que le *Mock* est appelé. "
"Voir l'attribut :attr:`~Mock.side_effect`. Utile pour lever des exceptions "
"ou modifier dynamiquement les valeurs de retour. La fonction est appelée "
"avec les mêmes arguments que la fonction simulée et, à moins qu'elle ne "
"renvoie :data:`DEFAULT`, la valeur de retour de cette fonction devient la "
"valeur de retour de la fonction simulée."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:253
2016-10-30 09:46:26 +00:00
msgid ""
"Alternatively *side_effect* can be an exception class or instance. In this "
"case the exception will be raised when the mock is called."
msgstr ""
"*side_effect* peut être soit une classe, soit une instance d'exception. Dans "
"ce cas, l'exception est levée lors de l'appel de l'objet simulacre."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:256
2016-10-30 09:46:26 +00:00
msgid ""
"If *side_effect* is an iterable then each call to the mock will return the "
"next value from the iterable."
msgstr ""
"Si *side_effect* est un itérable alors chaque appel au *mock* renvoie la "
"valeur suivante de litérable."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:259
2016-10-30 09:46:26 +00:00
msgid "A *side_effect* can be cleared by setting it to ``None``."
msgstr "Utilisez ``None`` pour remettre à zéro un *side_effect*."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:261
2016-10-30 09:46:26 +00:00
msgid ""
"*return_value*: The value returned when the mock is called. By default this "
"is a new Mock (created on first access). See the :attr:`return_value` "
"attribute."
msgstr ""
"*return_value* : valeur renvoyée lors de l'appel de l'objet simulacre. Par "
"défaut, il s'agit d'un nouveau *Mock* (créé lors du premier accès). Voir "
"l'attribut :attr:`return_value`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:265
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
2022-03-23 17:40:12 +00:00
"*unsafe*: By default, accessing any attribute whose name starts with "
"*assert*, *assret*, *asert*, *aseert* or *assrt* will raise an :exc:"
"`AttributeError`. Passing ``unsafe=True`` will allow access to these "
"attributes."
2016-10-30 09:46:26 +00:00
msgstr ""
"*unsafe* : par défaut, si un attribut commence par *assert* ou *assret*, une "
"exception :exc:`AttributeError` est levée. Le fait de passer ``unsafe=True`` "
"permet d'accéder à ces attributs."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:272
2016-10-30 09:46:26 +00:00
msgid ""
"*wraps*: Item for the mock object to wrap. If *wraps* is not ``None`` then "
"calling the Mock will pass the call through to the wrapped object (returning "
"the real result). Attribute access on the mock will return a Mock object "
"that wraps the corresponding attribute of the wrapped object (so attempting "
"to access an attribute that doesn't exist will raise an :exc:"
"`AttributeError`)."
msgstr ""
"*wraps* : élément que le simulacre doit simuler. Si *wraps* n'est pas "
"``None`` alors appeler *Mock* passe l'appel à l'objet simulé (renvoyant le "
"résultat réel). L'accès à un attribut sur le *mock* renvoie un objet *Mock* "
"qui simule l'attribut correspondant de l'objet simulé (donc essayer "
"d'accéder à un attribut qui n'existe pas lève une exception :exc:"
"`AttributeError`)."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:279
2016-10-30 09:46:26 +00:00
msgid ""
"If the mock has an explicit *return_value* set then calls are not passed to "
"the wrapped object and the *return_value* is returned instead."
msgstr ""
"Si l'objet simulacre a un ensemble explicite de *return_value* alors les "
"appels ne sont pas passés à l'objet simulé et c'est *return_value* qui est "
"renvoyée à la place."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:282
2016-10-30 09:46:26 +00:00
msgid ""
"*name*: If the mock has a name then it will be used in the repr of the mock. "
"This can be useful for debugging. The name is propagated to child mocks."
msgstr ""
"*name* : Si le *mock* a un nom, il est alors utilisé par la fonction *repr* "
"du *mock*. C'est utile pour le débogage. Le nom est propagé aux enfants de "
"l'objet *mock*."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:286
2016-10-30 09:46:26 +00:00
msgid ""
"Mocks can also be called with arbitrary keyword arguments. These will be "
"used to set attributes on the mock after it is created. See the :meth:"
"`configure_mock` method for details."
msgstr ""
"Les *mocks* peuvent aussi être appelés avec des arguments par mots-clés "
"arbitraires. Ceux-ci sont utilisés pour définir les attributs sur le *mock* "
"après sa création. Voir la méthode :meth:`configure_mock` pour plus de "
"détails."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:292
2016-10-30 09:46:26 +00:00
msgid "Assert that the mock was called at least once."
msgstr "Asserter que le *mock* a été appelé au moins une fois."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:303
2016-10-30 09:46:26 +00:00
msgid "Assert that the mock was called exactly once."
msgstr "Asserter que le *mock* a été appelé exactement une fois."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:321
2019-09-04 09:35:23 +00:00
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
2019-09-04 09:35:23 +00:00
"This method is a convenient way of asserting that the last call has been "
"made in a particular way:"
2016-10-30 09:46:26 +00:00
msgstr ""
"Cette méthode est un moyen pratique d'asserter que les appels sont effectués "
"d'une manière particulière :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:331
2021-06-04 11:47:25 +00:00
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
2021-06-04 11:47:25 +00:00
"Assert that the mock was called exactly once and that call was with the "
2017-04-02 20:14:06 +00:00
"specified arguments."
2016-10-30 09:46:26 +00:00
msgstr ""
"Asserter que le simulacre a été appelé exactement une fois et que cet appel "
"était avec les arguments spécifiés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:346
2016-10-30 09:46:26 +00:00
msgid "assert the mock has been called with the specified arguments."
msgstr "Asserter que le simulacre a été appelé avec les arguments spécifiés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:348
2016-10-30 09:46:26 +00:00
msgid ""
"The assert passes if the mock has *ever* been called, unlike :meth:"
"`assert_called_with` and :meth:`assert_called_once_with` that only pass if "
2017-04-02 20:14:06 +00:00
"the call is the most recent one, and in the case of :meth:"
"`assert_called_once_with` it must also be the only call."
2016-10-30 09:46:26 +00:00
msgstr ""
"Asserter que le simulacre a *bien* été appelé avec les arguments au cours de "
"la vie du simulacre. Contrairement à :meth:`assert_called_with` et :meth:"
"`assert_called_once_with` qui passent seulement si l'appel demandé "
"correspond bien au dernier appel, et dans le cas de :meth:"
"`assert_called_once_with` l'appel au simulacre doit être unique."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:361
2016-10-30 09:46:26 +00:00
msgid ""
"assert the mock has been called with the specified calls. The :attr:"
"`mock_calls` list is checked for the calls."
msgstr ""
"Asserter que le simulacre a été appelé avec les appels spécifiés. "
"L'attribut :attr:`mock_calls` est comparé à la liste des appels."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:364
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"If *any_order* is false then the calls must be sequential. There can be "
"extra calls before or after the specified calls."
2016-10-30 09:46:26 +00:00
msgstr ""
"Si *any_order* est faux (la valeur par défaut) alors les appels doivent être "
"séquentiels. Il peut y avoir des appels supplémentaires avant ou après les "
"appels spécifiés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:368
2016-10-30 09:46:26 +00:00
msgid ""
"If *any_order* is true then the calls can be in any order, but they must all "
"appear in :attr:`mock_calls`."
msgstr ""
"Si *any_order* est vrai alors les appels peuvent être dans n'importe quel "
"ordre, mais ils doivent tous apparaître dans :attr:`mock_calls`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:383
2016-10-30 09:46:26 +00:00
msgid "Assert the mock was never called."
msgstr "Asserter que le simulacre n'a jamais été appelé."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:398
2016-10-30 09:46:26 +00:00
msgid "The reset_mock method resets all the call attributes on a mock object:"
msgstr ""
"La méthode *reset_mock* réinitialise tous les attributs d'appel sur un "
"simulacre :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:408
2023-04-14 11:20:40 +00:00
#, fuzzy
msgid "Added two keyword-only arguments to the reset_mock function."
msgstr "Ajout de deux arguments nommés à la fonction *reset_mock*."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:411
2016-10-30 09:46:26 +00:00
msgid ""
"This can be useful where you want to make a series of assertions that reuse "
"the same object. Note that :meth:`reset_mock` *doesn't* clear the return "
"value, :attr:`side_effect` or any child attributes you have set using normal "
"assignment by default. In case you want to reset *return_value* or :attr:"
"`side_effect`, then pass the corresponding parameter as ``True``. Child "
"mocks and the return value mock (if any) are reset as well."
msgstr ""
"Utile pour faire une série d'assertions qui réutilisent le même objet. "
"Attention :meth:`reset_mock` *ne réinitialise pas* la valeur de retour, les :"
"attr:`side_effect` ou tout attribut enfant que vous avez défini en utilisant "
"l'affectation normale par défaut. Pour réinitialiser *return_value* ou :attr:"
"`side_effect`, utiliser les paramètres correspondants avec la valeur "
"``True``. Les simulacres enfants et le simulacre de valeur de retour (le cas "
"échéant) seront également réinitialisés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:419
2023-04-14 11:20:40 +00:00
#, fuzzy
msgid "*return_value*, and :attr:`side_effect` are keyword-only arguments."
2016-10-30 09:46:26 +00:00
msgstr ""
"*return_value*, et :attr:`side_effect` sont utilisable uniquement par "
"arguments nommés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:425
2016-10-30 09:46:26 +00:00
msgid ""
"Add a spec to a mock. *spec* can either be an object or a list of strings. "
"Only attributes on the *spec* can be fetched as attributes from the mock."
msgstr ""
"Ajoute une spécification à un simulacre. *spec* peut être un objet ou une "
"liste de chaînes de caractères. Seuls les attributs de la spécification "
"*spec* peuvent être récupérés en tant qu'attributs du simulacre."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:429
2016-10-30 09:46:26 +00:00
msgid "If *spec_set* is true then only attributes on the spec can be set."
msgstr ""
"Si *spec_set* est vrai, seuls les attributs de la spécification peuvent être "
"définis."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:434
2016-10-30 09:46:26 +00:00
msgid ""
"Attach a mock as an attribute of this one, replacing its name and parent. "
"Calls to the attached mock will be recorded in the :attr:`method_calls` and :"
"attr:`mock_calls` attributes of this one."
msgstr ""
"Attache un simulacre comme attribut de l'instance courante, en remplaçant "
"son nom et son parent. Les appels au simulacre attaché sont enregistrés dans "
"les attributs :attr:`method_calls` et :attr:`mock_calls` de l'instance "
"courante."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:441
2016-10-30 09:46:26 +00:00
msgid "Set attributes on the mock through keyword arguments."
msgstr "Définir les attributs sur le simulacre à l'aide d'arguments nommés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:443
2016-10-30 09:46:26 +00:00
msgid ""
"Attributes plus return values and side effects can be set on child mocks "
"using standard dot notation and unpacking a dictionary in the method call:"
msgstr ""
"Les attributs, les valeurs de retour et les effets de bords peuvent être "
"définis sur des simulacres enfants en utilisant la notation par points "
"standard et en dépaquetant un dictionnaire dans l'appel de méthode :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:457
2016-10-30 09:46:26 +00:00
msgid "The same thing can be achieved in the constructor call to mocks:"
msgstr ""
"La même chose peut être réalisée en utilisant le constructeur des "
"simulacres :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:470
2016-10-30 09:46:26 +00:00
msgid ""
":meth:`configure_mock` exists to make it easier to do configuration after "
"the mock has been created."
msgstr ""
":meth:`configure_mock` existe pour faciliter la configuration après la "
"création du simulacre."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:476
2016-10-30 09:46:26 +00:00
msgid ""
":class:`Mock` objects limit the results of ``dir(some_mock)`` to useful "
"results. For mocks with a *spec* this includes all the permitted attributes "
"for the mock."
msgstr ""
"Les objets :class:`Mock` limitent les résultats de ``dir(un_mock)`` à des "
"résultats utiles. Pour les simulacres avec une spécification *spec*, cela "
"inclut tous les attributs autorisés du simulacre."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:480
2016-10-30 09:46:26 +00:00
msgid ""
"See :data:`FILTER_DIR` for what this filtering does, and how to switch it "
"off."
msgstr ""
"Voir :data:`FILTER_DIR` pour savoir ce que fait ce filtrage, et comment le "
"désactiver."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:486
2016-10-30 09:46:26 +00:00
msgid ""
"Create the child mocks for attributes and return value. By default child "
"mocks will be the same type as the parent. Subclasses of Mock may want to "
"override this to customize the way child mocks are made."
msgstr ""
"Crée les simulacres enfants pour les attributs et la valeur de retour. Par "
"défaut, les objets simulacre enfants sont du même type que le parent. Les "
"sous-classes de *Mock* peuvent surcharger cette méthode pour personnaliser "
"la façon dont les simulacres enfants sont créés."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:491
2016-10-30 09:46:26 +00:00
msgid ""
"For non-callable mocks the callable variant will be used (rather than any "
"custom subclass)."
msgstr ""
"Pour les simulacres non appelables, la variante appelable est utilisée "
"(plutôt qu'une sous-classe personnalisée)."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:497
2016-10-30 09:46:26 +00:00
msgid "A boolean representing whether or not the mock object has been called:"
msgstr "Un booléen représentant si le simulacre a bien été appelé ou non :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:508
2016-10-30 09:46:26 +00:00
msgid "An integer telling you how many times the mock object has been called:"
msgstr "Un entier indiquant combien de fois le simulacre a été appelé :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:520
2016-10-30 09:46:26 +00:00
msgid "Set this to configure the value returned by calling the mock:"
msgstr ""
"Définir cette option pour configurer la valeur renvoyé par appel du "
"simulacre :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:527
2016-10-30 09:46:26 +00:00
msgid ""
"The default return value is a mock object and you can configure it in the "
"normal way:"
msgstr ""
"La valeur de revoie par défaut est un simulacre configurable normalement :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:536
2016-10-30 09:46:26 +00:00
msgid ":attr:`return_value` can also be set in the constructor:"
msgstr ""
"L'attribut :attr:`return_value` peut également être défini dans le "
"constructeur :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:547
2016-10-30 09:46:26 +00:00
msgid ""
"This can either be a function to be called when the mock is called, an "
"iterable or an exception (class or instance) to be raised."
msgstr ""
"C'est soit une fonction à appeler lors de l'appel du simulacre, soit une "
"exception (classe ou instance) à lever."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:550
2016-10-30 09:46:26 +00:00
msgid ""
"If you pass in a function it will be called with same arguments as the mock "
"and unless the function returns the :data:`DEFAULT` singleton the call to "
"the mock will then return whatever the function returns. If the function "
"returns :data:`DEFAULT` then the mock will return its normal value (from "
"the :attr:`return_value`)."
msgstr ""
"Si vous passez une fonction, elle est appelée avec les mêmes arguments que "
"la fonction simulée et à moins que la fonction ne renvoie le singleton :data:"
"`DEFAULT` l'appel le la fonction simulée renvoie ce que la fonction renvoie. "
"Si la fonction renvoie :data:`DEFAULT` alors le simulacre renvoie sa valeur "
"normale (celle de :attr:`return_value`)."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:556
2016-10-30 09:46:26 +00:00
msgid ""
"If you pass in an iterable, it is used to retrieve an iterator which must "
"yield a value on every call. This value can either be an exception instance "
"to be raised, or a value to be returned from the call to the mock (:data:"
"`DEFAULT` handling is identical to the function case)."
msgstr ""
"Si vous passez un itérable, il est utilisé pour récupérer un itérateur qui "
"doit renvoyer une valeur à chaque appel. Cette valeur peut être soit une "
"instance d'exception à lever, soit une valeur à renvoyer à l'appel au "
"simulacre (le traitement :data:`DEFAULT` est identique au renvoie de la "
"fonction simulée)."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:561
2016-10-30 09:46:26 +00:00
msgid ""
"An example of a mock that raises an exception (to test exception handling of "
"an API):"
msgstr ""
"Un exemple d'un simulacre qui lève une exception (pour tester la gestion des "
"exceptions d'une API) :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:571
2016-10-30 09:46:26 +00:00
msgid "Using :attr:`side_effect` to return a sequence of values:"
msgstr "Utiliser :attr:`side_effect` pour renvoyer une séquence de valeurs :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:578
2016-10-30 09:46:26 +00:00
msgid "Using a callable:"
msgstr "Utilisation d'un objet appelable :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:588
2016-10-30 09:46:26 +00:00
msgid ""
":attr:`side_effect` can be set in the constructor. Here's an example that "
"adds one to the value the mock is called with and returns it:"
msgstr ""
"Un attribut :attr:`side_effect` peut être défini dans le constructeur. Voici "
"un exemple qui ajoute un à la valeur du simulacre appelé et qui le renvoie :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:598
2016-10-30 09:46:26 +00:00
msgid "Setting :attr:`side_effect` to ``None`` clears it:"
msgstr "Positionner :attr:`side_effect` sur ``None`` l'efface :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:612
2019-09-04 09:35:23 +00:00
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
"This is either ``None`` (if the mock hasn't been called), or the arguments "
"that the mock was last called with. This will be in the form of a tuple: the "
2019-09-04 09:35:23 +00:00
"first member, which can also be accessed through the ``args`` property, is "
"any ordered arguments the mock was called with (or an empty tuple) and the "
"second member, which can also be accessed through the ``kwargs`` property, "
"is any keyword arguments (or an empty dictionary)."
2016-10-30 09:46:26 +00:00
msgstr ""
"C'est soit ``None`` (si le simulacre n'a pas été appelé), soit les arguments "
"avec lesquels le simulacre a été appelé en dernier. Le retour est sous la "
"forme d'un *n*-uplet : le premier élément est l'ensemble des arguments "
"ordonnés avec lequel le simulacre a été appelé (ou un *n*-uplet vide) et le "
"second élément est l'ensemble des arguments nommés (ou un dictionnaire vide)."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:645
2016-10-30 09:46:26 +00:00
msgid ""
":attr:`call_args`, along with members of the lists :attr:`call_args_list`, :"
"attr:`method_calls` and :attr:`mock_calls` are :data:`call` objects. These "
"are tuples, so they can be unpacked to get at the individual arguments and "
"make more complex assertions. See :ref:`calls as tuples <calls-as-tuples>`."
msgstr ""
"L'attribut :attr:`call_args`, ainsi que les éléments des listes :attr:"
"`call_args_list`, :attr:`method_calls` et :attr:`mock_calls` sont des "
"objets :data:`call`. Ce sont des *n*-uplets, que l'on peut dépaqueter afin "
"de faire des affirmations plus complexes sur chacun des arguments. Voir :ref:"
"`appels comme *n*-uplets <calls-as-tuples>`."
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:651
2020-09-11 07:11:46 +00:00
msgid "Added ``args`` and ``kwargs`` properties."
msgstr ""
#: library/unittest.mock.rst:657
2016-10-30 09:46:26 +00:00
msgid ""
"This is a list of all the calls made to the mock object in sequence (so the "
"length of the list is the number of times it has been called). Before any "
"calls have been made it is an empty list. The :data:`call` object can be "
"used for conveniently constructing lists of calls to compare with :attr:"
"`call_args_list`."
msgstr ""
#: library/unittest.mock.rst:673
2016-10-30 09:46:26 +00:00
msgid ""
"Members of :attr:`call_args_list` are :data:`call` objects. These can be "
"unpacked as tuples to get at the individual arguments. See :ref:`calls as "
"tuples <calls-as-tuples>`."
msgstr ""
#: library/unittest.mock.rst:680
2016-10-30 09:46:26 +00:00
msgid ""
"As well as tracking calls to themselves, mocks also track calls to methods "
"and attributes, and *their* methods and attributes:"
msgstr ""
#: library/unittest.mock.rst:691
2016-10-30 09:46:26 +00:00
msgid ""
"Members of :attr:`method_calls` are :data:`call` objects. These can be "
"unpacked as tuples to get at the individual arguments. See :ref:`calls as "
"tuples <calls-as-tuples>`."
msgstr ""
#: library/unittest.mock.rst:698
2016-10-30 09:46:26 +00:00
msgid ""
":attr:`mock_calls` records *all* calls to the mock object, its methods, "
"magic methods *and* return value mocks."
msgstr ""
#: library/unittest.mock.rst:716
2016-10-30 09:46:26 +00:00
msgid ""
"Members of :attr:`mock_calls` are :data:`call` objects. These can be "
"unpacked as tuples to get at the individual arguments. See :ref:`calls as "
"tuples <calls-as-tuples>`."
msgstr ""
#: library/unittest.mock.rst:722
2018-12-24 13:20:55 +00:00
msgid ""
"The way :attr:`mock_calls` are recorded means that where nested calls are "
"made, the parameters of ancestor calls are not recorded and so will always "
"compare equal:"
msgstr ""
#: library/unittest.mock.rst:736
2016-10-30 09:46:26 +00:00
msgid ""
"Normally the :attr:`__class__` attribute of an object will return its type. "
"For a mock object with a :attr:`spec`, ``__class__`` returns the spec class "
"instead. This allows mock objects to pass :func:`isinstance` tests for the "
"object they are replacing / masquerading as:"
msgstr ""
#: library/unittest.mock.rst:745
2016-10-30 09:46:26 +00:00
msgid ""
":attr:`__class__` is assignable to, this allows a mock to pass an :func:"
"`isinstance` check without forcing you to use a spec:"
msgstr ""
#: library/unittest.mock.rst:755
2016-10-30 09:46:26 +00:00
msgid ""
"A non-callable version of :class:`Mock`. The constructor parameters have the "
"same meaning of :class:`Mock`, with the exception of *return_value* and "
"*side_effect* which have no meaning on a non-callable mock."
msgstr ""
#: library/unittest.mock.rst:759
2016-10-30 09:46:26 +00:00
msgid ""
"Mock objects that use a class or an instance as a :attr:`spec` or :attr:"
"`spec_set` are able to pass :func:`isinstance` tests:"
msgstr ""
#: library/unittest.mock.rst:769
2016-10-30 09:46:26 +00:00
msgid ""
"The :class:`Mock` classes have support for mocking magic methods. See :ref:"
"`magic methods <magic-methods>` for the full details."
msgstr ""
#: library/unittest.mock.rst:772
2016-10-30 09:46:26 +00:00
msgid ""
"The mock classes and the :func:`patch` decorators all take arbitrary keyword "
"arguments for configuration. For the :func:`patch` decorators the keywords "
"are passed to the constructor of the mock being created. The keyword "
"arguments are for configuring attributes of the mock:"
msgstr ""
#: library/unittest.mock.rst:783
2016-10-30 09:46:26 +00:00
msgid ""
"The return value and side effect of child mocks can be set in the same way, "
"using dotted notation. As you can't use dotted names directly in a call you "
"have to create a dictionary and unpack it using ``**``:"
msgstr ""
#: library/unittest.mock.rst:798
2016-10-30 09:46:26 +00:00
msgid ""
"A callable mock which was created with a *spec* (or a *spec_set*) will "
"introspect the specification object's signature when matching calls to the "
"mock. Therefore, it can match the actual call's arguments regardless of "
"whether they were passed positionally or by name::"
msgstr ""
#: library/unittest.mock.rst:811
2016-10-30 09:46:26 +00:00
msgid ""
"This applies to :meth:`~Mock.assert_called_with`, :meth:`~Mock."
"assert_called_once_with`, :meth:`~Mock.assert_has_calls` and :meth:`~Mock."
"assert_any_call`. When :ref:`auto-speccing`, it will also apply to method "
"calls on the mock object."
msgstr ""
#: library/unittest.mock.rst:816
2016-10-30 09:46:26 +00:00
msgid "Added signature introspection on specced and autospecced mock objects."
msgstr ""
#: library/unittest.mock.rst:822
2016-10-30 09:46:26 +00:00
msgid ""
"A mock intended to be used as a property, or other descriptor, on a class. :"
"class:`PropertyMock` provides :meth:`__get__` and :meth:`__set__` methods so "
"you can specify a return value when it is fetched."
msgstr ""
#: library/unittest.mock.rst:826
2016-10-30 09:46:26 +00:00
msgid ""
"Fetching a :class:`PropertyMock` instance from an object calls the mock, "
2019-09-04 09:35:23 +00:00
"with no args. Setting it calls the mock with the value being set. ::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:847
2016-10-30 09:46:26 +00:00
msgid ""
"Because of the way mock attributes are stored you can't directly attach a :"
"class:`PropertyMock` to a mock object. Instead you can attach it to the mock "
"type object::"
msgstr ""
#: library/unittest.mock.rst:861
2019-09-04 09:35:23 +00:00
msgid ""
2020-07-20 08:56:42 +00:00
"An asynchronous version of :class:`MagicMock`. The :class:`AsyncMock` object "
"will behave so the object is recognized as an async function, and the result "
"of a call is an awaitable."
2019-09-04 09:35:23 +00:00
msgstr ""
#: library/unittest.mock.rst:871
2019-09-04 09:35:23 +00:00
msgid ""
"The result of ``mock()`` is an async function which will have the outcome of "
2019-10-09 16:10:12 +00:00
"``side_effect`` or ``return_value`` after it has been awaited:"
2019-09-04 09:35:23 +00:00
msgstr ""
#: library/unittest.mock.rst:874
2019-09-04 09:35:23 +00:00
msgid ""
"if ``side_effect`` is a function, the async function will return the result "
"of that function,"
msgstr ""
#: library/unittest.mock.rst:876
2019-09-04 09:35:23 +00:00
msgid ""
"if ``side_effect`` is an exception, the async function will raise the "
"exception,"
msgstr ""
#: library/unittest.mock.rst:878
2019-09-04 09:35:23 +00:00
msgid ""
"if ``side_effect`` is an iterable, the async function will return the next "
"value of the iterable, however, if the sequence of result is exhausted, "
2019-12-05 22:41:32 +00:00
"``StopAsyncIteration`` is raised immediately,"
2019-09-04 09:35:23 +00:00
msgstr ""
#: library/unittest.mock.rst:881
2019-09-04 09:35:23 +00:00
msgid ""
"if ``side_effect`` is not defined, the async function will return the value "
"defined by ``return_value``, hence, by default, the async function returns a "
"new :class:`AsyncMock` object."
msgstr ""
#: library/unittest.mock.rst:886
2019-09-04 09:35:23 +00:00
msgid ""
"Setting the *spec* of a :class:`Mock` or :class:`MagicMock` to an async "
"function will result in a coroutine object being returned after calling."
msgstr ""
#: library/unittest.mock.rst:898
2019-10-09 16:10:12 +00:00
msgid ""
"Setting the *spec* of a :class:`Mock`, :class:`MagicMock`, or :class:"
"`AsyncMock` to a class with asynchronous and synchronous functions will "
"automatically detect the synchronous functions and set them as :class:"
"`MagicMock` (if the parent mock is :class:`AsyncMock` or :class:`MagicMock`) "
"or :class:`Mock` (if the parent mock is :class:`Mock`). All asynchronous "
"functions will be :class:`AsyncMock`."
msgstr ""
#: library/unittest.mock.rst:926
2019-10-09 16:10:12 +00:00
msgid ""
"Assert that the mock was awaited at least once. Note that this is separate "
"from the object having been called, the ``await`` keyword must be used:"
msgstr ""
2019-09-04 09:35:23 +00:00
#: library/unittest.mock.rst:945
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid "Assert that the mock was awaited exactly once."
msgstr "Asserter que le *mock* a été appelé exactement une fois."
#: library/unittest.mock.rst:961
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid "Assert that the last await was with the specified arguments."
msgstr "Asserter que le simulacre a été appelé avec les arguments spécifiés."
#: library/unittest.mock.rst:978
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid ""
"Assert that the mock was awaited exactly once and with the specified "
"arguments."
msgstr ""
"Asserter que le simulacre a été appelé exactement une fois et que cet appel "
"était avec les arguments spécifiés."
#: library/unittest.mock.rst:995
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid "Assert the mock has ever been awaited with the specified arguments."
msgstr "Asserter que le simulacre a été appelé avec les arguments spécifiés."
#: library/unittest.mock.rst:1011
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid ""
"Assert the mock has been awaited with the specified calls. The :attr:"
"`await_args_list` list is checked for the awaits."
msgstr ""
"Asserter que le simulacre a été appelé avec les appels spécifiés. "
"L'attribut :attr:`mock_calls` est comparé à la liste des appels."
#: library/unittest.mock.rst:1014
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid ""
"If *any_order* is false then the awaits must be sequential. There can be "
"extra calls before or after the specified awaits."
2019-09-04 09:35:23 +00:00
msgstr ""
"Si *any_order* est faux (la valeur par défaut) alors les appels doivent être "
"séquentiels. Il peut y avoir des appels supplémentaires avant ou après les "
"appels spécifiés."
#: library/unittest.mock.rst:1018
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid ""
"If *any_order* is true then the awaits can be in any order, but they must "
2019-09-04 09:35:23 +00:00
"all appear in :attr:`await_args_list`."
msgstr ""
"Si *any_order* est vrai alors les appels peuvent être dans n'importe quel "
"ordre, mais ils doivent tous apparaître dans :attr:`mock_calls`."
#: library/unittest.mock.rst:1038
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid "Assert that the mock was never awaited."
msgstr "Asserter que le simulacre n'a jamais été appelé."
#: library/unittest.mock.rst:1045
2019-09-04 09:35:23 +00:00
msgid ""
"See :func:`Mock.reset_mock`. Also sets :attr:`await_count` to 0, :attr:"
"`await_args` to None, and clears the :attr:`await_args_list`."
msgstr ""
#: library/unittest.mock.rst:1050
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid ""
"An integer keeping track of how many times the mock object has been awaited."
msgstr "Un entier indiquant combien de fois le simulacre a été appelé :"
#: library/unittest.mock.rst:1065
2019-09-04 09:35:23 +00:00
msgid ""
"This is either ``None`` (if the mock hasnt been awaited), or the arguments "
"that the mock was last awaited with. Functions the same as :attr:`Mock."
"call_args`."
msgstr ""
#: library/unittest.mock.rst:1083
2019-09-04 09:35:23 +00:00
msgid ""
"This is a list of all the awaits made to the mock object in sequence (so the "
"length of the list is the number of times it has been awaited). Before any "
"awaits have been made it is an empty list."
msgstr ""
#: library/unittest.mock.rst:1102
2016-10-30 09:46:26 +00:00
msgid "Calling"
msgstr ""
#: library/unittest.mock.rst:1104
2016-10-30 09:46:26 +00:00
msgid ""
"Mock objects are callable. The call will return the value set as the :attr:"
"`~Mock.return_value` attribute. The default return value is a new Mock "
"object; it is created the first time the return value is accessed (either "
"explicitly or by calling the Mock) - but it is stored and the same one "
"returned each time."
msgstr ""
#: library/unittest.mock.rst:1110
2016-10-30 09:46:26 +00:00
msgid ""
"Calls made to the object will be recorded in the attributes like :attr:"
"`~Mock.call_args` and :attr:`~Mock.call_args_list`."
msgstr ""
#: library/unittest.mock.rst:1113
2016-10-30 09:46:26 +00:00
msgid ""
"If :attr:`~Mock.side_effect` is set then it will be called after the call "
"has been recorded, so if :attr:`side_effect` raises an exception the call is "
"still recorded."
msgstr ""
#: library/unittest.mock.rst:1117
2016-10-30 09:46:26 +00:00
msgid ""
"The simplest way to make a mock raise an exception when called is to make :"
"attr:`~Mock.side_effect` an exception class or instance:"
msgstr ""
#: library/unittest.mock.rst:1135
2016-10-30 09:46:26 +00:00
msgid ""
"If :attr:`side_effect` is a function then whatever that function returns is "
"what calls to the mock return. The :attr:`side_effect` function is called "
"with the same arguments as the mock. This allows you to vary the return "
"value of the call dynamically, based on the input:"
msgstr ""
#: library/unittest.mock.rst:1151
2016-10-30 09:46:26 +00:00
msgid ""
"If you want the mock to still return the default return value (a new mock), "
"or any set return value, then there are two ways of doing this. Either "
"return :attr:`mock.return_value` from inside :attr:`side_effect`, or return :"
"data:`DEFAULT`:"
msgstr ""
#: library/unittest.mock.rst:1170
2016-10-30 09:46:26 +00:00
msgid ""
"To remove a :attr:`side_effect`, and return to the default behaviour, set "
"the :attr:`side_effect` to ``None``:"
msgstr ""
#: library/unittest.mock.rst:1184
2016-10-30 09:46:26 +00:00
msgid ""
"The :attr:`side_effect` can also be any iterable object. Repeated calls to "
"the mock will return values from the iterable (until the iterable is "
"exhausted and a :exc:`StopIteration` is raised):"
msgstr ""
#: library/unittest.mock.rst:1200
2016-10-30 09:46:26 +00:00
msgid ""
"If any members of the iterable are exceptions they will be raised instead of "
"returned::"
msgstr ""
#: library/unittest.mock.rst:1218
2016-10-30 09:46:26 +00:00
msgid "Deleting Attributes"
msgstr ""
#: library/unittest.mock.rst:1220
2016-10-30 09:46:26 +00:00
msgid ""
"Mock objects create attributes on demand. This allows them to pretend to be "
"objects of any type."
msgstr ""
#: library/unittest.mock.rst:1223
2016-10-30 09:46:26 +00:00
msgid ""
"You may want a mock object to return ``False`` to a :func:`hasattr` call, or "
"raise an :exc:`AttributeError` when an attribute is fetched. You can do this "
"by providing an object as a :attr:`spec` for a mock, but that isn't always "
"convenient."
msgstr ""
#: library/unittest.mock.rst:1227
2016-10-30 09:46:26 +00:00
msgid ""
"You \"block\" attributes by deleting them. Once deleted, accessing an "
"attribute will raise an :exc:`AttributeError`."
msgstr ""
#: library/unittest.mock.rst:1244
2016-10-30 09:46:26 +00:00
msgid "Mock names and the name attribute"
msgstr ""
#: library/unittest.mock.rst:1246
2016-10-30 09:46:26 +00:00
msgid ""
"Since \"name\" is an argument to the :class:`Mock` constructor, if you want "
"your mock object to have a \"name\" attribute you can't just pass it in at "
"creation time. There are two alternatives. One option is to use :meth:`~Mock."
"configure_mock`::"
msgstr ""
#: library/unittest.mock.rst:1256
2016-10-30 09:46:26 +00:00
msgid ""
"A simpler option is to simply set the \"name\" attribute after mock "
"creation::"
msgstr ""
#: library/unittest.mock.rst:1263
2016-10-30 09:46:26 +00:00
msgid "Attaching Mocks as Attributes"
msgstr ""
#: library/unittest.mock.rst:1265
2016-10-30 09:46:26 +00:00
msgid ""
"When you attach a mock as an attribute of another mock (or as the return "
"value) it becomes a \"child\" of that mock. Calls to the child are recorded "
"in the :attr:`~Mock.method_calls` and :attr:`~Mock.mock_calls` attributes of "
"the parent. This is useful for configuring child mocks and then attaching "
"them to the parent, or for attaching mocks to a parent that records all "
"calls to the children and allows you to make assertions about the order of "
"calls between mocks:"
msgstr ""
#: library/unittest.mock.rst:1283
2016-10-30 09:46:26 +00:00
msgid ""
"The exception to this is if the mock has a name. This allows you to prevent "
"the \"parenting\" if for some reason you don't want it to happen."
msgstr ""
#: library/unittest.mock.rst:1294
2016-10-30 09:46:26 +00:00
msgid ""
"Mocks created for you by :func:`patch` are automatically given names. To "
"attach mocks that have names to a parent you use the :meth:`~Mock."
2019-09-04 09:35:23 +00:00
"attach_mock` method::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1312
2016-10-30 09:46:26 +00:00
msgid ""
"The only exceptions are magic methods and attributes (those that have "
"leading and trailing double underscores). Mock doesn't create these but "
"instead raises an :exc:`AttributeError`. This is because the interpreter "
"will often implicitly request these methods, and gets *very* confused to get "
"a new Mock object when it expects a magic method. If you need magic method "
"support see :ref:`magic methods <magic-methods>`."
msgstr ""
#: library/unittest.mock.rst:1321
2016-10-30 09:46:26 +00:00
msgid "The patchers"
msgstr ""
#: library/unittest.mock.rst:1323
2016-10-30 09:46:26 +00:00
msgid ""
"The patch decorators are used for patching objects only within the scope of "
"the function they decorate. They automatically handle the unpatching for "
"you, even if exceptions are raised. All of these functions can also be used "
"in with statements or as class decorators."
msgstr ""
#: library/unittest.mock.rst:1330
2016-10-30 09:46:26 +00:00
msgid "patch"
msgstr ""
#: library/unittest.mock.rst:1334
2016-10-30 09:46:26 +00:00
msgid ""
2020-07-20 08:56:42 +00:00
"The key is to do the patching in the right namespace. See the section `where "
"to patch`_."
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1338
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch` acts as a function decorator, class decorator or a context "
"manager. Inside the body of the function or with statement, the *target* is "
"patched with a *new* object. When the function/with statement exits the "
"patch is undone."
msgstr ""
#: library/unittest.mock.rst:1343
2016-10-30 09:46:26 +00:00
msgid ""
2019-10-09 16:10:12 +00:00
"If *new* is omitted, then the target is replaced with an :class:`AsyncMock` "
"if the patched object is an async function or a :class:`MagicMock` "
"otherwise. If :func:`patch` is used as a decorator and *new* is omitted, the "
"created mock is passed in as an extra argument to the decorated function. "
"If :func:`patch` is used as a context manager the created mock is returned "
"by the context manager."
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1351
2016-10-30 09:46:26 +00:00
msgid ""
"*target* should be a string in the form ``'package.module.ClassName'``. The "
"*target* is imported and the specified object replaced with the *new* "
"object, so the *target* must be importable from the environment you are "
"calling :func:`patch` from. The target is imported when the decorated "
"function is executed, not at decoration time."
msgstr ""
#: library/unittest.mock.rst:1357
2016-10-30 09:46:26 +00:00
msgid ""
"The *spec* and *spec_set* keyword arguments are passed to the :class:"
"`MagicMock` if patch is creating one for you."
msgstr ""
#: library/unittest.mock.rst:1360
2016-10-30 09:46:26 +00:00
msgid ""
"In addition you can pass ``spec=True`` or ``spec_set=True``, which causes "
"patch to pass in the object being mocked as the spec/spec_set object."
msgstr ""
#: library/unittest.mock.rst:1363
2016-10-30 09:46:26 +00:00
msgid ""
"*new_callable* allows you to specify a different class, or callable object, "
"that will be called to create the *new* object. By default :class:"
2019-10-09 16:10:12 +00:00
"`AsyncMock` is used for async functions and :class:`MagicMock` for the rest."
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1367
2016-10-30 09:46:26 +00:00
msgid ""
"A more powerful form of *spec* is *autospec*. If you set ``autospec=True`` "
"then the mock will be created with a spec from the object being replaced. "
"All attributes of the mock will also have the spec of the corresponding "
"attribute of the object being replaced. Methods and functions being mocked "
"will have their arguments checked and will raise a :exc:`TypeError` if they "
"are called with the wrong signature. For mocks replacing a class, their "
"return value (the 'instance') will have the same spec as the class. See the :"
"func:`create_autospec` function and :ref:`auto-speccing`."
msgstr ""
#: library/unittest.mock.rst:1377
2016-10-30 09:46:26 +00:00
msgid ""
"Instead of ``autospec=True`` you can pass ``autospec=some_object`` to use an "
"arbitrary object as the spec instead of the one being replaced."
msgstr ""
#: library/unittest.mock.rst:1380
2016-10-30 09:46:26 +00:00
msgid ""
"By default :func:`patch` will fail to replace attributes that don't exist. "
"If you pass in ``create=True``, and the attribute doesn't exist, patch will "
"create the attribute for you when the patched function is called, and delete "
2019-03-20 08:02:55 +00:00
"it again after the patched function has exited. This is useful for writing "
"tests against attributes that your production code creates at runtime. It is "
"off by default because it can be dangerous. With it switched on you can "
"write passing tests against APIs that don't actually exist!"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1390
2016-10-30 09:46:26 +00:00
msgid ""
"If you are patching builtins in a module then you don't need to pass "
"``create=True``, it will be added by default."
msgstr ""
#: library/unittest.mock.rst:1394
2016-10-30 09:46:26 +00:00
msgid ""
"Patch can be used as a :class:`TestCase` class decorator. It works by "
"decorating each test method in the class. This reduces the boilerplate code "
"when your test methods share a common patchings set. :func:`patch` finds "
"tests by looking for method names that start with ``patch.TEST_PREFIX``. By "
"default this is ``'test'``, which matches the way :mod:`unittest` finds "
"tests. You can specify an alternative prefix by setting ``patch."
"TEST_PREFIX``."
msgstr ""
#: library/unittest.mock.rst:1401
2016-10-30 09:46:26 +00:00
msgid ""
"Patch can be used as a context manager, with the with statement. Here the "
"patching applies to the indented block after the with statement. If you use "
"\"as\" then the patched object will be bound to the name after the \"as\"; "
"very useful if :func:`patch` is creating a mock object for you."
msgstr ""
#: library/unittest.mock.rst:1406
2016-10-30 09:46:26 +00:00
msgid ""
2020-07-20 08:56:42 +00:00
":func:`patch` takes arbitrary keyword arguments. These will be passed to :"
"class:`AsyncMock` if the patched object is asynchronous, to :class:"
"`MagicMock` otherwise or to *new_callable* if specified."
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1410
2016-10-30 09:46:26 +00:00
msgid ""
"``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are "
"available for alternate use-cases."
msgstr ""
#: library/unittest.mock.rst:1413
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch` as function decorator, creating the mock for you and passing "
2019-09-04 09:35:23 +00:00
"it into the decorated function::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1423
2016-10-30 09:46:26 +00:00
msgid ""
"Patching a class replaces the class with a :class:`MagicMock` *instance*. If "
"the class is instantiated in the code under test then it will be the :attr:"
"`~Mock.return_value` of the mock that will be used."
msgstr ""
#: library/unittest.mock.rst:1427
2016-10-30 09:46:26 +00:00
msgid ""
"If the class is instantiated multiple times you could use :attr:`~Mock."
"side_effect` to return a new mock each time. Alternatively you can set the "
"*return_value* to be anything you want."
msgstr ""
#: library/unittest.mock.rst:1431
2016-10-30 09:46:26 +00:00
msgid ""
"To configure return values on methods of *instances* on the patched class "
2019-09-04 09:35:23 +00:00
"you must do this on the :attr:`return_value`. For example::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1445
2016-10-30 09:46:26 +00:00
msgid ""
"If you use *spec* or *spec_set* and :func:`patch` is replacing a *class*, "
2019-09-04 09:35:23 +00:00
"then the return value of the created mock will have the same spec. ::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1455
2016-10-30 09:46:26 +00:00
msgid ""
"The *new_callable* argument is useful where you want to use an alternative "
"class to the default :class:`MagicMock` for the created mock. For example, "
2019-09-04 09:35:23 +00:00
"if you wanted a :class:`NonCallableMock` to be used::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1468
2016-10-30 09:46:26 +00:00
msgid ""
"Another use case might be to replace an object with an :class:`io.StringIO` "
2019-09-04 09:35:23 +00:00
"instance::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1481
2016-10-30 09:46:26 +00:00
msgid ""
"When :func:`patch` is creating a mock for you, it is common that the first "
"thing you need to do is to configure the mock. Some of that configuration "
"can be done in the call to patch. Any arbitrary keywords you pass into the "
2019-09-04 09:35:23 +00:00
"call will be used to set attributes on the created mock::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1493
2016-10-30 09:46:26 +00:00
msgid ""
"As well as attributes on the created mock attributes, like the :attr:`~Mock."
"return_value` and :attr:`~Mock.side_effect`, of child mocks can also be "
"configured. These aren't syntactically valid to pass in directly as keyword "
"arguments, but a dictionary with these as keys can still be expanded into a :"
2019-09-04 09:35:23 +00:00
"func:`patch` call using ``**``::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1509
2019-03-20 08:02:55 +00:00
msgid ""
"By default, attempting to patch a function in a module (or a method or an "
"attribute in a class) that does not exist will fail with :exc:"
"`AttributeError`::"
msgstr ""
#: library/unittest.mock.rst:1521
2019-03-20 08:02:55 +00:00
msgid ""
"but adding ``create=True`` in the call to :func:`patch` will make the "
"previous example work as expected::"
msgstr ""
#: library/unittest.mock.rst:1532
2019-10-09 16:10:12 +00:00
msgid ""
":func:`patch` now returns an :class:`AsyncMock` if the target is an async "
"function."
msgstr ""
#: library/unittest.mock.rst:1536
2016-10-30 09:46:26 +00:00
msgid "patch.object"
msgstr ""
#: library/unittest.mock.rst:1540
2016-10-30 09:46:26 +00:00
msgid ""
"patch the named member (*attribute*) on an object (*target*) with a mock "
"object."
msgstr ""
#: library/unittest.mock.rst:1543
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch.object` can be used as a decorator, class decorator or a "
"context manager. Arguments *new*, *spec*, *create*, *spec_set*, *autospec* "
"and *new_callable* have the same meaning as for :func:`patch`. Like :func:"
"`patch`, :func:`patch.object` takes arbitrary keyword arguments for "
"configuring the mock object it creates."
msgstr ""
#: library/unittest.mock.rst:1549
2016-10-30 09:46:26 +00:00
msgid ""
"When used as a class decorator :func:`patch.object` honours ``patch."
"TEST_PREFIX`` for choosing which methods to wrap."
msgstr ""
#: library/unittest.mock.rst:1552
2016-10-30 09:46:26 +00:00
msgid ""
"You can either call :func:`patch.object` with three arguments or two "
"arguments. The three argument form takes the object to be patched, the "
"attribute name and the object to replace the attribute with."
msgstr ""
#: library/unittest.mock.rst:1556
2016-10-30 09:46:26 +00:00
msgid ""
"When calling with the two argument form you omit the replacement object, and "
"a mock is created for you and passed in as an extra argument to the "
"decorated function:"
msgstr ""
#: library/unittest.mock.rst:1567
2016-10-30 09:46:26 +00:00
msgid ""
"*spec*, *create* and the other arguments to :func:`patch.object` have the "
"same meaning as they do for :func:`patch`."
msgstr ""
#: library/unittest.mock.rst:1572
2016-10-30 09:46:26 +00:00
msgid "patch.dict"
msgstr ""
#: library/unittest.mock.rst:1576
2016-10-30 09:46:26 +00:00
msgid ""
"Patch a dictionary, or dictionary like object, and restore the dictionary to "
"its original state after the test."
msgstr ""
#: library/unittest.mock.rst:1579
2016-10-30 09:46:26 +00:00
msgid ""
"*in_dict* can be a dictionary or a mapping like container. If it is a "
"mapping then it must at least support getting, setting and deleting items "
"plus iterating over keys."
msgstr ""
#: library/unittest.mock.rst:1583
2016-10-30 09:46:26 +00:00
msgid ""
"*in_dict* can also be a string specifying the name of the dictionary, which "
"will then be fetched by importing it."
msgstr ""
#: library/unittest.mock.rst:1586
2016-10-30 09:46:26 +00:00
msgid ""
"*values* can be a dictionary of values to set in the dictionary. *values* "
"can also be an iterable of ``(key, value)`` pairs."
msgstr ""
#: library/unittest.mock.rst:1589
2016-10-30 09:46:26 +00:00
msgid ""
"If *clear* is true then the dictionary will be cleared before the new values "
"are set."
msgstr ""
#: library/unittest.mock.rst:1592
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch.dict` can also be called with arbitrary keyword arguments to "
"set values in the dictionary."
msgstr ""
#: library/unittest.mock.rst:1597
2019-10-09 16:10:12 +00:00
msgid ""
":func:`patch.dict` now returns the patched dictionary when used as a context "
"manager."
msgstr ""
#: library/unittest.mock.rst:1600
2019-10-09 16:10:12 +00:00
#, fuzzy
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch.dict` can be used as a context manager, decorator or class "
2019-10-09 16:10:12 +00:00
"decorator:"
2016-10-30 09:46:26 +00:00
msgstr ""
2019-10-09 16:10:12 +00:00
"Comme tout décorateur, :func:`patch` peut être utilisé comme gestionnaire de "
"contexte avec une instruction *with* :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:1610
2019-09-04 09:35:23 +00:00
msgid ""
2019-10-09 16:10:12 +00:00
"When used as a class decorator :func:`patch.dict` honours ``patch."
"TEST_PREFIX`` (default to ``'test'``) for choosing which methods to wrap:"
msgstr ""
#: library/unittest.mock.rst:1621
2019-10-09 16:10:12 +00:00
msgid ""
"If you want to use a different prefix for your test, you can inform the "
"patchers of the different prefix by setting ``patch.TEST_PREFIX``. For more "
"details about how to change the value of see :ref:`test-prefix`."
2019-09-04 09:35:23 +00:00
msgstr ""
#: library/unittest.mock.rst:1625
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch.dict` can be used to add members to a dictionary, or simply let "
"a test change a dictionary, and ensure the dictionary is restored when the "
"test ends."
msgstr ""
#: library/unittest.mock.rst:1646
2016-10-30 09:46:26 +00:00
msgid ""
"Keywords can be used in the :func:`patch.dict` call to set values in the "
"dictionary:"
msgstr ""
#: library/unittest.mock.rst:1656
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch.dict` can be used with dictionary like objects that aren't "
"actually dictionaries. At the very minimum they must support item getting, "
"setting, deleting and either iteration or membership test. This corresponds "
"to the magic methods :meth:`__getitem__`, :meth:`__setitem__`, :meth:"
"`__delitem__` and either :meth:`__iter__` or :meth:`__contains__`."
msgstr ""
#: library/unittest.mock.rst:1685
2016-10-30 09:46:26 +00:00
msgid "patch.multiple"
msgstr ""
#: library/unittest.mock.rst:1689
2016-10-30 09:46:26 +00:00
msgid ""
"Perform multiple patches in a single call. It takes the object to be patched "
"(either as an object or a string to fetch the object by importing) and "
"keyword arguments for the patches::"
msgstr ""
#: library/unittest.mock.rst:1696
2016-10-30 09:46:26 +00:00
msgid ""
"Use :data:`DEFAULT` as the value if you want :func:`patch.multiple` to "
"create mocks for you. In this case the created mocks are passed into a "
"decorated function by keyword, and a dictionary is returned when :func:"
"`patch.multiple` is used as a context manager."
msgstr ""
#: library/unittest.mock.rst:1701
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch.multiple` can be used as a decorator, class decorator or a "
"context manager. The arguments *spec*, *spec_set*, *create*, *autospec* and "
"*new_callable* have the same meaning as for :func:`patch`. These arguments "
"will be applied to *all* patches done by :func:`patch.multiple`."
msgstr ""
#: library/unittest.mock.rst:1706
2016-10-30 09:46:26 +00:00
msgid ""
"When used as a class decorator :func:`patch.multiple` honours ``patch."
"TEST_PREFIX`` for choosing which methods to wrap."
msgstr ""
#: library/unittest.mock.rst:1709
2016-10-30 09:46:26 +00:00
msgid ""
"If you want :func:`patch.multiple` to create mocks for you, then you can "
"use :data:`DEFAULT` as the value. If you use :func:`patch.multiple` as a "
"decorator then the created mocks are passed into the decorated function by "
2019-09-04 09:35:23 +00:00
"keyword. ::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1723
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch.multiple` can be nested with other ``patch`` decorators, but "
"put arguments passed by keyword *after* any of the standard arguments "
2019-09-04 09:35:23 +00:00
"created by :func:`patch`::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1735
2016-10-30 09:46:26 +00:00
msgid ""
"If :func:`patch.multiple` is used as a context manager, the value returned "
2019-03-20 08:41:37 +00:00
"by the context manager is a dictionary where created mocks are keyed by "
"name::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1749
2016-10-30 09:46:26 +00:00
msgid "patch methods: start and stop"
msgstr ""
#: library/unittest.mock.rst:1751
2016-10-30 09:46:26 +00:00
msgid ""
"All the patchers have :meth:`start` and :meth:`stop` methods. These make it "
"simpler to do patching in ``setUp`` methods or where you want to do multiple "
"patches without nesting decorators or with statements."
msgstr ""
#: library/unittest.mock.rst:1755
2016-10-30 09:46:26 +00:00
msgid ""
"To use them call :func:`patch`, :func:`patch.object` or :func:`patch.dict` "
"as normal and keep a reference to the returned ``patcher`` object. You can "
"then call :meth:`start` to put the patch in place and :meth:`stop` to undo "
"it."
msgstr ""
#: library/unittest.mock.rst:1759
2016-10-30 09:46:26 +00:00
msgid ""
"If you are using :func:`patch` to create a mock for you then it will be "
2019-09-04 09:35:23 +00:00
"returned by the call to ``patcher.start``. ::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1773
2016-10-30 09:46:26 +00:00
msgid ""
"A typical use case for this might be for doing multiple patches in the "
2019-09-04 09:35:23 +00:00
"``setUp`` method of a :class:`TestCase`::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1795
2016-10-30 09:46:26 +00:00
msgid ""
"If you use this technique you must ensure that the patching is \"undone\" by "
"calling ``stop``. This can be fiddlier than you might think, because if an "
"exception is raised in the ``setUp`` then ``tearDown`` is not called. :meth:"
2019-09-04 09:35:23 +00:00
"`unittest.TestCase.addCleanup` makes this easier::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1810
2016-10-30 09:46:26 +00:00
msgid ""
"As an added bonus you no longer need to keep a reference to the ``patcher`` "
"object."
msgstr ""
#: library/unittest.mock.rst:1813
2016-10-30 09:46:26 +00:00
msgid ""
"It is also possible to stop all patches which have been started by using :"
"func:`patch.stopall`."
msgstr ""
#: library/unittest.mock.rst:1818
2016-10-30 09:46:26 +00:00
msgid "Stop all active patches. Only stops patches started with ``start``."
msgstr ""
#: library/unittest.mock.rst:1824
2016-10-30 09:46:26 +00:00
msgid "patch builtins"
msgstr ""
#: library/unittest.mock.rst:1825
2016-10-30 09:46:26 +00:00
msgid ""
"You can patch any builtins within a module. The following example patches "
2019-09-04 09:35:23 +00:00
"builtin :func:`ord`::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1840
2016-10-30 09:46:26 +00:00
msgid "TEST_PREFIX"
msgstr ""
#: library/unittest.mock.rst:1842
2016-10-30 09:46:26 +00:00
msgid ""
"All of the patchers can be used as class decorators. When used in this way "
"they wrap every test method on the class. The patchers recognise methods "
"that start with ``'test'`` as being test methods. This is the same way that "
"the :class:`unittest.TestLoader` finds test methods by default."
msgstr ""
#: library/unittest.mock.rst:1847
2016-10-30 09:46:26 +00:00
msgid ""
"It is possible that you want to use a different prefix for your tests. You "
"can inform the patchers of the different prefix by setting ``patch."
2019-09-04 09:35:23 +00:00
"TEST_PREFIX``::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1870
2016-10-30 09:46:26 +00:00
msgid "Nesting Patch Decorators"
msgstr ""
#: library/unittest.mock.rst:1872
2016-10-30 09:46:26 +00:00
msgid ""
"If you want to perform multiple patches then you can simply stack up the "
"decorators."
msgstr ""
#: library/unittest.mock.rst:1875
2016-10-30 09:46:26 +00:00
msgid "You can stack up multiple patch decorators using this pattern:"
msgstr ""
#: library/unittest.mock.rst:1891
2016-10-30 09:46:26 +00:00
msgid ""
"Note that the decorators are applied from the bottom upwards. This is the "
"standard way that Python applies decorators. The order of the created mocks "
"passed into your test function matches this order."
msgstr ""
#: library/unittest.mock.rst:1899
2016-10-30 09:46:26 +00:00
msgid "Where to patch"
msgstr ""
#: library/unittest.mock.rst:1901
2016-10-30 09:46:26 +00:00
msgid ""
":func:`patch` 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."
msgstr ""
#: library/unittest.mock.rst:1906
2016-10-30 09:46:26 +00:00
msgid ""
"The basic principle is that you patch where an object is *looked up*, which "
"is not necessarily the same place as where it is defined. A couple of "
"examples will help to clarify this."
msgstr ""
#: library/unittest.mock.rst:1910
2016-10-30 09:46:26 +00:00
msgid ""
"Imagine we have a project that we want to test with the following structure::"
msgstr ""
#: library/unittest.mock.rst:1919
2016-10-30 09:46:26 +00:00
msgid ""
"Now we want to test ``some_function`` but we want to mock out ``SomeClass`` "
"using :func:`patch`. The problem is that when we import module b, which we "
"will have to do then it imports ``SomeClass`` from module a. If we use :func:"
"`patch` to mock out ``a.SomeClass`` then it will have no effect on our test; "
"module b already has a reference to the *real* ``SomeClass`` and it looks "
"like our patching had no effect."
msgstr ""
#: library/unittest.mock.rst:1926
2016-10-30 09:46:26 +00:00
msgid ""
"The key is to patch out ``SomeClass`` where it is used (or where it is "
2018-06-28 13:32:56 +00:00
"looked up). In this case ``some_function`` will actually look up "
2016-10-30 09:46:26 +00:00
"``SomeClass`` in module b, where we have imported it. The patching should "
"look like::"
msgstr ""
#: library/unittest.mock.rst:1932
2016-10-30 09:46:26 +00:00
msgid ""
"However, consider the alternative scenario where instead of ``from a import "
"SomeClass`` module b does ``import a`` and ``some_function`` uses ``a."
"SomeClass``. Both of these import forms are common. In this case the class "
"we want to patch is being looked up in the module and so we have to patch "
"``a.SomeClass`` instead::"
msgstr ""
#: library/unittest.mock.rst:1941
2016-10-30 09:46:26 +00:00
msgid "Patching Descriptors and Proxy Objects"
msgstr ""
#: library/unittest.mock.rst:1943
2016-10-30 09:46:26 +00:00
msgid ""
"Both patch_ and patch.object_ correctly patch and restore descriptors: class "
"methods, static methods and properties. You should patch these on the "
"*class* rather than an instance. They also work with *some* objects that "
"proxy attribute access, like the `django settings object <https://web."
"archive.org/web/20200603181648/http://www.voidspace.org.uk/python/weblog/"
"arch_d7_2010_12_04.shtml#e1198>`_."
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:1951
2016-10-30 09:46:26 +00:00
msgid "MagicMock and magic method support"
msgstr ""
#: library/unittest.mock.rst:1956
2016-10-30 09:46:26 +00:00
msgid "Mocking Magic Methods"
msgstr ""
#: library/unittest.mock.rst:1958
2016-10-30 09:46:26 +00:00
msgid ""
":class:`Mock` supports mocking the Python protocol methods, also known as "
"\"magic methods\". This allows mock objects to replace containers or other "
"objects that implement Python protocols."
msgstr ""
#: library/unittest.mock.rst:1962
2016-10-30 09:46:26 +00:00
msgid ""
"Because magic methods are looked up differently from normal methods [#]_, "
"this support has been specially implemented. This means that only specific "
"magic methods are supported. The supported list includes *almost* all of "
"them. If there are any missing that you need please let us know."
msgstr ""
#: library/unittest.mock.rst:1967
2016-10-30 09:46:26 +00:00
msgid ""
"You mock magic methods by setting the method you are interested in to a "
"function or a mock instance. If you are using a function then it *must* take "
"``self`` as the first argument [#]_."
msgstr ""
#: library/unittest.mock.rst:1990
2016-10-30 09:46:26 +00:00
msgid ""
"One use case for this is for mocking objects used as context managers in a :"
"keyword:`with` statement:"
msgstr ""
#: library/unittest.mock.rst:2002
2016-10-30 09:46:26 +00:00
msgid ""
"Calls to magic methods do not appear in :attr:`~Mock.method_calls`, but they "
"are recorded in :attr:`~Mock.mock_calls`."
msgstr ""
#: library/unittest.mock.rst:2007
2016-10-30 09:46:26 +00:00
msgid ""
"If you use the *spec* keyword argument to create a mock then attempting to "
"set a magic method that isn't in the spec will raise an :exc:"
"`AttributeError`."
msgstr ""
#: library/unittest.mock.rst:2010
2016-10-30 09:46:26 +00:00
msgid "The full list of supported magic methods is:"
msgstr ""
#: library/unittest.mock.rst:2012
2016-10-30 09:46:26 +00:00
msgid "``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__``"
msgstr ""
#: library/unittest.mock.rst:2013
2016-10-30 09:46:26 +00:00
msgid "``__dir__``, ``__format__`` and ``__subclasses__``"
msgstr "``__dir__``, ``__format__`` et ``__subclasses__``"
#: library/unittest.mock.rst:2014
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid "``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__``"
2016-10-30 09:46:26 +00:00
msgstr "``__floor__``, ``__trunc__`` et ``__ceil__``"
#: library/unittest.mock.rst:2015
2016-10-30 09:46:26 +00:00
msgid ""
"Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``, ``__eq__`` and "
"``__ne__``"
msgstr ""
#: library/unittest.mock.rst:2017
2016-10-30 09:46:26 +00:00
msgid ""
"Container methods: ``__getitem__``, ``__setitem__``, ``__delitem__``, "
"``__contains__``, ``__len__``, ``__iter__``, ``__reversed__`` and "
"``__missing__``"
msgstr ""
#: library/unittest.mock.rst:2020
2019-09-04 09:35:23 +00:00
#, fuzzy
msgid ""
"Context manager: ``__enter__``, ``__exit__``, ``__aenter__`` and "
"``__aexit__``"
msgstr "``__get__``, ``__set__`` et ``__delete__``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2021
2016-10-30 09:46:26 +00:00
msgid "Unary numeric methods: ``__neg__``, ``__pos__`` and ``__invert__``"
msgstr ""
#: library/unittest.mock.rst:2022
2016-10-30 09:46:26 +00:00
msgid ""
"The numeric methods (including right hand and in-place variants): "
2022-03-23 17:40:12 +00:00
"``__add__``, ``__sub__``, ``__mul__``, ``__matmul__``, ``__truediv__``, "
"``__floordiv__``, ``__mod__``, ``__divmod__``, ``__lshift__``, "
"``__rshift__``, ``__and__``, ``__xor__``, ``__or__``, and ``__pow__``"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2026
2016-10-30 09:46:26 +00:00
msgid ""
"Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__`` and "
"``__index__``"
msgstr ""
#: library/unittest.mock.rst:2028
2016-10-30 09:46:26 +00:00
msgid "Descriptor methods: ``__get__``, ``__set__`` and ``__delete__``"
msgstr ""
#: library/unittest.mock.rst:2029
2016-10-30 09:46:26 +00:00
msgid ""
"Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, "
"``__getnewargs__``, ``__getstate__`` and ``__setstate__``"
msgstr ""
#: library/unittest.mock.rst:2031
2019-09-04 09:35:23 +00:00
msgid "File system path representation: ``__fspath__``"
msgstr ""
#: library/unittest.mock.rst:2032
2019-09-04 09:35:23 +00:00
msgid "Asynchronous iteration methods: ``__aiter__`` and ``__anext__``"
msgstr ""
#: library/unittest.mock.rst:2034
2019-09-04 09:35:23 +00:00
msgid "Added support for :func:`os.PathLike.__fspath__`."
msgstr ""
#: library/unittest.mock.rst:2037
2019-09-04 09:35:23 +00:00
msgid ""
"Added support for ``__aenter__``, ``__aexit__``, ``__aiter__`` and "
"``__anext__``."
msgstr ""
#: library/unittest.mock.rst:2041
2016-10-30 09:46:26 +00:00
msgid ""
"The following methods exist but are *not* supported as they are either in "
"use by mock, can't be set dynamically, or can cause problems:"
msgstr ""
#: library/unittest.mock.rst:2044
2016-10-30 09:46:26 +00:00
msgid "``__getattr__``, ``__setattr__``, ``__init__`` and ``__new__``"
msgstr ""
#: library/unittest.mock.rst:2045
2016-10-30 09:46:26 +00:00
msgid ""
"``__prepare__``, ``__instancecheck__``, ``__subclasscheck__``, ``__del__``"
msgstr ""
#: library/unittest.mock.rst:2050
2016-10-30 09:46:26 +00:00
msgid "Magic Mock"
msgstr ""
#: library/unittest.mock.rst:2052
2016-10-30 09:46:26 +00:00
msgid ""
"There are two ``MagicMock`` variants: :class:`MagicMock` and :class:"
"`NonCallableMagicMock`."
msgstr ""
#: library/unittest.mock.rst:2057
2016-10-30 09:46:26 +00:00
msgid ""
"``MagicMock`` is a subclass of :class:`Mock` with default implementations of "
"most of the magic methods. You can use ``MagicMock`` without having to "
"configure the magic methods yourself."
msgstr ""
#: library/unittest.mock.rst:2061
2016-10-30 09:46:26 +00:00
msgid "The constructor parameters have the same meaning as for :class:`Mock`."
msgstr ""
#: library/unittest.mock.rst:2063
2016-10-30 09:46:26 +00:00
msgid ""
"If you use the *spec* or *spec_set* arguments then *only* magic methods that "
"exist in the spec will be created."
msgstr ""
#: library/unittest.mock.rst:2069
2016-10-30 09:46:26 +00:00
msgid "A non-callable version of :class:`MagicMock`."
msgstr ""
#: library/unittest.mock.rst:2071
2016-10-30 09:46:26 +00:00
msgid ""
"The constructor parameters have the same meaning as for :class:`MagicMock`, "
"with the exception of *return_value* and *side_effect* which have no meaning "
"on a non-callable mock."
msgstr ""
#: library/unittest.mock.rst:2075
2016-10-30 09:46:26 +00:00
msgid ""
"The magic methods are setup with :class:`MagicMock` objects, so you can "
"configure them and use them in the usual way:"
msgstr ""
#: library/unittest.mock.rst:2085
2016-10-30 09:46:26 +00:00
msgid ""
"By default many of the protocol methods are required to return objects of a "
"specific type. These methods are preconfigured with a default return value, "
"so that they can be used without you having to do anything if you aren't "
"interested in the return value. You can still *set* the return value "
"manually if you want to change the default."
msgstr ""
#: library/unittest.mock.rst:2091
2016-10-30 09:46:26 +00:00
msgid "Methods and their defaults:"
msgstr ""
#: library/unittest.mock.rst:2093
msgid "``__lt__``: ``NotImplemented``"
msgstr "``__lt__``: ``NotImplemented``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2094
msgid "``__gt__``: ``NotImplemented``"
msgstr "``__gt__``: ``NotImplemented``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2095
msgid "``__le__``: ``NotImplemented``"
msgstr "``__le__``: ``NotImplemented``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2096
msgid "``__ge__``: ``NotImplemented``"
msgstr "``__ge__``: ``NotImplemented``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2097
msgid "``__int__``: ``1``"
msgstr "``__int__``: ``1``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2098
msgid "``__contains__``: ``False``"
msgstr "``__contains__``: ``False``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2099
msgid "``__len__``: ``0``"
msgstr "``__int__``: ``0``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2100
msgid "``__iter__``: ``iter([])``"
msgstr "``__iter__``: ``iter([])``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2101
msgid "``__exit__``: ``False``"
msgstr "``__exit__``: ``False``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2102
msgid "``__aexit__``: ``False``"
msgstr "``__exit__``: ``False``"
2019-09-04 09:35:23 +00:00
#: library/unittest.mock.rst:2103
msgid "``__complex__``: ``1j``"
msgstr "``__complex__``: ``1j``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2104
msgid "``__float__``: ``1.0``"
msgstr "``__float__``: ``1.0``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2105
msgid "``__bool__``: ``True``"
msgstr "``__bool__``: ``True``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2106
msgid "``__index__``: ``1``"
msgstr "``__index__``: ``1``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2107
2016-10-30 09:46:26 +00:00
msgid "``__hash__``: default hash for the mock"
msgstr ""
#: library/unittest.mock.rst:2108
2016-10-30 09:46:26 +00:00
msgid "``__str__``: default str for the mock"
msgstr ""
#: library/unittest.mock.rst:2109
2016-10-30 09:46:26 +00:00
msgid "``__sizeof__``: default sizeof for the mock"
msgstr ""
#: library/unittest.mock.rst:2111
2016-10-30 09:46:26 +00:00
msgid "For example:"
2019-03-09 22:39:59 +00:00
msgstr "Par exemple :"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2123
2016-10-30 09:46:26 +00:00
msgid ""
"The two equality methods, :meth:`__eq__` and :meth:`__ne__`, are special. "
"They do the default equality comparison on identity, using the :attr:`~Mock."
"side_effect` attribute, unless you change their return value to return "
"something else::"
msgstr ""
#: library/unittest.mock.rst:2137
2016-10-30 09:46:26 +00:00
msgid ""
"The return value of :meth:`MagicMock.__iter__` can be any iterable object "
"and isn't required to be an iterator:"
msgstr ""
#: library/unittest.mock.rst:2147
2016-10-30 09:46:26 +00:00
msgid ""
"If the return value *is* an iterator, then iterating over it once will "
"consume it and subsequent iterations will result in an empty list:"
msgstr ""
#: library/unittest.mock.rst:2156
2016-10-30 09:46:26 +00:00
msgid ""
"``MagicMock`` has all of the supported magic methods configured except for "
"some of the obscure and obsolete ones. You can still set these up if you "
"want."
msgstr ""
#: library/unittest.mock.rst:2159
2016-10-30 09:46:26 +00:00
msgid ""
"Magic methods that are supported but not setup by default in ``MagicMock`` "
"are:"
msgstr ""
#: library/unittest.mock.rst:2161
2016-10-30 09:46:26 +00:00
msgid "``__subclasses__``"
msgstr "``__subclasses__``"
#: library/unittest.mock.rst:2162
2016-10-30 09:46:26 +00:00
msgid "``__dir__``"
msgstr "``__dir__``"
#: library/unittest.mock.rst:2163
2016-10-30 09:46:26 +00:00
msgid "``__format__``"
msgstr "``__format__``"
#: library/unittest.mock.rst:2164
2016-10-30 09:46:26 +00:00
msgid "``__get__``, ``__set__`` and ``__delete__``"
msgstr "``__get__``, ``__set__`` et ``__delete__``"
#: library/unittest.mock.rst:2165
2016-10-30 09:46:26 +00:00
msgid "``__reversed__`` and ``__missing__``"
msgstr "``__reversed__`` et ``__missing__``"
#: library/unittest.mock.rst:2166
2016-10-30 09:46:26 +00:00
msgid ""
"``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, ``__getnewargs__``, "
"``__getstate__`` and ``__setstate__``"
msgstr ""
#: library/unittest.mock.rst:2168
2022-03-23 17:40:12 +00:00
#, fuzzy
msgid "``__getformat__``"
msgstr "``__format__``"
2016-10-30 09:46:26 +00:00
#: library/unittest.mock.rst:2172
2016-10-30 09:46:26 +00:00
msgid ""
"Magic methods *should* be looked up on the class rather than the instance. "
"Different versions of Python are inconsistent about applying this rule. The "
"supported protocol methods should work with all supported versions of Python."
msgstr ""
#: library/unittest.mock.rst:2176
2016-10-30 09:46:26 +00:00
msgid ""
"The function is basically hooked up to the class, but each ``Mock`` instance "
"is kept isolated from the others."
msgstr ""
#: library/unittest.mock.rst:2181
2016-10-30 09:46:26 +00:00
msgid "Helpers"
msgstr ""
#: library/unittest.mock.rst:2184
2016-10-30 09:46:26 +00:00
msgid "sentinel"
msgstr ""
#: library/unittest.mock.rst:2188
2016-10-30 09:46:26 +00:00
msgid ""
"The ``sentinel`` object provides a convenient way of providing unique "
"objects for your tests."
msgstr ""
#: library/unittest.mock.rst:2191
2016-10-30 09:46:26 +00:00
msgid ""
"Attributes are created on demand when you access them by name. Accessing the "
"same attribute will always return the same object. The objects returned have "
"a sensible repr so that test failure messages are readable."
msgstr ""
#: library/unittest.mock.rst:2195
2017-04-02 20:14:06 +00:00
msgid ""
2018-06-28 13:32:56 +00:00
"The ``sentinel`` attributes now preserve their identity when they are :mod:"
2017-04-02 20:14:06 +00:00
"`copied <copy>` or :mod:`pickled <pickle>`."
msgstr ""
#: library/unittest.mock.rst:2199
2016-10-30 09:46:26 +00:00
msgid ""
"Sometimes when testing you need to test that a specific object is passed as "
"an argument to another method, or returned. It can be common to create named "
"sentinel objects to test this. :data:`sentinel` provides a convenient way of "
"creating and testing the identity of objects like this."
msgstr ""
#: library/unittest.mock.rst:2204
2016-10-30 09:46:26 +00:00
msgid ""
"In this example we monkey patch ``method`` to return ``sentinel."
"some_object``:"
msgstr ""
#: library/unittest.mock.rst:2216
2016-10-30 09:46:26 +00:00
msgid "DEFAULT"
msgstr ""
#: library/unittest.mock.rst:2221
2016-10-30 09:46:26 +00:00
msgid ""
"The :data:`DEFAULT` object is a pre-created sentinel (actually ``sentinel."
"DEFAULT``). It can be used by :attr:`~Mock.side_effect` functions to "
"indicate that the normal return value should be used."
msgstr ""
#: library/unittest.mock.rst:2227
2016-10-30 09:46:26 +00:00
msgid "call"
msgstr ""
#: library/unittest.mock.rst:2231
2016-10-30 09:46:26 +00:00
msgid ""
":func:`call` is a helper object for making simpler assertions, for comparing "
"with :attr:`~Mock.call_args`, :attr:`~Mock.call_args_list`, :attr:`~Mock."
"mock_calls` and :attr:`~Mock.method_calls`. :func:`call` can also be used "
"with :meth:`~Mock.assert_has_calls`."
msgstr ""
#: library/unittest.mock.rst:2244
2016-10-30 09:46:26 +00:00
msgid ""
"For a call object that represents multiple calls, :meth:`call_list` returns "
"a list of all the intermediate calls as well as the final call."
msgstr ""
#: library/unittest.mock.rst:2248
2016-10-30 09:46:26 +00:00
msgid ""
2022-03-23 17:40:12 +00:00
"``call_list`` is particularly useful for making assertions on \"chained "
"calls\". A chained call is multiple calls on a single line of code. This "
"results in multiple entries in :attr:`~Mock.mock_calls` on a mock. Manually "
2016-10-30 09:46:26 +00:00
"constructing the sequence of calls can be tedious."
msgstr ""
#: library/unittest.mock.rst:2253
2016-10-30 09:46:26 +00:00
msgid ""
":meth:`~call.call_list` can construct the sequence of calls from the same "
"chained call:"
msgstr ""
#: library/unittest.mock.rst:2270
2016-10-30 09:46:26 +00:00
msgid ""
"A ``call`` object is either a tuple of (positional args, keyword args) or "
"(name, positional args, keyword args) depending on how it was constructed. "
"When you construct them yourself this isn't particularly interesting, but "
"the ``call`` objects that are in the :attr:`Mock.call_args`, :attr:`Mock."
"call_args_list` and :attr:`Mock.mock_calls` attributes can be introspected "
"to get at the individual arguments they contain."
msgstr ""
#: library/unittest.mock.rst:2277
2016-10-30 09:46:26 +00:00
msgid ""
"The ``call`` objects in :attr:`Mock.call_args` and :attr:`Mock."
"call_args_list` are two-tuples of (positional args, keyword args) whereas "
"the ``call`` objects in :attr:`Mock.mock_calls`, along with ones you "
"construct yourself, are three-tuples of (name, positional args, keyword "
"args)."
msgstr ""
#: library/unittest.mock.rst:2282
2016-10-30 09:46:26 +00:00
msgid ""
"You can use their \"tupleness\" to pull out the individual arguments for "
"more complex introspection and assertions. The positional arguments are a "
"tuple (an empty tuple if there are no positional arguments) and the keyword "
"arguments are a dictionary:"
msgstr ""
#: library/unittest.mock.rst:2315
2016-10-30 09:46:26 +00:00
msgid "create_autospec"
msgstr ""
#: library/unittest.mock.rst:2319
2016-10-30 09:46:26 +00:00
msgid ""
"Create a mock object using another object as a spec. Attributes on the mock "
"will use the corresponding attribute on the *spec* object as their spec."
msgstr ""
#: library/unittest.mock.rst:2323
2016-10-30 09:46:26 +00:00
msgid ""
"Functions or methods being mocked will have their arguments checked to "
"ensure that they are called with the correct signature."
msgstr ""
#: library/unittest.mock.rst:2326
2016-10-30 09:46:26 +00:00
msgid ""
"If *spec_set* is ``True`` then attempting to set attributes that don't exist "
"on the spec object will raise an :exc:`AttributeError`."
msgstr ""
#: library/unittest.mock.rst:2329
2016-10-30 09:46:26 +00:00
msgid ""
"If a class is used as a spec then the return value of the mock (the instance "
"of the class) will have the same spec. You can use a class as the spec for "
"an instance object by passing ``instance=True``. The returned mock will only "
"be callable if instances of the mock are callable."
msgstr ""
#: library/unittest.mock.rst:2334
2016-10-30 09:46:26 +00:00
msgid ""
":func:`create_autospec` also takes arbitrary keyword arguments that are "
"passed to the constructor of the created mock."
msgstr ""
#: library/unittest.mock.rst:2337
2016-10-30 09:46:26 +00:00
msgid ""
"See :ref:`auto-speccing` for examples of how to use auto-speccing with :func:"
"`create_autospec` and the *autospec* argument to :func:`patch`."
msgstr ""
#: library/unittest.mock.rst:2343
2019-10-09 16:10:12 +00:00
msgid ""
":func:`create_autospec` now returns an :class:`AsyncMock` if the target is "
"an async function."
msgstr ""
#: library/unittest.mock.rst:2348
2016-10-30 09:46:26 +00:00
msgid "ANY"
msgstr ""
#: library/unittest.mock.rst:2352
2016-10-30 09:46:26 +00:00
msgid ""
"Sometimes you may need to make assertions about *some* of the arguments in a "
"call to mock, but either not care about some of the arguments or want to "
"pull them individually out of :attr:`~Mock.call_args` and make more complex "
"assertions on them."
msgstr ""
#: library/unittest.mock.rst:2357
2016-10-30 09:46:26 +00:00
msgid ""
"To ignore certain arguments you can pass in objects that compare equal to "
"*everything*. Calls to :meth:`~Mock.assert_called_with` and :meth:`~Mock."
"assert_called_once_with` will then succeed no matter what was passed in."
msgstr ""
#: library/unittest.mock.rst:2366
2016-10-30 09:46:26 +00:00
msgid ""
":data:`ANY` can also be used in comparisons with call lists like :attr:"
"`~Mock.mock_calls`:"
msgstr ""
#: library/unittest.mock.rst:2379
2016-10-30 09:46:26 +00:00
msgid "FILTER_DIR"
msgstr ""
#: library/unittest.mock.rst:2383
2016-10-30 09:46:26 +00:00
msgid ""
":data:`FILTER_DIR` is a module level variable that controls the way mock "
2022-05-22 21:15:02 +00:00
"objects respond to :func:`dir`. The default is ``True``, which uses the "
"filtering described below, to only show useful members. If you dislike this "
"filtering, or need to switch it off for diagnostic purposes, then set ``mock."
"FILTER_DIR = False``."
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2389
2016-10-30 09:46:26 +00:00
msgid ""
"With filtering on, ``dir(some_mock)`` shows only useful attributes and will "
"include any dynamically created attributes that wouldn't normally be shown. "
"If the mock was created with a *spec* (or *autospec* of course) then all the "
"attributes from the original are shown, even if they haven't been accessed "
"yet:"
msgstr ""
#: library/unittest.mock.rst:2416
2016-10-30 09:46:26 +00:00
msgid ""
"Many of the not-very-useful (private to :class:`Mock` rather than the thing "
"being mocked) underscore and double underscore prefixed attributes have been "
"filtered from the result of calling :func:`dir` on a :class:`Mock`. If you "
"dislike this behaviour you can switch it off by setting the module level "
"switch :data:`FILTER_DIR`:"
msgstr ""
#: library/unittest.mock.rst:2437
2016-10-30 09:46:26 +00:00
msgid ""
"Alternatively you can just use ``vars(my_mock)`` (instance members) and "
"``dir(type(my_mock))`` (type members) to bypass the filtering irrespective "
"of :data:`mock.FILTER_DIR`."
msgstr ""
#: library/unittest.mock.rst:2443
2016-10-30 09:46:26 +00:00
msgid "mock_open"
msgstr ""
#: library/unittest.mock.rst:2447
2016-10-30 09:46:26 +00:00
msgid ""
"A helper function to create a mock to replace the use of :func:`open`. It "
"works for :func:`open` called directly or used as a context manager."
msgstr ""
#: library/unittest.mock.rst:2450
2016-10-30 09:46:26 +00:00
msgid ""
"The *mock* argument is the mock object to configure. If ``None`` (the "
"default) then a :class:`MagicMock` will be created for you, with the API "
"limited to methods or attributes available on standard file handles."
msgstr ""
#: library/unittest.mock.rst:2454
2016-10-30 09:46:26 +00:00
msgid ""
"*read_data* is a string for the :meth:`~io.IOBase.read`, :meth:`~io.IOBase."
"readline`, and :meth:`~io.IOBase.readlines` methods of the file handle to "
"return. Calls to those methods will take data from *read_data* until it is "
"depleted. The mock of these methods is pretty simplistic: every time the "
"*mock* is called, the *read_data* is rewound to the start. If you need more "
"control over the data that you are feeding to the tested code you will need "
"to customize this mock for yourself. When that is insufficient, one of the "
2018-06-10 09:32:30 +00:00
"in-memory filesystem packages on `PyPI <https://pypi.org>`_ can offer a "
"realistic filesystem for testing."
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2464
2016-10-30 09:46:26 +00:00
msgid ""
"Added :meth:`~io.IOBase.readline` and :meth:`~io.IOBase.readlines` support. "
"The mock of :meth:`~io.IOBase.read` changed to consume *read_data* rather "
"than returning it on each call."
msgstr ""
#: library/unittest.mock.rst:2469
2016-10-30 09:46:26 +00:00
msgid "*read_data* is now reset on each call to the *mock*."
msgstr ""
#: library/unittest.mock.rst:2472
2016-10-30 09:46:26 +00:00
msgid ""
2018-09-15 20:37:31 +00:00
"Added :meth:`__iter__` to implementation so that iteration (such as in for "
"loops) correctly consumes *read_data*."
msgstr ""
#: library/unittest.mock.rst:2476
2018-09-15 20:37:31 +00:00
msgid ""
2016-10-30 09:46:26 +00:00
"Using :func:`open` as a context manager is a great way to ensure your file "
"handles are closed properly and is becoming common::"
msgstr ""
#: library/unittest.mock.rst:2482
2016-10-30 09:46:26 +00:00
msgid ""
"The issue is that even if you mock out the call to :func:`open` it is the "
"*returned object* that is used as a context manager (and has :meth:"
"`__enter__` and :meth:`__exit__` called)."
msgstr ""
#: library/unittest.mock.rst:2486
2016-10-30 09:46:26 +00:00
msgid ""
"Mocking context managers with a :class:`MagicMock` is common enough and "
2019-09-04 09:35:23 +00:00
"fiddly enough that a helper function is useful. ::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2503
2019-09-04 09:35:23 +00:00
msgid "And for reading files::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2516
2016-10-30 09:46:26 +00:00
msgid "Autospeccing"
msgstr ""
#: library/unittest.mock.rst:2518
2016-10-30 09:46:26 +00:00
msgid ""
"Autospeccing is based on the existing :attr:`spec` feature of mock. It "
"limits the api of mocks to the api of an original object (the spec), but it "
"is recursive (implemented lazily) so that attributes of mocks only have the "
"same api as the attributes of the spec. In addition mocked functions / "
"methods have the same call signature as the original so they raise a :exc:"
"`TypeError` if they are called incorrectly."
msgstr ""
#: library/unittest.mock.rst:2525
2016-10-30 09:46:26 +00:00
msgid "Before I explain how auto-speccing works, here's why it is needed."
msgstr ""
#: library/unittest.mock.rst:2527
2016-10-30 09:46:26 +00:00
msgid ""
":class:`Mock` is a very powerful and flexible object, but it suffers from "
"two flaws when used to mock out objects from a system under test. One of "
"these flaws is specific to the :class:`Mock` api and the other is a more "
"general problem with using mock objects."
msgstr ""
#: library/unittest.mock.rst:2532
2016-10-30 09:46:26 +00:00
msgid ""
"First the problem specific to :class:`Mock`. :class:`Mock` has two assert "
"methods that are extremely handy: :meth:`~Mock.assert_called_with` and :meth:"
"`~Mock.assert_called_once_with`."
msgstr ""
#: library/unittest.mock.rst:2545
2016-10-30 09:46:26 +00:00
msgid ""
"Because mocks auto-create attributes on demand, and allow you to call them "
"with arbitrary arguments, if you misspell one of these assert methods then "
"your assertion is gone:"
msgstr ""
#: library/unittest.mock.rst:2555
2016-10-30 09:46:26 +00:00
msgid "Your tests can pass silently and incorrectly because of the typo."
msgstr ""
#: library/unittest.mock.rst:2557
2016-10-30 09:46:26 +00:00
msgid ""
"The second issue is more general to mocking. If you refactor some of your "
"code, rename members and so on, any tests for code that is still using the "
"*old api* but uses mocks instead of the real objects will still pass. This "
"means your tests can all pass even though your code is broken."
msgstr ""
#: library/unittest.mock.rst:2562
2016-10-30 09:46:26 +00:00
msgid ""
"Note that this is another reason why you need integration tests as well as "
"unit tests. Testing everything in isolation is all fine and dandy, but if "
"you don't test how your units are \"wired together\" there is still lots of "
"room for bugs that tests might have caught."
msgstr ""
#: library/unittest.mock.rst:2567
2016-10-30 09:46:26 +00:00
msgid ""
":mod:`mock` already provides a feature to help with this, called speccing. "
"If you use a class or instance as the :attr:`spec` for a mock then you can "
"only access attributes on the mock that exist on the real class:"
msgstr ""
#: library/unittest.mock.rst:2578
2016-10-30 09:46:26 +00:00
msgid ""
"The spec only applies to the mock itself, so we still have the same issue "
"with any methods on the mock:"
msgstr ""
#: library/unittest.mock.rst:2587
2016-10-30 09:46:26 +00:00
msgid ""
"Auto-speccing solves this problem. You can either pass ``autospec=True`` to :"
"func:`patch` / :func:`patch.object` or use the :func:`create_autospec` "
"function to create a mock with a spec. If you use the ``autospec=True`` "
"argument to :func:`patch` then the object that is being replaced will be "
"used as the spec object. Because the speccing is done \"lazily\" (the spec "
"is created as attributes on the mock are accessed) you can use it with very "
"complex or deeply nested objects (like modules that import modules that "
"import modules) without a big performance hit."
msgstr ""
#: library/unittest.mock.rst:2596
2019-09-04 09:35:23 +00:00
msgid "Here's an example of it in use::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2606
2016-10-30 09:46:26 +00:00
msgid ""
"You can see that :class:`request.Request` has a spec. :class:`request."
"Request` takes two arguments in the constructor (one of which is *self*). "
2019-09-04 09:35:23 +00:00
"Here's what happens if we try to call it incorrectly::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2615
2016-10-30 09:46:26 +00:00
msgid ""
"The spec also applies to instantiated classes (i.e. the return value of "
2019-09-04 09:35:23 +00:00
"specced mocks)::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2622
2016-10-30 09:46:26 +00:00
msgid ""
":class:`Request` objects are not callable, so the return value of "
"instantiating our mocked out :class:`request.Request` is a non-callable "
"mock. With the spec in place any typos in our asserts will raise the correct "
2019-09-04 09:35:23 +00:00
"error::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2634
2016-10-30 09:46:26 +00:00
msgid ""
"In many cases you will just be able to add ``autospec=True`` to your "
"existing :func:`patch` calls and then be protected against bugs due to typos "
"and api changes."
msgstr ""
#: library/unittest.mock.rst:2638
2016-10-30 09:46:26 +00:00
msgid ""
"As well as using *autospec* through :func:`patch` there is a :func:"
"`create_autospec` for creating autospecced mocks directly:"
msgstr ""
#: library/unittest.mock.rst:2646
2016-10-30 09:46:26 +00:00
msgid ""
"This isn't without caveats and limitations however, which is why it is not "
"the default behaviour. In order to know what attributes are available on the "
"spec object, autospec has to introspect (access attributes) the spec. As you "
"traverse attributes on the mock a corresponding traversal of the original "
"object is happening under the hood. If any of your specced objects have "
"properties or descriptors that can trigger code execution then you may not "
"be able to use autospec. On the other hand it is much better to design your "
"objects so that introspection is safe [#]_."
msgstr ""
#: library/unittest.mock.rst:2655
2016-10-30 09:46:26 +00:00
msgid ""
"A more serious problem is that it is common for instance attributes to be "
"created in the :meth:`__init__` method and not to exist on the class at all. "
"*autospec* can't know about any dynamically created attributes and restricts "
2019-09-04 09:35:23 +00:00
"the api to visible attributes. ::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2672
2016-10-30 09:46:26 +00:00
msgid ""
"There are a few different ways of resolving this problem. The easiest, but "
"not necessarily the least annoying, way is to simply set the required "
"attributes on the mock after creation. Just because *autospec* doesn't allow "
"you to fetch attributes that don't exist on the spec it doesn't prevent you "
2019-09-04 09:35:23 +00:00
"setting them::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2683
2016-10-30 09:46:26 +00:00
msgid ""
"There is a more aggressive version of both *spec* and *autospec* that *does* "
"prevent you setting non-existent attributes. This is useful if you want to "
"ensure your code only *sets* valid attributes too, but obviously it prevents "
"this particular scenario:"
msgstr ""
#: library/unittest.mock.rst:2696
2016-10-30 09:46:26 +00:00
msgid ""
"Probably the best way of solving the problem is to add class attributes as "
"default values for instance members initialised in :meth:`__init__`. Note "
"that if you are only setting default attributes in :meth:`__init__` then "
"providing them via class attributes (shared between instances of course) is "
"faster too. e.g."
msgstr ""
#: library/unittest.mock.rst:2706
2016-10-30 09:46:26 +00:00
msgid ""
"This brings up another issue. It is relatively common to provide a default "
"value of ``None`` for members that will later be an object of a different "
"type. ``None`` would be useless as a spec because it wouldn't let you access "
"*any* attributes or methods on it. As ``None`` is *never* going to be useful "
"as a spec, and probably indicates a member that will normally of some other "
"type, autospec doesn't use a spec for members that are set to ``None``. "
"These will just be ordinary mocks (well - MagicMocks):"
msgstr ""
#: library/unittest.mock.rst:2721
2016-10-30 09:46:26 +00:00
msgid ""
"If modifying your production classes to add defaults isn't to your liking "
"then there are more options. One of these is simply to use an instance as "
"the spec rather than the class. The other is to create a subclass of the "
"production class and add the defaults to the subclass without affecting the "
"production class. Both of these require you to use an alternative object as "
"the spec. Thankfully :func:`patch` supports this - you can simply pass the "
2019-09-04 09:35:23 +00:00
"alternative object as the *autospec* argument::"
2016-10-30 09:46:26 +00:00
msgstr ""
#: library/unittest.mock.rst:2742
2016-10-30 09:46:26 +00:00
msgid ""
"This only applies to classes or already instantiated objects. Calling a "
"mocked class to create a mock instance *does not* create a real instance. It "
"is only attribute lookups - along with calls to :func:`dir` - that are done."
msgstr ""
2018-06-28 13:32:56 +00:00
#: library/unittest.mock.rst:2747
2018-06-28 13:32:56 +00:00
msgid "Sealing mocks"
msgstr ""
#: library/unittest.mock.rst:2756
2018-06-28 13:32:56 +00:00
msgid ""
2018-11-29 15:13:39 +00:00
"Seal will disable the automatic creation of mocks when accessing an "
"attribute of the mock being sealed or any of its attributes that are already "
"mocks recursively."
2018-06-28 13:32:56 +00:00
msgstr ""
#: library/unittest.mock.rst:2759
2018-06-28 13:32:56 +00:00
msgid ""
2018-11-29 15:13:39 +00:00
"If a mock instance with a name or a spec is assigned to an attribute it "
"won't be considered in the sealing chain. This allows one to prevent seal "
2019-09-04 09:35:23 +00:00
"from fixing part of the mock object. ::"
2018-06-28 13:32:56 +00:00
msgstr ""
2022-03-23 17:40:12 +00:00
#~ msgid "``__getformat__`` and ``__setformat__``"
#~ msgstr "``__getformat__`` et ``__setformat__``"