diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 8067ed10cc..17cf967b7f 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-07-22 00:04+0000\n" -"PO-Revision-Date: 2023-09-09 23:07+0800\n" +"PO-Revision-Date: 2023-10-10 21:59+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -17,7 +17,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.3.2\n" +"X-Generator: Poedit 3.4\n" #: ../../library/unittest.mock.rst:3 msgid ":mod:`unittest.mock` --- mock object library" @@ -253,16 +253,16 @@ msgid "" "class of :class:`Mock` using the *new_callable* argument to :func:`patch`." msgstr "" ":func:`patch` 裝飾器可以輕鬆地用 :class:`Mock` 物件臨時替換特定模組中的類別。" -"預設情況下,:func:`patch` 會為你建立一個 :class:`MagicMock`。你可以使" -"用 :func:`patch` 的 *new_callable* 引數指定 :class:`Mock` 的替代類別。" +"預設情況下,:func:`patch` 會為你建立一個 :class:`MagicMock`。你可以使用 :" +"func:`patch` 的 *new_callable* 引數指定 :class:`Mock` 的替代類別。" #: ../../library/unittest.mock.rst:231 msgid "" "Create a new :class:`Mock` object. :class:`Mock` takes several optional " "arguments that specify the behaviour of the Mock object:" msgstr "" -"建立一個新的 :class:`Mock` 物件。:class:`Mock` 接受數個可選的引數來指定 " -"Mock 物件的行為:" +"建立一個新的 :class:`Mock` 物件。:class:`Mock` 接受數個可選的引數來指定 Mock " +"物件的行為:" #: ../../library/unittest.mock.rst:234 msgid "" @@ -428,8 +428,8 @@ msgid "" "assert the mock has been called with the specified calls. The :attr:" "`mock_calls` list is checked for the calls." msgstr "" -"斷言 mock 已經使用指定的呼叫方式來呼叫。此斷言會檢查 :attr:`mock_calls` 串列中的" -"呼叫。" +"斷言 mock 已經使用指定的呼叫方式來呼叫。此斷言會檢查 :attr:`mock_calls` 串列" +"中的呼叫。" #: ../../library/unittest.mock.rst:365 msgid "" @@ -449,15 +449,15 @@ msgstr "" #: ../../library/unittest.mock.rst:384 msgid "Assert the mock was never called." -msgstr "" +msgstr "斷言 mock 從未被呼叫。" #: ../../library/unittest.mock.rst:399 msgid "The reset_mock method resets all the call attributes on a mock object:" -msgstr "" +msgstr "reset_mock 方法重置 mock 物件上的所有呼叫屬性:" #: ../../library/unittest.mock.rst:409 msgid "Added two keyword-only arguments to the reset_mock function." -msgstr "" +msgstr "reset_mock 函式新增了兩個僅限關鍵字引數 (keyword-only arguments)。" #: ../../library/unittest.mock.rst:412 msgid "" @@ -468,20 +468,26 @@ msgid "" "`side_effect`, then pass the corresponding parameter as ``True``. Child " "mocks and the return value mock (if any) are reset as well." msgstr "" +"這在你想要進行一系列重複使用同一物件的斷言時非常有用。請注意,預設情況下,:" +"meth:`reset_mock` *不會*\\ 清除回傳值、:attr:`side_effect` 或使用普通賦值設定的" +"任何子屬性。如果你想要重置 *return_value* 或 :attr:`side_effect`,則將相應的" +"參數設置為 ``True``。Child mock 和回傳值 mock(如果有的話)也會被重置。" #: ../../library/unittest.mock.rst:420 msgid "*return_value*, and :attr:`side_effect` are keyword-only arguments." -msgstr "" +msgstr "*return_value* 和 :attr:`side_effect` 是僅限關鍵字引數。" #: ../../library/unittest.mock.rst:426 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 "" +"向 mock 增加一個規格 (spec)。*spec* 可以是一個物件或一個字串串列 (list of " +"strings)。只有在 *spec* 上的屬性才能作為 mock 的屬性被取得。" #: ../../library/unittest.mock.rst:430 msgid "If *spec_set* is true then only attributes on the spec can be set." -msgstr "" +msgstr "如果 *spec_set* 為 true,那麼只能設定在規格中的屬性。" #: ../../library/unittest.mock.rst:435 msgid "" @@ -489,26 +495,32 @@ msgid "" "Calls to the attached mock will be recorded in the :attr:`method_calls` and :" "attr:`mock_calls` attributes of this one." msgstr "" +"將一個 mock 作為這個 Mock 的屬性附加,取代它的名稱和上代 (parent)。對附加的 " +"mock 的呼叫將被記錄在這個 Mock 的 :attr:`method_calls` 和 :attr:`mock_calls` " +"屬性中。" #: ../../library/unittest.mock.rst:442 msgid "Set attributes on the mock through keyword arguments." -msgstr "" +msgstr "透過關鍵字引數在 mock 上設定屬性。" #: ../../library/unittest.mock.rst:444 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 "" +"可以在使用 method(方法)呼叫時,使用標準點記法 (dot notation) 並將字典拆開," +"為 child mock 設定屬性、回傳值和 side effects:" #: ../../library/unittest.mock.rst:458 msgid "The same thing can be achieved in the constructor call to mocks:" -msgstr "" +msgstr "同樣的事情可以在 mock 的建構函式呼叫中實現:" #: ../../library/unittest.mock.rst:471 msgid "" ":meth:`configure_mock` exists to make it easier to do configuration after " "the mock has been created." msgstr "" +":meth:`configure_mock` 的存在是為了在 mock 被建立後更容易進行組態設定。" #: ../../library/unittest.mock.rst:477 msgid "" @@ -516,12 +528,14 @@ msgid "" "results. For mocks with a *spec* this includes all the permitted attributes " "for the mock." msgstr "" +":class:`Mock` 物件限制了 ``dir(some_mock)`` 僅顯示有用的結果。對於具有 " +"*spec* 的 mock,這包含所有被允許的 mock 屬性。" #: ../../library/unittest.mock.rst:481 msgid "" "See :data:`FILTER_DIR` for what this filtering does, and how to switch it " "off." -msgstr "" +msgstr "請參閱 :data:`FILTER_DIR` 以了解這種過濾行為的作用,以及如何關閉它。" #: ../../library/unittest.mock.rst:487 msgid "" @@ -529,40 +543,44 @@ msgid "" "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 "" +"建立為了得到屬性和回傳值的 child mock。預設情況下,child mock 將與其上代是相" +"同的型別。Mock 的子類別可能會想要置換此行為,以自定義 child mock 的建立方式。" #: ../../library/unittest.mock.rst:492 msgid "" "For non-callable mocks the callable variant will be used (rather than any " "custom subclass)." -msgstr "" +msgstr "對於不可呼叫的 mock,將使用可呼叫的變體,而不是任何的自定義子類別。" #: ../../library/unittest.mock.rst:498 msgid "A boolean representing whether or not the mock object has been called:" -msgstr "" +msgstr "一個 boolean(布林),表述 mock 物件是否已經被呼叫:" #: ../../library/unittest.mock.rst:509 msgid "An integer telling you how many times the mock object has been called:" -msgstr "" +msgstr "一個整數,告訴你 mock 物件被呼叫的次數:" #: ../../library/unittest.mock.rst:521 msgid "Set this to configure the value returned by calling the mock:" -msgstr "" +msgstr "設定此值以配置呼叫 mock 時回傳的值:" #: ../../library/unittest.mock.rst:528 msgid "" "The default return value is a mock object and you can configure it in the " "normal way:" -msgstr "" +msgstr "預設的回傳值是一個 mock 物件,你也可以按照正常的方式配置它:" #: ../../library/unittest.mock.rst:537 msgid ":attr:`return_value` can also be set in the constructor:" -msgstr "" +msgstr ":attr:`return_value` 也可以在建構函式中設定:" #: ../../library/unittest.mock.rst:548 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 "" +"這可以是一個在呼叫 mock 時要呼叫的函式、一個可疊代物件,或者要引發的例外(類" +"別或實例)。" #: ../../library/unittest.mock.rst:551 msgid "" @@ -572,6 +590,10 @@ msgid "" "returns :data:`DEFAULT` then the mock will return its normal value (from " "the :attr:`return_value`)." msgstr "" +"如果你傳遞一個函式,它將被呼叫,其引數與 mock 相同,且除非該函式回傳 :data:" +"`DEFAULT` 單例 (singleton),否則對 mock 的呼叫將回傳函式回傳的任何值。如果函" +"式回傳 :data:`DEFAULT`,那麼 mock 將回傳其正常的回傳值(從 :attr:" +"`return_value` 得到)。" #: ../../library/unittest.mock.rst:557 msgid "" @@ -580,30 +602,35 @@ msgid "" "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 "" +"如果你傳遞一個可疊代物件,它將被用於檢索一個疊代器,該疊代器必須在每次呼叫時" +"產出 (yield) 一個值。這個值可以是要引發的例外實例,或者是對 mock 呼叫時要回傳" +"的值(處理 :data:`DEFAULT` 的方式與函式的狀況相同)。" #: ../../library/unittest.mock.rst:562 msgid "" "An example of a mock that raises an exception (to test exception handling of " "an API):" -msgstr "" +msgstr "以下是一個引發例外的 mock 的範例(用於測試 API 的例外處理):" #: ../../library/unittest.mock.rst:572 msgid "Using :attr:`side_effect` to return a sequence of values:" -msgstr "" +msgstr "使用 :attr:`side_effect` 回傳一連串值的範例:" #: ../../library/unittest.mock.rst:579 msgid "Using a callable:" -msgstr "" +msgstr "使用可被呼叫物件的範例:" #: ../../library/unittest.mock.rst:589 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 "" +":attr:`side_effect` 可以在建構函式中設定。以下是一個範例,它將 mock 被呼叫時" +"給的值加一並回傳:" #: ../../library/unittest.mock.rst:599 msgid "Setting :attr:`side_effect` to ``None`` clears it:" -msgstr "" +msgstr "將 :attr:`side_effect` 設定為 ``None`` 可以清除它:" #: ../../library/unittest.mock.rst:613 msgid "" @@ -614,6 +641,10 @@ msgid "" "second member, which can also be accessed through the ``kwargs`` property, " "is any keyword arguments (or an empty dictionary)." msgstr "" +"這會是 ``None``(如果 mock 尚未被呼叫),或是 mock 上次被呼叫時使用的引數。這" +"將以元組的形式呈現:第一個成員 (member),其可以通過 ``args`` 屬性訪問,是 " +"mock 被呼叫時傳遞的所有有序引數(或一個空元組)。第二個成員,其可以通過 " +"``kwargs`` 屬性訪問,是所有關鍵字引數(或一個空字典)。" #: ../../library/unittest.mock.rst:646 msgid "" @@ -622,6 +653,10 @@ msgid "" "are tuples, so they can be unpacked to get at the individual arguments and " "make more complex assertions. See :ref:`calls as tuples `." msgstr "" +":attr:`call_args`,以及串列 :attr:`call_args_list`、:attr:`method_calls` 和 :" +"attr:`mock_calls` 的成員都是 :data:`call` 物件。這些都是元組,因此可以解包以" +"獲取各個引數並進行更複雜的斷言。參見 :ref:`calls as tuples `。" #: ../../library/unittest.mock.rst:652 msgid "Added ``args`` and ``kwargs`` properties." @@ -635,6 +670,9 @@ msgid "" "used for conveniently constructing lists of calls to compare with :attr:" "`call_args_list`." msgstr "" +"這是按順序列出所有呼叫 mock 物件的串列(因此串列的長度表示它被呼叫的次數)。" +"在任何呼叫發生之前,它會是一個空的串列。 :data:`call` 物件可用於方便地建構呼" +"叫的串列,以便與 :attr:`call_args_list` 進行比較。" #: ../../library/unittest.mock.rst:674 msgid "" @@ -642,12 +680,16 @@ msgid "" "unpacked as tuples to get at the individual arguments. See :ref:`calls as " "tuples `." msgstr "" +":attr:`call_args_list` 的成員都是 :data:`call` 物件。這些物件可以被拆包為元" +"組,以取得各個引數。參見 :ref:`calls as tuples `。" #: ../../library/unittest.mock.rst:681 msgid "" "As well as tracking calls to themselves, mocks also track calls to methods " "and attributes, and *their* methods and attributes:" msgstr "" +"除了追蹤對自身的呼叫之外,mock 還會追蹤對方法和屬性的呼降,以及*它們(這些方" +"法和屬性)*的方法和屬性:" #: ../../library/unittest.mock.rst:692 msgid "" @@ -655,12 +697,16 @@ msgid "" "unpacked as tuples to get at the individual arguments. See :ref:`calls as " "tuples `." msgstr "" +":attr:`method_calls` 的成員都是 :data:`call` 物件。這些物件可以拆包為元組,以" +"取得各個引數。參見 :ref:`calls as tuples `。" #: ../../library/unittest.mock.rst:699 msgid "" ":attr:`mock_calls` records *all* calls to the mock object, its methods, " "magic methods *and* return value mocks." msgstr "" +":attr:`mock_calls` 記錄了 *所有* 對 mock 物件的呼叫,包含其方法、魔術方法以及" +"回傳值 mock。" #: ../../library/unittest.mock.rst:717 msgid "" @@ -668,6 +714,8 @@ msgid "" "unpacked as tuples to get at the individual arguments. See :ref:`calls as " "tuples `." msgstr "" +":attr:`method_calls` 的成員都是 :data:`call` 物件。這些物件可以拆包為元組,以" +"取得各個引數。參見 :ref:`calls as tuples `。" #: ../../library/unittest.mock.rst:723 msgid "" @@ -675,6 +723,8 @@ msgid "" "made, the parameters of ancestor calls are not recorded and so will always " "compare equal:" msgstr "" +":attr:`mock_calls` 記錄的方式意味著在進行嵌套呼叫時,上代 (ancestor) 呼叫的參" +"數不會被記錄,因此在比較時它們將始終相等:" #: ../../library/unittest.mock.rst:737 msgid "" @@ -683,12 +733,17 @@ msgid "" "instead. This allows mock objects to pass :func:`isinstance` tests for the " "object they are replacing / masquerading as:" msgstr "" +"通常,物件的 :attr:`__class__` 屬性會回傳它的型別。但對於擁有 :attr:`spec` " +"的 mock 物件,``__class__`` 會回傳 spec 的類別。這允許 mock 物件通過對它們所" +"替代或偽裝的物件進行的 :func:`isinstance` 測試:" #: ../../library/unittest.mock.rst:746 msgid "" ":attr:`__class__` is assignable to, this allows a mock to pass an :func:" "`isinstance` check without forcing you to use a spec:" msgstr "" +":attr:`__class__` 可以被指定,這允許 mock 通過 :func:`isinstance` 檢查,而不" +"需要強制使用 spec:" #: ../../library/unittest.mock.rst:756 msgid "" @@ -696,18 +751,24 @@ msgid "" "same meaning of :class:`Mock`, with the exception of *return_value* and " "*side_effect* which have no meaning on a non-callable mock." msgstr "" +":class:`Mock` 的一個不可呼叫版本。建構函式參數的意義與 :class:`Mock` 相同,其" +"例外為 *return_value* 和 *side_effect* 在不可呼叫的 mock 上無意義。" #: ../../library/unittest.mock.rst:760 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 "" +"使用類別或實例作為 :attr:`spec` 或 :attr:`spec_set` 的 mock 物件能夠通過 :" +"func:`isinstance` 測試:" #: ../../library/unittest.mock.rst:770 msgid "" "The :class:`Mock` classes have support for mocking magic methods. See :ref:" "`magic methods ` for the full details." msgstr "" +":class:`Mock` 類別支援 mock 魔術方法。細節請參考\\ :ref:`魔術方法 `。" #: ../../library/unittest.mock.rst:773 msgid "" @@ -716,6 +777,9 @@ msgid "" "are passed to the constructor of the mock being created. The keyword " "arguments are for configuring attributes of the mock:" msgstr "" +"Mock類別和 :func:`patch` 裝飾器於組態時接受任意的關鍵字引數。對於 :func:" +"`patch` 裝飾器,這些關鍵字會傳遞給正在建立 mock 的建構函式。這些關鍵字引數用" +"於配置 mock 的屬性:" #: ../../library/unittest.mock.rst:784 msgid "" @@ -723,6 +787,8 @@ msgid "" "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 "" +"Child mock 的回傳值和 side effect 可以使用使用點記法進行設置。由於你無法直接" +"在呼叫中使用帶有點 (.) 的名稱,因此你必須建立一個字典並使用 ``**`` 解包:" #: ../../library/unittest.mock.rst:799 msgid "" @@ -731,6 +797,11 @@ msgid "" "mock. Therefore, it can match the actual call's arguments regardless of " "whether they were passed positionally or by name::" msgstr "" +"在匹配對 mock 的呼叫時,使用 *spec*(或 *spec_set*)建立的可呼叫 mock 將會內" +"省規格物件的簽名 (signature)。因此,它可以匹配實際呼叫的引數,無論它們是按位" +"置傳遞還是按名稱傳遞:\n" +"\n" +"::" #: ../../library/unittest.mock.rst:812 msgid "" @@ -739,10 +810,16 @@ msgid "" "assert_any_call`. When :ref:`auto-speccing`, it will also apply to method " "calls on the mock object." msgstr "" +"這適用於 :meth:`~Mock.assert_called_with`、:meth:`~Mock." +"assert_called_once_with`、:meth:`~Mock.assert_has_calls` 和 :meth:`~Mock." +"assert_any_call`。在使用 :ref:`auto-speccing` ,它還適用於 mock 物件的方法呼" +"叫。" #: ../../library/unittest.mock.rst:817 msgid "Added signature introspection on specced and autospecced mock objects." msgstr "" +"對於已經設置了規格(spec)和自動規格(autospec)的 mock 物件,新增簽名內省功" +"能。" #: ../../library/unittest.mock.rst:823 msgid ""