Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
fb13438a
Kaydet (Commit)
fb13438a
authored
Şub 03, 2013
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes #17109: fix heading levels in mock doc.
üst
09aa7520
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
23 deletions
+22
-23
unittest.mock.rst
Doc/library/unittest.mock.rst
+22
-23
No files found.
Doc/library/unittest.mock.rst
Dosyayı görüntüle @
fb13438a
...
@@ -926,7 +926,7 @@ method:
...
@@ -926,7 +926,7 @@ method:
The patchers
The patchers
============
------------
The patch decorators are used for patching objects only within the scope of
The patch decorators are used for patching objects only within the scope of
the function they decorate. They automatically handle the unpatching for you,
the function they decorate. They automatically handle the unpatching for you,
...
@@ -935,7 +935,7 @@ statements or as class decorators.
...
@@ -935,7 +935,7 @@ statements or as class decorators.
patch
patch
-----
~~~~~
.. note::
.. note::
...
@@ -1108,7 +1108,7 @@ into a `patch` call using `**`:
...
@@ -1108,7 +1108,7 @@ into a `patch` call using `**`:
patch.object
patch.object
------------
~~~~~~~~~~~~
.. function:: patch.object(target, attribute, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
.. function:: patch.object(target, attribute, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
...
@@ -1144,7 +1144,7 @@ meaning as they do for `patch`.
...
@@ -1144,7 +1144,7 @@ meaning as they do for `patch`.
patch.dict
patch.dict
----------
~~~~~~~~~~
.. function:: patch.dict(in_dict, values=(), clear=False, **kwargs)
.. function:: patch.dict(in_dict, values=(), clear=False, **kwargs)
...
@@ -1227,7 +1227,7 @@ magic methods `__getitem__`, `__setitem__`, `__delitem__` and either
...
@@ -1227,7 +1227,7 @@ magic methods `__getitem__`, `__setitem__`, `__delitem__` and either
patch.multiple
patch.multiple
--------------
~~~~~~~~~~~~~~
.. function:: patch.multiple(target, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
.. function:: patch.multiple(target, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
...
@@ -1291,7 +1291,7 @@ context manger is a dictionary where created mocks are keyed by name:
...
@@ -1291,7 +1291,7 @@ context manger is a dictionary where created mocks are keyed by name:
.. _start-and-stop:
.. _start-and-stop:
patch methods: start and stop
patch methods: start and stop
-----------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All the patchers have `start` and `stop` methods. These make it simpler to do
All the patchers have `start` and `stop` methods. These make it simpler to do
patching in `setUp` methods or where you want to do multiple patches without
patching in `setUp` methods or where you want to do multiple patches without
...
@@ -1364,7 +1364,7 @@ It is also possible to stop all patches which have been started by using
...
@@ -1364,7 +1364,7 @@ It is also possible to stop all patches which have been started by using
TEST_PREFIX
TEST_PREFIX
-----------
~~~~~~~~~~~
All of the patchers can be used as class decorators. When used in this way
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
they wrap every test method on the class. The patchers recognise methods that
...
@@ -1394,7 +1394,7 @@ inform the patchers of the different prefix by setting `patch.TEST_PREFIX`:
...
@@ -1394,7 +1394,7 @@ inform the patchers of the different prefix by setting `patch.TEST_PREFIX`:
Nesting Patch Decorators
Nesting Patch Decorators
------------------------
~~~~~~~~~~~~~~~~~~~~~~~~
If you want to perform multiple patches then you can simply stack up the
If you want to perform multiple patches then you can simply stack up the
decorators.
decorators.
...
@@ -1423,7 +1423,7 @@ passed into your test function matches this order.
...
@@ -1423,7 +1423,7 @@ passed into your test function matches this order.
.. _where-to-patch:
.. _where-to-patch:
Where to patch
Where to patch
--------------
~~~~~~~~~~~~~~
`patch` works by (temporarily) changing the object that a *name* points to with
`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
another one. There can be many names pointing to any individual object, so
...
@@ -1465,7 +1465,7 @@ being looked up on the a module and so we have to patch `a.SomeClass` instead::
...
@@ -1465,7 +1465,7 @@ being looked up on the a module and so we have to patch `a.SomeClass` instead::
Patching Descriptors and Proxy Objects
Patching Descriptors and Proxy Objects
--------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Both patch_ and patch.object_ correctly patch and restore descriptors: class
Both patch_ and patch.object_ correctly patch and restore descriptors: class
methods, static methods and properties. You should patch these on the *class*
methods, static methods and properties. You should patch these on the *class*
...
@@ -1475,12 +1475,12 @@ that proxy attribute access, like the `django setttings object
...
@@ -1475,12 +1475,12 @@ that proxy attribute access, like the `django setttings object
MagicMock and magic method support
MagicMock and magic method support
==================================
----------------------------------
.. _magic-methods:
.. _magic-methods:
Mocking Magic Methods
Mocking Magic Methods
---------------------
~~~~~~~~~~~~~~~~~~~~~
:class:`Mock` supports mocking the Python protocol methods, also known as
:class:`Mock` supports mocking the Python protocol methods, also known as
"magic methods". This allows mock objects to replace containers or other
"magic methods". This allows mock objects to replace containers or other
...
@@ -1566,7 +1566,7 @@ by mock, can't be set dynamically, or can cause problems:
...
@@ -1566,7 +1566,7 @@ by mock, can't be set dynamically, or can cause problems:
Magic Mock
Magic Mock
----------
~~~~~~~~~~
There are two `MagicMock` variants: `MagicMock` and `NonCallableMagicMock`.
There are two `MagicMock` variants: `MagicMock` and `NonCallableMagicMock`.
...
@@ -1695,10 +1695,10 @@ Magic methods that are supported but not setup by default in ``MagicMock`` are:
...
@@ -1695,10 +1695,10 @@ Magic methods that are supported but not setup by default in ``MagicMock`` are:
Helpers
Helpers
=======
-------
sentinel
sentinel
--------
~~~~~~~~
.. data:: sentinel
.. data:: sentinel
...
@@ -1726,7 +1726,7 @@ In this example we monkey patch `method` to return `sentinel.some_object`:
...
@@ -1726,7 +1726,7 @@ In this example we monkey patch `method` to return `sentinel.some_object`:
DEFAULT
DEFAULT
-------
~~~~~~~
.. data:: DEFAULT
.. data:: DEFAULT
...
@@ -1736,9 +1736,8 @@ DEFAULT
...
@@ -1736,9 +1736,8 @@ DEFAULT
functions to indicate that the normal return value should be used.
functions to indicate that the normal return value should be used.
call
call
----
~~~~
.. function:: call(*args, **kwargs)
.. function:: call(*args, **kwargs)
...
@@ -1827,7 +1826,7 @@ arguments are a dictionary:
...
@@ -1827,7 +1826,7 @@ arguments are a dictionary:
create_autospec
create_autospec
---------------
~~~~~~~~~~~~~~~
.. function:: create_autospec(spec, spec_set=False, instance=False, **kwargs)
.. function:: create_autospec(spec, spec_set=False, instance=False, **kwargs)
...
@@ -1854,7 +1853,7 @@ See :ref:`auto-speccing` for examples of how to use auto-speccing with
...
@@ -1854,7 +1853,7 @@ See :ref:`auto-speccing` for examples of how to use auto-speccing with
ANY
ANY
---
~~~
.. data:: ANY
.. data:: ANY
...
@@ -1885,7 +1884,7 @@ passed in.
...
@@ -1885,7 +1884,7 @@ passed in.
FILTER_DIR
FILTER_DIR
----------
~~~~~~~~~~
.. data:: FILTER_DIR
.. data:: FILTER_DIR
...
@@ -1940,7 +1939,7 @@ Alternatively you can just use `vars(my_mock)` (instance members) and
...
@@ -1940,7 +1939,7 @@ Alternatively you can just use `vars(my_mock)` (instance members) and
mock_open
mock_open
---------
~~~~~~~~~
.. function:: mock_open(mock=None, read_data=None)
.. function:: mock_open(mock=None, read_data=None)
...
@@ -1994,7 +1993,7 @@ And for reading files:
...
@@ -1994,7 +1993,7 @@ And for reading files:
.. _auto-speccing:
.. _auto-speccing:
Autospeccing
Autospeccing
------------
~~~~~~~~~~~~
Autospeccing is based on the existing `spec` feature of mock. It limits the
Autospeccing is based on the existing `spec` feature of mock. It limits the
api of mocks to the api of an original object (the spec), but it is recursive
api of mocks to the api of an original object (the spec), but it is recursive
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment