diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 11966b7545..cceb36be21 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -7,7 +7,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-12-16 00:03+0000\n" -"PO-Revision-Date: 2024-01-24 18:03+0800\n" +"PO-Revision-Date: 2024-02-19 21:27+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -16,7 +16,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Poedit 3.4.2\n" +"X-Generator: Poedit 3.4.1\n" #: ../../library/unittest.mock.rst:3 msgid ":mod:`unittest.mock` --- mock object library" @@ -131,8 +131,8 @@ msgid "" "above the mock for ``module.ClassName1`` is passed in first." msgstr "" "當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相" -"同(一般 *Python* 應用裝飾器的順序)。這意味著由下而上,因此在上面的範例" -"中,``module.ClassName1`` 的 mock 會先被傳入。" +"同(一般 *Python* 應用裝飾器的順序)。這意味著由下而上,因此在上面的範例中," +"``module.ClassName1`` 的 mock 會先被傳入。" #: ../../library/unittest.mock.rst:122 msgid "" @@ -1794,6 +1794,7 @@ msgid "" "You can patch any builtins within a module. The following example patches " "builtin :func:`ord`::" msgstr "" +"你可以 patch 模組內的任何內建函式。以下範例 patch 內建函式 :func:`ord`: ::" #: ../../library/unittest.mock.rst:1844 msgid "TEST_PREFIX" @@ -1806,6 +1807,9 @@ msgid "" "that start with ``'test'`` as being test methods. This is the same way that " "the :class:`unittest.TestLoader` finds test methods by default." msgstr "" +"所有 patcher 都可以作為類別裝飾器使用。以這種方式使用時,它們包裝了類別上的每" +"個測試方法。Patcher 將 ``'test'`` 開頭的方法認定為測試方法。這與 :class:" +"`unittest.TestLoader` 預設尋找測試方法的方式相同。" #: ../../library/unittest.mock.rst:1851 msgid "" @@ -1813,20 +1817,22 @@ msgid "" "can inform the patchers of the different prefix by setting ``patch." "TEST_PREFIX``::" msgstr "" +"你可能會想為你的測試使用不同的前綴。你可以透過設定 ``patch.TEST_PREFIX`` 來告" +"知 patcher 使用不同的前綴: ::" #: ../../library/unittest.mock.rst:1874 msgid "Nesting Patch Decorators" -msgstr "" +msgstr "巢狀使用 Patch 裝飾器" #: ../../library/unittest.mock.rst:1876 msgid "" "If you want to perform multiple patches then you can simply stack up the " "decorators." -msgstr "" +msgstr "如果你想執行多個 patch,那麼你可以簡單地堆疊裝飾器。" #: ../../library/unittest.mock.rst:1879 msgid "You can stack up multiple patch decorators using this pattern:" -msgstr "" +msgstr "你可以使用這個模式來堆疊多個 patch 裝飾器:" #: ../../library/unittest.mock.rst:1895 msgid "" @@ -1834,10 +1840,12 @@ msgid "" "standard way that Python applies decorators. The order of the created mocks " "passed into your test function matches this order." msgstr "" +"請注意,裝飾器是從底部向上應用的。這是 Python 應用裝飾器的標準方式。被建立的 " +"mock 傳遞到測試函式中的順序與此順序相同。" #: ../../library/unittest.mock.rst:1903 msgid "Where to patch" -msgstr "" +msgstr "該 patch 何處" #: ../../library/unittest.mock.rst:1905 msgid "" @@ -1846,6 +1854,9 @@ msgid "" "individual object, so for patching to work you must ensure that you patch " "the name used by the system under test." msgstr "" +":func:`patch` 的工作原理是(暫時)將 *name* 指向的物件變更為另一個物件。可以" +"有許多 name 指向任何單一物件,因此為了使 patch 起作用,你必須確保你 patch 了" +"被測試系統使用的 name。" #: ../../library/unittest.mock.rst:1910 msgid "" @@ -1853,11 +1864,13 @@ msgid "" "is not necessarily the same place as where it is defined. A couple of " "examples will help to clarify this." msgstr "" +"基本原則是在物件\\ *被查找*\\ 的位置進行 patch,該位置不一定與其被定義的位置" +"相同。幾個範例將有助於闡明這一點。" #: ../../library/unittest.mock.rst:1914 msgid "" "Imagine we have a project that we want to test with the following structure::" -msgstr "" +msgstr "想像一下,我們想要測試一個專案,其結構如下: ::" #: ../../library/unittest.mock.rst:1923 msgid "" @@ -1868,6 +1881,11 @@ msgid "" "module b already has a reference to the *real* ``SomeClass`` and it looks " "like our patching had no effect." msgstr "" +"現在我們想要測試 ``some_function``,但我們想使用 :func:`patch` mock " +"``SomeClass``。問題是,當我們 import 模組 b 時(我們必須這樣做),它會從模組 " +"a import ``SomeClass``。如果我們使用 :func:`patch` 來 mock ``a.SomeClass``," +"那麼它對我們的測試就不會有任何影響;模組 b 已經有了一個\\ *真實的*\\ " +"``SomeClass`` 的參照 ,看起來我們的 patch 並沒有任何效果。" #: ../../library/unittest.mock.rst:1930 msgid "" @@ -1876,6 +1894,9 @@ msgid "" "``SomeClass`` in module b, where we have imported it. The patching should " "look like::" msgstr "" +"關鍵是在使用(或查找它)的地方 patch ``SomeClass``。在這個情況下," +"``some_function`` 實際上會在我們 import 它的模組 b 中查找``SomeClass``。這裡" +"的 patch 應該長得像這樣: ::" #: ../../library/unittest.mock.rst:1936 msgid "" @@ -1885,10 +1906,14 @@ msgid "" "we want to patch is being looked up in the module and so we have to patch " "``a.SomeClass`` instead::" msgstr "" +"然而,考慮另一種情況,其中模組 b 並不是使用 ``from a import SomeClass``,而" +"是 ``import a``,然後 ``some_function`` 使用 ``a.SomeClass``。這兩種 import " +"形式都很常見。在這種情況下,我們想要 patch 的類別正在其模組中被查找,因此我們" +"必須 patch ``a.SomeClass``: ::" #: ../../library/unittest.mock.rst:1945 msgid "Patching Descriptors and Proxy Objects" -msgstr "" +msgstr "Patch 描述器與代理物件 (Proxy Objects)" #: ../../library/unittest.mock.rst:1947 msgid "" @@ -1899,14 +1924,19 @@ msgid "" "archive.org/web/20200603181648/http://www.voidspace.org.uk/python/weblog/" "arch_d7_2010_12_04.shtml#e1198>`_." msgstr "" +"patch_ 和 patch.object_ 都正確地 patch 和還原描述器:類別方法、靜態方法以及屬" +"性。你應該在 *類別* 而不是實例上 patch 它們。它們還可以使用代理屬性存取的\\ *" +"一些*\\ 物件,例如 `django 設定物件 `_。" #: ../../library/unittest.mock.rst:1955 msgid "MagicMock and magic method support" -msgstr "" +msgstr "MagicMock 以及魔術方法支援" #: ../../library/unittest.mock.rst:1960 msgid "Mocking Magic Methods" -msgstr "" +msgstr "Mock 魔術方法" #: ../../library/unittest.mock.rst:1962 msgid "" @@ -1914,6 +1944,8 @@ msgid "" "term:`\"magic methods\" `. This allows mock objects to replace " "containers or other objects that implement Python protocols." msgstr "" +":class:`Mock` 支援 mock Python 協定方法,其也被稱作 :term:`\"魔術方法\" " +"`。這允許 mock 物件替換容器或實作 Python 協定的其他物件。" #: ../../library/unittest.mock.rst:1966 msgid "" @@ -1922,6 +1954,9 @@ msgid "" "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 "" +"由於魔術方法被查找的方式與一般的方法 [#]_ 不同,因此專門實作了此支援方式。這" +"代表著僅有特定的魔術方法被此方式支援。現在已支援清單中已經\\ *幾乎*\\ 包含了" +"所有魔術方法。如果你需要 mock 任何魔術方法而其尚未被支援,請讓我們知道。" #: ../../library/unittest.mock.rst:1971 msgid "" @@ -1929,18 +1964,22 @@ msgid "" "function or a mock instance. If you are using a function then it *must* take " "``self`` as the first argument [#]_." msgstr "" +"你可以透過將你感興趣的方法設定為函式或 mock 實例來 mock 魔術方法。如果你使用" +"函式,那麼它\\ *必須*\\ 將 ``self`` 作為第一個引數 [#]_。" #: ../../library/unittest.mock.rst:1994 msgid "" "One use case for this is for mocking objects used as context managers in a :" "keyword:`with` statement:" -msgstr "" +msgstr "一個用法是在 :keyword:`with` 陳述式中 mock 作為情境管理器使用的物件:" #: ../../library/unittest.mock.rst:2006 msgid "" "Calls to magic methods do not appear in :attr:`~Mock.method_calls`, but they " "are recorded in :attr:`~Mock.mock_calls`." msgstr "" +"對魔術方法的呼叫並不會出現在 :attr:`~Mock.method_calls` 中,它們會被記錄在 :" +"attr:`~Mock.mock_calls` 內。" #: ../../library/unittest.mock.rst:2011 msgid "" @@ -1948,29 +1987,32 @@ msgid "" "set a magic method that isn't in the spec will raise an :exc:" "`AttributeError`." msgstr "" +"如果你使用\\ *spec*\\ 關鍵字引數來建立一個 mock,則嘗試設定規格中未包含的魔術" +"方法將引發一個 :exc:`AttributeError`。" #: ../../library/unittest.mock.rst:2014 msgid "The full list of supported magic methods is:" -msgstr "" +msgstr "已支援的魔術方法的完整列表是:" #: ../../library/unittest.mock.rst:2016 msgid "``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__``" -msgstr "``__hash__``\\ 、\\ ``__sizeof__``\\ 、\\ ``__repr__`` 和 ``__str__``" +msgstr "``__hash__``、``__sizeof__``、 ``__repr__`` 和 ``__str__``" #: ../../library/unittest.mock.rst:2017 msgid "``__dir__``, ``__format__`` and ``__subclasses__``" -msgstr "``__dir__``\\ 、\\ ``__format__`` 和 ``__subclasses__``" +msgstr "``__dir__``、 ``__format__`` 和 ``__subclasses__``" #: ../../library/unittest.mock.rst:2018 msgid "``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__``" -msgstr "" -"``__round__``\\ 、\\ ``__floor__``\\ 、\\ ``__trunc__`` 和 ``__ceil__``" +msgstr "``__round__``、``__floor__``、``__trunc__`` 和 ``__ceil__``" #: ../../library/unittest.mock.rst:2019 msgid "" "Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``, ``__eq__`` and " "``__ne__``" msgstr "" +"比較方法:``__lt__``、``__gt__``、``__le__``、``__ge__``、``__eq__`` 和 " +"``__ne__``" #: ../../library/unittest.mock.rst:2021 msgid "" @@ -1978,16 +2020,20 @@ msgid "" "``__contains__``, ``__len__``, ``__iter__``, ``__reversed__`` and " "``__missing__``" msgstr "" +"容器方法:``__getitem__``、``__setitem__``、``__delitem__``、" +"``__contains__``、``__len__``、``__iter__``、``__reversed__`` 和 " +"``__missing__``" #: ../../library/unittest.mock.rst:2024 msgid "" "Context manager: ``__enter__``, ``__exit__``, ``__aenter__`` and " "``__aexit__``" msgstr "" +"情境管理器:``__enter__``、``__exit__``、``__aenter__`` 和 ``__aexit__``" #: ../../library/unittest.mock.rst:2025 msgid "Unary numeric methods: ``__neg__``, ``__pos__`` and ``__invert__``" -msgstr "" +msgstr "一元數值方法:``__neg__``、``__pos__`` 和 ``__invert__``" #: ../../library/unittest.mock.rst:2026 msgid "" @@ -1996,68 +2042,79 @@ msgid "" "``__floordiv__``, ``__mod__``, ``__divmod__``, ``__lshift__``, " "``__rshift__``, ``__and__``, ``__xor__``, ``__or__``, and ``__pow__``" msgstr "" +"數值方法(包括右側 (right hand) 和原地 (in-place) 變體):``__add__``、" +"``__sub__``、``__mul__``、``__matmul__``、``__truediv__``、" +"``__floordiv__``、 `` __mod__``、``__divmod__``、``__lshift__``、" +"``__rshift__``、``__and__``、``__xor__``、``__or__`` 和 ``__pow__``" #: ../../library/unittest.mock.rst:2030 msgid "" "Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__`` and " "``__index__``" msgstr "" +"數值轉換方法:``__complex__``、``__int__``、``__float__`` 和 ``__index__``" #: ../../library/unittest.mock.rst:2032 msgid "Descriptor methods: ``__get__``, ``__set__`` and ``__delete__``" -msgstr "" +msgstr "描述器方法:``__get__``、``__set__`` 和 ``__delete__``" #: ../../library/unittest.mock.rst:2033 msgid "" "Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, " "``__getnewargs__``, ``__getstate__`` and ``__setstate__``" msgstr "" +"Pickling:``__reduce__``、``__reduce_ex__``、``__getinitargs__``、" +"``__getnewargs__``、``__getstate__`` 和 ``__setstate__``" #: ../../library/unittest.mock.rst:2035 msgid "File system path representation: ``__fspath__``" -msgstr "" +msgstr "檔案系統路徑表示法:``__fspath__``" #: ../../library/unittest.mock.rst:2036 msgid "Asynchronous iteration methods: ``__aiter__`` and ``__anext__``" -msgstr "" +msgstr "非同步疊代方法:``__aiter__`` 和 ``__anext__``" #: ../../library/unittest.mock.rst:2038 msgid "Added support for :func:`os.PathLike.__fspath__`." -msgstr "" +msgstr "新增對於 :func:`os.PathLike.__fspath__` 的支援。" #: ../../library/unittest.mock.rst:2041 msgid "" "Added support for ``__aenter__``, ``__aexit__``, ``__aiter__`` and " "``__anext__``." msgstr "" +"新增對於 ``__aenter__``、``__aexit__``、``__aiter__`` 和 ``__anext__`` 的支" +"援。" #: ../../library/unittest.mock.rst:2045 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 "" +"以下方法存在,但「不」被支援,因為它們在被 mock 使用時,會無法動態設定,或可" +"能導致問題:" #: ../../library/unittest.mock.rst:2048 msgid "``__getattr__``, ``__setattr__``, ``__init__`` and ``__new__``" -msgstr "" -"``__getattr__``\\ 、\\ ``__setattr__``\\ 、\\ ``__init__`` 和 ``__new__``" +msgstr "``__getattr__``、``__setattr__``、``__init__`` 和 ``__new__``" #: ../../library/unittest.mock.rst:2049 msgid "" "``__prepare__``, ``__instancecheck__``, ``__subclasscheck__``, ``__del__``" msgstr "" -"``__prepare__``\\ 、\\ ``__instancecheck__``\\ 、\\ " -"``__subclasscheck__``\\ 、\\ ``__del__``" +"``__prepare__``、``__instancecheck__``、``__subclasscheck__``、``__del__``" #: ../../library/unittest.mock.rst:2054 msgid "Magic Mock" -msgstr "" +msgstr "Magic Mock" #: ../../library/unittest.mock.rst:2056 msgid "" "There are two ``MagicMock`` variants: :class:`MagicMock` and :class:" "`NonCallableMagicMock`." msgstr "" +"``MagicMock`` 有兩個變體::class:`MagicMock` 和 :class:" +"`NonCallableMagicMock`。" #: ../../library/unittest.mock.rst:2061 msgid "" @@ -2065,20 +2122,24 @@ msgid "" "most of the :term:`magic methods `. You can use ``MagicMock`` " "without having to configure the magic methods yourself." msgstr "" +"``MagicMock`` 是 :class:`Mock` 的子類別,其預設具有大多數\\ :term:`魔術方法 " +"`\\ 的實作。你可以使用 ``MagicMock``,而無需自行配置魔術方法。" #: ../../library/unittest.mock.rst:2065 msgid "The constructor parameters have the same meaning as for :class:`Mock`." -msgstr "" +msgstr "建構函式參數的意義與 :class:`Mock` 中的參數相同。" #: ../../library/unittest.mock.rst:2067 msgid "" "If you use the *spec* or *spec_set* arguments then *only* magic methods that " "exist in the spec will be created." msgstr "" +"如果你使用 *spec* 或 *spec_set* 引數,那麼\\ *只有*\\ 規格中存在的魔術方法會" +"被建立。" #: ../../library/unittest.mock.rst:2073 msgid "A non-callable version of :class:`MagicMock`." -msgstr "" +msgstr ":class:`MagicMock` 的不可呼叫版本。" #: ../../library/unittest.mock.rst:2075 msgid "" @@ -2086,12 +2147,16 @@ msgid "" "with the exception of *return_value* and *side_effect* which have no meaning " "on a non-callable mock." msgstr "" +"建構函式參數的意義與 :class:`MagicMock` 中的參數相同,但 *return_value* 和 " +"*side_effect* 除外,它們對不可呼叫的 mock 來說沒有任何意義。" #: ../../library/unittest.mock.rst:2079 msgid "" "The magic methods are setup with :class:`MagicMock` objects, so you can " "configure them and use them in the usual way:" msgstr "" +"魔術方法是使用 :class:`MagicMock` 物件設定的,因此你可以配置它們並以一般的方" +"法來使用它們:" #: ../../library/unittest.mock.rst:2089 msgid "" @@ -2101,10 +2166,13 @@ msgid "" "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:2095 msgid "Methods and their defaults:" -msgstr "" +msgstr "方法及其預設值:" #: ../../library/unittest.mock.rst:2097 msgid "``__lt__``: ``NotImplemented``" @@ -2164,15 +2232,15 @@ msgstr "``__index__``\\ :\\ ``1``" #: ../../library/unittest.mock.rst:2111 msgid "``__hash__``: default hash for the mock" -msgstr "" +msgstr "``__hash__``:mock 的預設雜湊" #: ../../library/unittest.mock.rst:2112 msgid "``__str__``: default str for the mock" -msgstr "" +msgstr "``__str__``:mock 的預設字串" #: ../../library/unittest.mock.rst:2113 msgid "``__sizeof__``: default sizeof for the mock" -msgstr "" +msgstr "``__sizeof__``:mock 的預設 sizeof" #: ../../library/unittest.mock.rst:2115 msgid "For example:" @@ -2185,18 +2253,24 @@ msgid "" "side_effect` attribute, unless you change their return value to return " "something else::" msgstr "" +":meth:`!__eq__` 和 :meth:`!__ne__` 這兩個相等的方法是特別的。它們使用 :attr:" +"`~Mock.side_effect` 屬性對識別性 (identity) 進行預設的相等比較,除非你變更它" +"們的回傳值以回傳其他內容: ::" #: ../../library/unittest.mock.rst:2141 msgid "" "The return value of :meth:`MagicMock.__iter__` can be any iterable object " "and isn't required to be an iterator:" msgstr "" +":meth:`MagicMock.__iter__` 的回傳值可以是任何可疊代物件,且不需是一個疊代器:" #: ../../library/unittest.mock.rst:2151 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:2160 msgid "" @@ -2204,12 +2278,14 @@ msgid "" "some of the obscure and obsolete ones. You can still set these up if you " "want." msgstr "" +"``MagicMock`` 配置了所有支援的魔術方法,除了一些少見和過時的方法。如果你想" +"要,你仍然可以設定這些魔術方法。" #: ../../library/unittest.mock.rst:2163 msgid "" "Magic methods that are supported but not setup by default in ``MagicMock`` " "are:" -msgstr "" +msgstr "``MagicMock`` 中支援但預設未設置的魔術方法包含:" #: ../../library/unittest.mock.rst:2165 msgid "``__subclasses__``" @@ -2225,7 +2301,7 @@ msgstr "``__format__``" #: ../../library/unittest.mock.rst:2168 msgid "``__get__``, ``__set__`` and ``__delete__``" -msgstr "``__get__``\\ 、\\ ``__set__`` 和 ``__delete__``" +msgstr "``__get__``、``__set__`` 和 ``__delete__``" #: ../../library/unittest.mock.rst:2169 msgid "``__reversed__`` and ``__missing__``" @@ -2236,6 +2312,8 @@ msgid "" "``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, ``__getnewargs__``, " "``__getstate__`` and ``__setstate__``" msgstr "" +"``__reduce__``、``__reduce_ex__``、``__getinitargs__``、``__getnewargs__``、" +"``__getstate__`` 和 ``__setstate__``" #: ../../library/unittest.mock.rst:2172 msgid "``__getformat__``" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy