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

2612 lines
96 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (C) 2001-2018, Python Software Foundation
# For licence information, see README file.
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-24 09:01+0200\n"
"PO-Revision-Date: 2019-04-22 12:07+0200\n"
"Last-Translator: Bousquié Pierre <pierre.bousquie@gmail.com>\n"
"Language-Team: FRENCH <traductions@lists.afpy.org>\n"
"Language: fr\n"
"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"
#: library/unittest.mock.rst:3
msgid ":mod:`unittest.mock` --- mock object library"
msgstr ":mod:`unittest.mock` — Bibliothèque d'objets simulacres"
#: library/unittest.mock.rst:13
msgid "**Source code:** :source:`Lib/unittest/mock.py`"
msgstr "**Code source :** :source:`Lib/unittest/mock.py`"
#: library/unittest.mock.rst:17
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."
#: library/unittest.mock.rst:21
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."
#: library/unittest.mock.rst:27
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`."
#: library/unittest.mock.rst:33
msgid ""
"Mock is very easy to use and is designed for use with :mod:`unittest`. Mock "
"is based on the 'action -> assertion' pattern instead of 'record -> replay' "
"used by many mocking frameworks."
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."
#: library/unittest.mock.rst:37
msgid ""
"There is a backport of :mod:`unittest.mock` for earlier versions of Python, "
"available as `mock on PyPI <https://pypi.org/project/mock>`_."
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>`_."
#: library/unittest.mock.rst:42
msgid "Quick Guide"
msgstr "Guide rapide"
#: library/unittest.mock.rst:60
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 ::"
#: library/unittest.mock.rst:72
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é ::"
#: library/unittest.mock.rst:92
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`."
#: library/unittest.mock.rst:97
#, fuzzy
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 "
"ends::"
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 ::"
#: library/unittest.mock.rst:116
msgid ""
"When you nest patch decorators the mocks are passed in to the decorated "
"function in the same order they applied (the normal *Python* order that "
"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."
#: library/unittest.mock.rst:121
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>`."
#: library/unittest.mock.rst:125
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* ::"
#: library/unittest.mock.rst:135
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 ::"
#: library/unittest.mock.rst:146
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 ::"
#: library/unittest.mock.rst:156
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)."
#: library/unittest.mock.rst:161
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 ::"
#: library/unittest.mock.rst:169
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."
#: library/unittest.mock.rst:177
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 ::"
#: library/unittest.mock.rst:193
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__``."
#: library/unittest.mock.rst:200
msgid "The Mock Class"
msgstr "La classe *Mock*"
#: library/unittest.mock.rst:211
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."
#: library/unittest.mock.rst:217
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`"
#: library/unittest.mock.rst:222
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`."
#: library/unittest.mock.rst:230
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* ::"
#: library/unittest.mock.rst:233
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`."
#: library/unittest.mock.rst:239
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`."
#: library/unittest.mock.rst:243
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`."
#: library/unittest.mock.rst:247
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."
#: library/unittest.mock.rst:253
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."
#: library/unittest.mock.rst:256
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."
#: library/unittest.mock.rst:259
msgid "A *side_effect* can be cleared by setting it to ``None``."
msgstr "Utilisez ``None`` pour remettre à zéro un *side_effect*."
#: library/unittest.mock.rst:261
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`."
#: library/unittest.mock.rst:265
msgid ""
"*unsafe*: By default if any attribute starts with *assert* or *assret* will "
"raise an :exc:`AttributeError`. Passing ``unsafe=True`` will allow access to "
"these attributes."
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."
#: library/unittest.mock.rst:271
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`)."
#: library/unittest.mock.rst:278
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."
#: library/unittest.mock.rst:281
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*."
#: library/unittest.mock.rst:285
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."
#: library/unittest.mock.rst:291
msgid "Assert that the mock was called at least once."
msgstr "Asserter que le *mock* a été appelé au moins une fois."
#: library/unittest.mock.rst:302
msgid "Assert that the mock was called exactly once."
msgstr "Asserter que le *mock* a été appelé exactement une fois."
#: library/unittest.mock.rst:320
#, fuzzy
msgid ""
"This method is a convenient way of asserting that the last call has been "
"made in a particular way:"
msgstr ""
"Cette méthode est un moyen pratique d'asserter que les appels sont effectués "
"d'une manière particulière ::"
#: library/unittest.mock.rst:330
msgid ""
"Assert that the mock was called exactly once and that that call was 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:345
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."
#: library/unittest.mock.rst:347
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 "
"the call is the most recent one, and in the case of :meth:"
"`assert_called_once_with` it must also be the only call."
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."
#: library/unittest.mock.rst:360
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."
#: library/unittest.mock.rst:363
#, fuzzy
msgid ""
"If *any_order* is false then the calls must be sequential. There can be "
"extra calls before or after the specified calls."
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:367
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`."
#: library/unittest.mock.rst:382
msgid "Assert the mock was never called."
msgstr "Asserter que le simulacre n'a jamais été appelé."
#: library/unittest.mock.rst:397
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 :"
#: library/unittest.mock.rst:407
msgid "Added two keyword only argument to the reset_mock function."
msgstr "Ajout de deux arguments nommés à la fonction *reset_mock*."
#: library/unittest.mock.rst:410
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."
#: library/unittest.mock.rst:418
msgid "*return_value*, and :attr:`side_effect` are keyword only argument."
msgstr ""
"*return_value*, et :attr:`side_effect` sont utilisable uniquement par "
"arguments nommés."
#: library/unittest.mock.rst:424
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."
#: library/unittest.mock.rst:428
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."
#: library/unittest.mock.rst:433
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."
#: library/unittest.mock.rst:440
msgid "Set attributes on the mock through keyword arguments."
msgstr "Définir les attributs sur le simulacre à l'aide d'arguments nommés."
#: library/unittest.mock.rst:442
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 :"
#: library/unittest.mock.rst:456
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 :"
#: library/unittest.mock.rst:469
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."
#: library/unittest.mock.rst:475
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."
#: library/unittest.mock.rst:479
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."
#: library/unittest.mock.rst:485
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."
#: library/unittest.mock.rst:490
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)."
#: library/unittest.mock.rst:496
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 :"
#: library/unittest.mock.rst:507
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é :"
#: library/unittest.mock.rst:519
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 :"
#: library/unittest.mock.rst:526
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 :"
#: library/unittest.mock.rst:535
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 :"
#: library/unittest.mock.rst:546
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."
#: library/unittest.mock.rst:549
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`)."
#: library/unittest.mock.rst:555
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)."
#: library/unittest.mock.rst:560
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) :"
#: library/unittest.mock.rst:570
msgid "Using :attr:`side_effect` to return a sequence of values:"
msgstr "Utiliser :attr:`side_effect` pour renvoyer une séquence de valeurs :"
#: library/unittest.mock.rst:577
msgid "Using a callable:"
msgstr "Utilisation d'un objet appelable :"
#: library/unittest.mock.rst:587
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 :"
#: library/unittest.mock.rst:597
msgid "Setting :attr:`side_effect` to ``None`` clears it:"
msgstr "Positionner :attr:`side_effect` sur ``None`` l'efface :"
#: library/unittest.mock.rst:611
#, fuzzy
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 "
"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)."
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)."
#: library/unittest.mock.rst:644
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>`."
#: library/unittest.mock.rst:650
msgid "Added ``args`` and ``kwargs`` properties."
msgstr ""
#: library/unittest.mock.rst:656
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:672
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:679
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:690
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:697
msgid ""
":attr:`mock_calls` records *all* calls to the mock object, its methods, "
"magic methods *and* return value mocks."
msgstr ""
#: library/unittest.mock.rst:715
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:721
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:735
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:744
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:754
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:758
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:768
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:771
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:782
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:797
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:810
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:815
msgid "Added signature introspection on specced and autospecced mock objects."
msgstr ""
#: library/unittest.mock.rst:821
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:825
msgid ""
"Fetching a :class:`PropertyMock` instance from an object calls the mock, "
"with no args. Setting it calls the mock with the value being set. ::"
msgstr ""
#: library/unittest.mock.rst:846
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:860
msgid ""
"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."
msgstr ""
#: library/unittest.mock.rst:870
msgid ""
"The result of ``mock()`` is an async function which will have the outcome of "
"``side_effect`` or ``return_value`` after it has been awaited:"
msgstr ""
#: library/unittest.mock.rst:873
msgid ""
"if ``side_effect`` is a function, the async function will return the result "
"of that function,"
msgstr ""
#: library/unittest.mock.rst:875
msgid ""
"if ``side_effect`` is an exception, the async function will raise the "
"exception,"
msgstr ""
#: library/unittest.mock.rst:877
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, "
"``StopAsyncIteration`` is raised immediately,"
msgstr ""
#: library/unittest.mock.rst:880
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:885
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:897
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:925
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 ""
#: library/unittest.mock.rst:944
#, 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:960
#, 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:977
#, 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:994
#, 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:1010
#, 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:1013
#, fuzzy
msgid ""
"If *any_order* is false then the awaits must be sequential. There can be "
"extra calls before or after the specified awaits."
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:1017
#, fuzzy
msgid ""
"If *any_order* is true then the awaits can be in any order, but they must "
"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:1037
#, fuzzy
msgid "Assert that the mock was never awaited."
msgstr "Asserter que le simulacre n'a jamais été appelé."
#: library/unittest.mock.rst:1044
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:1049
#, 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:1064
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:1082
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:1101
msgid "Calling"
msgstr ""
#: library/unittest.mock.rst:1103
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:1109
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:1112
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:1116
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:1134
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:1150
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:1169
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:1183
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:1199
msgid ""
"If any members of the iterable are exceptions they will be raised instead of "
"returned::"
msgstr ""
#: library/unittest.mock.rst:1217
msgid "Deleting Attributes"
msgstr ""
#: library/unittest.mock.rst:1219
msgid ""
"Mock objects create attributes on demand. This allows them to pretend to be "
"objects of any type."
msgstr ""
#: library/unittest.mock.rst:1222
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:1226
msgid ""
"You \"block\" attributes by deleting them. Once deleted, accessing an "
"attribute will raise an :exc:`AttributeError`."
msgstr ""
#: library/unittest.mock.rst:1243
msgid "Mock names and the name attribute"
msgstr ""
#: library/unittest.mock.rst:1245
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:1255
msgid ""
"A simpler option is to simply set the \"name\" attribute after mock "
"creation::"
msgstr ""
#: library/unittest.mock.rst:1262
msgid "Attaching Mocks as Attributes"
msgstr ""
#: library/unittest.mock.rst:1264
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:1282
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:1293
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."
"attach_mock` method::"
msgstr ""
#: library/unittest.mock.rst:1311
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:1320
msgid "The patchers"
msgstr ""
#: library/unittest.mock.rst:1322
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:1329
msgid "patch"
msgstr ""
#: library/unittest.mock.rst:1333
msgid ""
"The key is to do the patching in the right namespace. See the section `where "
"to patch`_."
msgstr ""
#: library/unittest.mock.rst:1337
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:1342
msgid ""
"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."
msgstr ""
#: library/unittest.mock.rst:1350
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:1356
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:1359
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:1362
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:"
"`AsyncMock` is used for async functions and :class:`MagicMock` for the rest."
msgstr ""
#: library/unittest.mock.rst:1366
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:1376
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:1379
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 "
"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!"
msgstr ""
#: library/unittest.mock.rst:1389
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:1393
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:1400
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:1405
msgid ""
":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."
msgstr ""
#: library/unittest.mock.rst:1409
msgid ""
"``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are "
"available for alternate use-cases."
msgstr ""
#: library/unittest.mock.rst:1412
msgid ""
":func:`patch` as function decorator, creating the mock for you and passing "
"it into the decorated function::"
msgstr ""
#: library/unittest.mock.rst:1422
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:1426
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:1430
msgid ""
"To configure return values on methods of *instances* on the patched class "
"you must do this on the :attr:`return_value`. For example::"
msgstr ""
#: library/unittest.mock.rst:1444
msgid ""
"If you use *spec* or *spec_set* and :func:`patch` is replacing a *class*, "
"then the return value of the created mock will have the same spec. ::"
msgstr ""
#: library/unittest.mock.rst:1454
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, "
"if you wanted a :class:`NonCallableMock` to be used::"
msgstr ""
#: library/unittest.mock.rst:1467
msgid ""
"Another use case might be to replace an object with an :class:`io.StringIO` "
"instance::"
msgstr ""
#: library/unittest.mock.rst:1480
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 "
"call will be used to set attributes on the created mock::"
msgstr ""
#: library/unittest.mock.rst:1492
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 :"
"func:`patch` call using ``**``::"
msgstr ""
#: library/unittest.mock.rst:1508
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:1520
msgid ""
"but adding ``create=True`` in the call to :func:`patch` will make the "
"previous example work as expected::"
msgstr ""
#: library/unittest.mock.rst:1531
msgid ""
":func:`patch` now returns an :class:`AsyncMock` if the target is an async "
"function."
msgstr ""
#: library/unittest.mock.rst:1535
msgid "patch.object"
msgstr ""
#: library/unittest.mock.rst:1539
msgid ""
"patch the named member (*attribute*) on an object (*target*) with a mock "
"object."
msgstr ""
#: library/unittest.mock.rst:1542
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:1548
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:1551
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:1555
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:1566
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:1571
msgid "patch.dict"
msgstr ""
#: library/unittest.mock.rst:1575
msgid ""
"Patch a dictionary, or dictionary like object, and restore the dictionary to "
"its original state after the test."
msgstr ""
#: library/unittest.mock.rst:1578
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:1582
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:1585
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:1588
msgid ""
"If *clear* is true then the dictionary will be cleared before the new values "
"are set."
msgstr ""
#: library/unittest.mock.rst:1591
msgid ""
":func:`patch.dict` can also be called with arbitrary keyword arguments to "
"set values in the dictionary."
msgstr ""
#: library/unittest.mock.rst:1596
msgid ""
":func:`patch.dict` now returns the patched dictionary when used as a context "
"manager."
msgstr ""
#: library/unittest.mock.rst:1599
#, fuzzy
msgid ""
":func:`patch.dict` can be used as a context manager, decorator or class "
"decorator:"
msgstr ""
"Comme tout décorateur, :func:`patch` peut être utilisé comme gestionnaire de "
"contexte avec une instruction *with* ::"
#: library/unittest.mock.rst:1609
msgid ""
"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:1620
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`."
msgstr ""
#: library/unittest.mock.rst:1624
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:1645
msgid ""
"Keywords can be used in the :func:`patch.dict` call to set values in the "
"dictionary:"
msgstr ""
#: library/unittest.mock.rst:1655
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:1684
msgid "patch.multiple"
msgstr ""
#: library/unittest.mock.rst:1688
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:1695
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:1700
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:1705
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:1708
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 "
"keyword. ::"
msgstr ""
#: library/unittest.mock.rst:1722
msgid ""
":func:`patch.multiple` can be nested with other ``patch`` decorators, but "
"put arguments passed by keyword *after* any of the standard arguments "
"created by :func:`patch`::"
msgstr ""
#: library/unittest.mock.rst:1734
msgid ""
"If :func:`patch.multiple` is used as a context manager, the value returned "
"by the context manager is a dictionary where created mocks are keyed by "
"name::"
msgstr ""
#: library/unittest.mock.rst:1748
msgid "patch methods: start and stop"
msgstr ""
#: library/unittest.mock.rst:1750
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:1754
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:1758
msgid ""
"If you are using :func:`patch` to create a mock for you then it will be "
"returned by the call to ``patcher.start``. ::"
msgstr ""
#: library/unittest.mock.rst:1772
msgid ""
"A typical use case for this might be for doing multiple patches in the "
"``setUp`` method of a :class:`TestCase`::"
msgstr ""
#: library/unittest.mock.rst:1794
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:"
"`unittest.TestCase.addCleanup` makes this easier::"
msgstr ""
#: library/unittest.mock.rst:1809
msgid ""
"As an added bonus you no longer need to keep a reference to the ``patcher`` "
"object."
msgstr ""
#: library/unittest.mock.rst:1812
msgid ""
"It is also possible to stop all patches which have been started by using :"
"func:`patch.stopall`."
msgstr ""
#: library/unittest.mock.rst:1817
msgid "Stop all active patches. Only stops patches started with ``start``."
msgstr ""
#: library/unittest.mock.rst:1823
msgid "patch builtins"
msgstr ""
#: library/unittest.mock.rst:1824
msgid ""
"You can patch any builtins within a module. The following example patches "
"builtin :func:`ord`::"
msgstr ""
#: library/unittest.mock.rst:1839
msgid "TEST_PREFIX"
msgstr ""
#: library/unittest.mock.rst:1841
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:1846
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."
"TEST_PREFIX``::"
msgstr ""
#: library/unittest.mock.rst:1869
msgid "Nesting Patch Decorators"
msgstr ""
#: library/unittest.mock.rst:1871
msgid ""
"If you want to perform multiple patches then you can simply stack up the "
"decorators."
msgstr ""
#: library/unittest.mock.rst:1874
msgid "You can stack up multiple patch decorators using this pattern:"
msgstr ""
#: library/unittest.mock.rst:1890
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:1898
msgid "Where to patch"
msgstr ""
#: library/unittest.mock.rst:1900
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:1905
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:1909
msgid ""
"Imagine we have a project that we want to test with the following structure::"
msgstr ""
#: library/unittest.mock.rst:1918
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:1925
msgid ""
"The key is to patch out ``SomeClass`` where it is used (or where it is "
"looked up). In this case ``some_function`` will actually look up "
"``SomeClass`` in module b, where we have imported it. The patching should "
"look like::"
msgstr ""
#: library/unittest.mock.rst:1931
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:1940
msgid "Patching Descriptors and Proxy Objects"
msgstr ""
#: library/unittest.mock.rst:1942
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 <http://www."
"voidspace.org.uk/python/weblog/arch_d7_2010_12_04.shtml#e1198>`_."
msgstr ""
#: library/unittest.mock.rst:1950
msgid "MagicMock and magic method support"
msgstr ""
#: library/unittest.mock.rst:1955
msgid "Mocking Magic Methods"
msgstr ""
#: library/unittest.mock.rst:1957
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:1961
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:1966
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:1989
msgid ""
"One use case for this is for mocking objects used as context managers in a :"
"keyword:`with` statement:"
msgstr ""
#: library/unittest.mock.rst:2001
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:2006
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:2009
msgid "The full list of supported magic methods is:"
msgstr ""
#: library/unittest.mock.rst:2011
msgid "``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__``"
msgstr ""
#: library/unittest.mock.rst:2012
msgid "``__dir__``, ``__format__`` and ``__subclasses__``"
msgstr "``__dir__``, ``__format__`` et ``__subclasses__``"
#: library/unittest.mock.rst:2013
#, fuzzy
msgid "``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__``"
msgstr "``__floor__``, ``__trunc__`` et ``__ceil__``"
#: library/unittest.mock.rst:2014
msgid ""
"Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``, ``__eq__`` and "
"``__ne__``"
msgstr ""
#: library/unittest.mock.rst:2016
msgid ""
"Container methods: ``__getitem__``, ``__setitem__``, ``__delitem__``, "
"``__contains__``, ``__len__``, ``__iter__``, ``__reversed__`` and "
"``__missing__``"
msgstr ""
#: library/unittest.mock.rst:2019
#, fuzzy
msgid ""
"Context manager: ``__enter__``, ``__exit__``, ``__aenter__`` and "
"``__aexit__``"
msgstr "``__get__``, ``__set__`` et ``__delete__``"
#: library/unittest.mock.rst:2020
msgid "Unary numeric methods: ``__neg__``, ``__pos__`` and ``__invert__``"
msgstr ""
#: library/unittest.mock.rst:2021
msgid ""
"The numeric methods (including right hand and in-place variants): "
"``__add__``, ``__sub__``, ``__mul__``, ``__matmul__``, ``__div__``, "
"``__truediv__``, ``__floordiv__``, ``__mod__``, ``__divmod__``, "
"``__lshift__``, ``__rshift__``, ``__and__``, ``__xor__``, ``__or__``, and "
"``__pow__``"
msgstr ""
#: library/unittest.mock.rst:2025
msgid ""
"Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__`` and "
"``__index__``"
msgstr ""
#: library/unittest.mock.rst:2027
msgid "Descriptor methods: ``__get__``, ``__set__`` and ``__delete__``"
msgstr ""
#: library/unittest.mock.rst:2028
msgid ""
"Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, "
"``__getnewargs__``, ``__getstate__`` and ``__setstate__``"
msgstr ""
#: library/unittest.mock.rst:2030
msgid "File system path representation: ``__fspath__``"
msgstr ""
#: library/unittest.mock.rst:2031
msgid "Asynchronous iteration methods: ``__aiter__`` and ``__anext__``"
msgstr ""
#: library/unittest.mock.rst:2033
msgid "Added support for :func:`os.PathLike.__fspath__`."
msgstr ""
#: library/unittest.mock.rst:2036
msgid ""
"Added support for ``__aenter__``, ``__aexit__``, ``__aiter__`` and "
"``__anext__``."
msgstr ""
#: library/unittest.mock.rst:2040
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:2043
msgid "``__getattr__``, ``__setattr__``, ``__init__`` and ``__new__``"
msgstr ""
#: library/unittest.mock.rst:2044
msgid ""
"``__prepare__``, ``__instancecheck__``, ``__subclasscheck__``, ``__del__``"
msgstr ""
#: library/unittest.mock.rst:2049
msgid "Magic Mock"
msgstr ""
#: library/unittest.mock.rst:2051
msgid ""
"There are two ``MagicMock`` variants: :class:`MagicMock` and :class:"
"`NonCallableMagicMock`."
msgstr ""
#: library/unittest.mock.rst:2056
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:2060
msgid "The constructor parameters have the same meaning as for :class:`Mock`."
msgstr ""
#: library/unittest.mock.rst:2062
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:2068
msgid "A non-callable version of :class:`MagicMock`."
msgstr ""
#: library/unittest.mock.rst:2070
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:2074
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:2084
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:2090
msgid "Methods and their defaults:"
msgstr ""
#: library/unittest.mock.rst:2092
msgid "``__lt__``: ``NotImplemented``"
msgstr "``__lt__``: ``NotImplemented``"
#: library/unittest.mock.rst:2093
msgid "``__gt__``: ``NotImplemented``"
msgstr "``__gt__``: ``NotImplemented``"
#: library/unittest.mock.rst:2094
msgid "``__le__``: ``NotImplemented``"
msgstr "``__le__``: ``NotImplemented``"
#: library/unittest.mock.rst:2095
msgid "``__ge__``: ``NotImplemented``"
msgstr "``__ge__``: ``NotImplemented``"
#: library/unittest.mock.rst:2096
msgid "``__int__``: ``1``"
msgstr "``__int__``: ``1``"
#: library/unittest.mock.rst:2097
msgid "``__contains__``: ``False``"
msgstr "``__contains__``: ``False``"
#: library/unittest.mock.rst:2098
msgid "``__len__``: ``0``"
msgstr "``__int__``: ``0``"
#: library/unittest.mock.rst:2099
msgid "``__iter__``: ``iter([])``"
msgstr "``__iter__``: ``iter([])``"
#: library/unittest.mock.rst:2100
msgid "``__exit__``: ``False``"
msgstr "``__exit__``: ``False``"
#: library/unittest.mock.rst:2101
msgid "``__aexit__``: ``False``"
msgstr "``__exit__``: ``False``"
#: library/unittest.mock.rst:2102
msgid "``__complex__``: ``1j``"
msgstr "``__complex__``: ``1j``"
#: library/unittest.mock.rst:2103
msgid "``__float__``: ``1.0``"
msgstr "``__float__``: ``1.0``"
#: library/unittest.mock.rst:2104
msgid "``__bool__``: ``True``"
msgstr "``__bool__``: ``True``"
#: library/unittest.mock.rst:2105
msgid "``__index__``: ``1``"
msgstr "``__index__``: ``1``"
#: library/unittest.mock.rst:2106
msgid "``__hash__``: default hash for the mock"
msgstr ""
#: library/unittest.mock.rst:2107
msgid "``__str__``: default str for the mock"
msgstr ""
#: library/unittest.mock.rst:2108
msgid "``__sizeof__``: default sizeof for the mock"
msgstr ""
#: library/unittest.mock.rst:2110
msgid "For example:"
msgstr "Par exemple :"
#: library/unittest.mock.rst:2122
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:2136
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:2146
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:2155
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:2158
msgid ""
"Magic methods that are supported but not setup by default in ``MagicMock`` "
"are:"
msgstr ""
#: library/unittest.mock.rst:2160
msgid "``__subclasses__``"
msgstr "``__subclasses__``"
#: library/unittest.mock.rst:2161
msgid "``__dir__``"
msgstr "``__dir__``"
#: library/unittest.mock.rst:2162
msgid "``__format__``"
msgstr "``__format__``"
#: library/unittest.mock.rst:2163
msgid "``__get__``, ``__set__`` and ``__delete__``"
msgstr "``__get__``, ``__set__`` et ``__delete__``"
#: library/unittest.mock.rst:2164
msgid "``__reversed__`` and ``__missing__``"
msgstr "``__reversed__`` et ``__missing__``"
#: library/unittest.mock.rst:2165
msgid ""
"``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, ``__getnewargs__``, "
"``__getstate__`` and ``__setstate__``"
msgstr ""
#: library/unittest.mock.rst:2167
msgid "``__getformat__`` and ``__setformat__``"
msgstr "``__getformat__`` et ``__setformat__``"
#: library/unittest.mock.rst:2171
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:2175
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:2180
msgid "Helpers"
msgstr ""
#: library/unittest.mock.rst:2183
msgid "sentinel"
msgstr ""
#: library/unittest.mock.rst:2187
msgid ""
"The ``sentinel`` object provides a convenient way of providing unique "
"objects for your tests."
msgstr ""
#: library/unittest.mock.rst:2190
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:2194
msgid ""
"The ``sentinel`` attributes now preserve their identity when they are :mod:"
"`copied <copy>` or :mod:`pickled <pickle>`."
msgstr ""
#: library/unittest.mock.rst:2198
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:2203
msgid ""
"In this example we monkey patch ``method`` to return ``sentinel."
"some_object``:"
msgstr ""
#: library/unittest.mock.rst:2215
msgid "DEFAULT"
msgstr ""
#: library/unittest.mock.rst:2220
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:2226
msgid "call"
msgstr ""
#: library/unittest.mock.rst:2230
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:2243
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:2247
msgid ""
"``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 "
"constructing the sequence of calls can be tedious."
msgstr ""
#: library/unittest.mock.rst:2252
msgid ""
":meth:`~call.call_list` can construct the sequence of calls from the same "
"chained call:"
msgstr ""
#: library/unittest.mock.rst:2269
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:2276
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:2281
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:2314
msgid "create_autospec"
msgstr ""
#: library/unittest.mock.rst:2318
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:2322
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:2325
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:2328
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:2333
msgid ""
":func:`create_autospec` also takes arbitrary keyword arguments that are "
"passed to the constructor of the created mock."
msgstr ""
#: library/unittest.mock.rst:2336
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:2342
msgid ""
":func:`create_autospec` now returns an :class:`AsyncMock` if the target is "
"an async function."
msgstr ""
#: library/unittest.mock.rst:2347
msgid "ANY"
msgstr ""
#: library/unittest.mock.rst:2351
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:2356
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:2365
msgid ""
":data:`ANY` can also be used in comparisons with call lists like :attr:"
"`~Mock.mock_calls`:"
msgstr ""
#: library/unittest.mock.rst:2378
msgid "FILTER_DIR"
msgstr ""
#: library/unittest.mock.rst:2382
msgid ""
":data:`FILTER_DIR` is a module level variable that controls the way mock "
"objects respond to :func:`dir` (only for Python 2.6 or more recent). 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``."
msgstr ""
#: library/unittest.mock.rst:2388
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:2415
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:2436
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:2442
msgid "mock_open"
msgstr ""
#: library/unittest.mock.rst:2446
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:2449
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:2453
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 "
"in-memory filesystem packages on `PyPI <https://pypi.org>`_ can offer a "
"realistic filesystem for testing."
msgstr ""
#: library/unittest.mock.rst:2463
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:2468
msgid "*read_data* is now reset on each call to the *mock*."
msgstr ""
#: library/unittest.mock.rst:2471
msgid ""
"Added :meth:`__iter__` to implementation so that iteration (such as in for "
"loops) correctly consumes *read_data*."
msgstr ""
#: library/unittest.mock.rst:2475
msgid ""
"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:2481
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:2485
msgid ""
"Mocking context managers with a :class:`MagicMock` is common enough and "
"fiddly enough that a helper function is useful. ::"
msgstr ""
#: library/unittest.mock.rst:2502
msgid "And for reading files::"
msgstr ""
#: library/unittest.mock.rst:2515
msgid "Autospeccing"
msgstr ""
#: library/unittest.mock.rst:2517
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:2524
msgid "Before I explain how auto-speccing works, here's why it is needed."
msgstr ""
#: library/unittest.mock.rst:2526
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:2531
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:2544
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:2554
msgid "Your tests can pass silently and incorrectly because of the typo."
msgstr ""
#: library/unittest.mock.rst:2556
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:2561
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:2566
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:2577
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:2586
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:2595
msgid "Here's an example of it in use::"
msgstr ""
#: library/unittest.mock.rst:2605
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*). "
"Here's what happens if we try to call it incorrectly::"
msgstr ""
#: library/unittest.mock.rst:2614
msgid ""
"The spec also applies to instantiated classes (i.e. the return value of "
"specced mocks)::"
msgstr ""
#: library/unittest.mock.rst:2621
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 "
"error::"
msgstr ""
#: library/unittest.mock.rst:2633
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:2637
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:2645
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:2654
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 "
"the api to visible attributes. ::"
msgstr ""
#: library/unittest.mock.rst:2671
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 "
"setting them::"
msgstr ""
#: library/unittest.mock.rst:2682
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:2695
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:2705
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:2720
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 "
"alternative object as the *autospec* argument::"
msgstr ""
#: library/unittest.mock.rst:2741
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 ""
#: library/unittest.mock.rst:2746
msgid "Sealing mocks"
msgstr ""
#: library/unittest.mock.rst:2755
msgid ""
"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."
msgstr ""
#: library/unittest.mock.rst:2758
msgid ""
"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 "
"from fixing part of the mock object. ::"
msgstr ""