From 1f965507d6bfa32e6e93bd889b1a3c517ea19c35 Mon Sep 17 00:00:00 2001 From: Payon Date: Tue, 20 Feb 2024 21:39:48 +0800 Subject: [PATCH 01/16] feat: to rst:2286 --- library/unittest.mock.po | 45 +++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 9d5c806de1..5ac3df580c 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-02-19 21:27+0800\n" +"PO-Revision-Date: 2024-02-20 21:39+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2325,26 +2325,28 @@ msgid "" "Different versions of Python are inconsistent about applying this rule. The " "supported protocol methods should work with all supported versions of Python." msgstr "" +"魔術方法\\ *應該*\\ 在類別而不是實例上被查找。不同版本的 Python 對於這條規則" +"的適用並不一致。支援的協定方法應適用於所有支援的 Python 版本。" #: ../../library/unittest.mock.rst:2180 msgid "" "The function is basically hooked up to the class, but each ``Mock`` instance " "is kept isolated from the others." -msgstr "" +msgstr "該函式基本上與類別掛鉤,但每個 ``Mock`` 實例都與其他實例保持隔離。" #: ../../library/unittest.mock.rst:2185 msgid "Helpers" -msgstr "" +msgstr "輔助函式" #: ../../library/unittest.mock.rst:2188 msgid "sentinel" -msgstr "" +msgstr "sentinel(哨兵)" #: ../../library/unittest.mock.rst:2192 msgid "" "The ``sentinel`` object provides a convenient way of providing unique " "objects for your tests." -msgstr "" +msgstr "``哨兵``\\ 物件提供了一種為你的測試提供獨特物件的便利方式。" #: ../../library/unittest.mock.rst:2195 msgid "" @@ -2352,12 +2354,16 @@ msgid "" "same attribute will always return the same object. The objects returned have " "a sensible repr so that test failure messages are readable." msgstr "" +"當你使用名稱存取屬性時,屬性會根據需要被建立。存取相同的屬性將始終回傳相同的" +"物件。回傳的物件會具有合適的 repr,讓測試失敗的訊息是可閱讀的。" #: ../../library/unittest.mock.rst:2199 msgid "" "The ``sentinel`` attributes now preserve their identity when they are :mod:" "`copied ` or :mod:`pickled `." msgstr "" +"``哨兵``\\ 屬性現在在是 :mod:`copied ` 或 :mod:`pickled ` 時保" +"留其標識 (identity)。" #: ../../library/unittest.mock.rst:2203 msgid "" @@ -2366,12 +2372,16 @@ msgid "" "sentinel objects to test this. :data:`sentinel` provides a convenient way of " "creating and testing the identity of objects like this." msgstr "" +"在測試時,有時你需要測試特定物件是否作為引數被傳遞給另一個方法或回傳。建立命" +"名的哨兵物件來測試這一點是常見的。:data:`sentinel` 提供了一種建立和測試此類物" +"件標識的便利方式。" #: ../../library/unittest.mock.rst:2208 msgid "" "In this example we monkey patch ``method`` to return ``sentinel." "some_object``:" msgstr "" +"在這個例子中,我們 monkey patch ``method`` 以回傳 ``sentinel.some_object``:" #: ../../library/unittest.mock.rst:2220 msgid "DEFAULT" @@ -2383,10 +2393,13 @@ msgid "" "DEFAULT``). It can be used by :attr:`~Mock.side_effect` functions to " "indicate that the normal return value should be used." msgstr "" +":data:`DEFAULT` 物件是一個預先建立的哨兵(實際上是 ``sentinel." +"DEFAULT``\\ )。它可以被 :attr:`~Mock.side_effect` 函式使用來表示正常的回傳值" +"應該被使用。" #: ../../library/unittest.mock.rst:2231 msgid "call" -msgstr "" +msgstr "call" #: ../../library/unittest.mock.rst:2235 msgid "" @@ -2395,12 +2408,18 @@ msgid "" "mock_calls` and :attr:`~Mock.method_calls`. :func:`call` can also be used " "with :meth:`~Mock.assert_has_calls`." msgstr "" +"與 :attr:`~Mock.call_args`、:attr:`~Mock.call_args_list`、:attr:`~Mock." +"mock_calls ` 和 :attr:`~Mock.method_calls` 相比,:func:`call` 是一個用於進行" +"更簡單的斷言的輔助物件。:func:`call` 也可以與 :meth:`~Mock.assert_has_calls` " +"一起使用。" #: ../../library/unittest.mock.rst:2248 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 "" +"對於表示多個呼叫的 call 物件,:meth:`call_list` 回傳所有中間呼叫以及最終呼叫" +"的清單。" #: ../../library/unittest.mock.rst:2252 msgid "" @@ -2409,12 +2428,15 @@ msgid "" "results in multiple entries in :attr:`~Mock.mock_calls` on a mock. Manually " "constructing the sequence of calls can be tedious." msgstr "" +"``call_list`` 在對\\ \"鍊接呼叫 (chained calls)\"\\ 進行斷言時特別有用。鍊接" +"呼叫是對單行程式碼進行的多次呼叫。這會導致 mock 上的 :attr:`~Mock." +"mock_calls` 中出現多個項目。手動建構呼叫序列會相當單調乏味。" #: ../../library/unittest.mock.rst:2257 msgid "" ":meth:`~call.call_list` can construct the sequence of calls from the same " "chained call:" -msgstr "" +msgstr ":meth:`~call.call_list` 可以從同一個鍊接呼叫建構呼叫序列:" #: ../../library/unittest.mock.rst:2274 msgid "" @@ -2425,6 +2447,10 @@ msgid "" "call_args_list` and :attr:`Mock.mock_calls` attributes can be introspected " "to get at the individual arguments they contain." msgstr "" +"取決於它的建構方式,一個 ``call`` 物件會是(位置引數, 關鍵字引數)的元組,或" +"是(名稱, 位置引數, 關鍵字引數)的元組。當你自己建構它們時,這並不是那麼有" +"趣,但是 :attr:`Mock.call_args`、:attr:`Mock.call_args_list` 和 :attr:`Mock." +"mock_calls` 屬性中的 ``call`` 物件可以被內省以取得它們包含的各個引數。" #: ../../library/unittest.mock.rst:2281 msgid "" @@ -2434,6 +2460,9 @@ msgid "" "construct yourself, are three-tuples of (name, positional args, keyword " "args)." msgstr "" +":attr:`Mock.call_args` 和 :attr:`Mock.call_args_list` 中的 ``call`` 物件是" +"(位置引數, 關鍵字引數)的二元組,而 :attr:`Mock.mock_calls`中的 ``call`` 物" +"件以及你自己建立 ``call`` 物件是(名稱, 位置引數, 關鍵字引數)的三元組。" #: ../../library/unittest.mock.rst:2286 msgid "" @@ -2442,6 +2471,8 @@ msgid "" "tuple (an empty tuple if there are no positional arguments) and the keyword " "arguments are a dictionary:" msgstr "" +"你可以利用它們作為元組的特性來提取單個引數,以進行更複雜的內省和斷言。位置引" +"數是一個元組(如果沒有位置引數則為空元組),關鍵字引數是一個字典:" #: ../../library/unittest.mock.rst:2319 msgid "create_autospec" From b324fabbef1f87a1b4f8bdbc04972cca3df46661 Mon Sep 17 00:00:00 2001 From: Payon Date: Wed, 21 Feb 2024 00:10:46 +0800 Subject: [PATCH 02/16] fix: fix inconsistent term references --- library/unittest.mock.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 5ac3df580c..4d431035a8 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-02-20 21:39+0800\n" +"PO-Revision-Date: 2024-02-21 00:10+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2408,10 +2408,10 @@ msgid "" "mock_calls` and :attr:`~Mock.method_calls`. :func:`call` can also be used " "with :meth:`~Mock.assert_has_calls`." msgstr "" -"與 :attr:`~Mock.call_args`、:attr:`~Mock.call_args_list`、:attr:`~Mock." -"mock_calls ` 和 :attr:`~Mock.method_calls` 相比,:func:`call` 是一個用於進行" -"更簡單的斷言的輔助物件。:func:`call` 也可以與 :meth:`~Mock.assert_has_calls` " -"一起使用。" +":func:`call` 是一個用於進行更簡單的斷言的輔助物件,與 :attr:`~Mock." +"call_args`、:attr:`~Mock.call_args_list`、:attr:`~Mock.mock_calls ` 和 :attr:" +"`~Mock.method_calls` 相比。:func:`call` 也可以與 :meth:`~Mock." +"assert_has_calls` 一起使用。" #: ../../library/unittest.mock.rst:2248 msgid "" From c466d862382c3cc67d341725e435083577e33b09 Mon Sep 17 00:00:00 2001 From: Payon Date: Wed, 21 Feb 2024 00:26:51 +0800 Subject: [PATCH 03/16] fix: fix inconsistent term references --- library/unittest.mock.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 4d431035a8..5e022de4aa 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-02-21 00:10+0800\n" +"PO-Revision-Date: 2024-02-21 00:26+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2409,7 +2409,7 @@ msgid "" "with :meth:`~Mock.assert_has_calls`." msgstr "" ":func:`call` 是一個用於進行更簡單的斷言的輔助物件,與 :attr:`~Mock." -"call_args`、:attr:`~Mock.call_args_list`、:attr:`~Mock.mock_calls ` 和 :attr:" +"call_args`、:attr:`~Mock.call_args_list`、:attr:`~Mock.mock_calls` 和 :attr:" "`~Mock.method_calls` 相比。:func:`call` 也可以與 :meth:`~Mock." "assert_has_calls` 一起使用。" From 61faa6ce057f3e50b9abd3749de6a0b73077165f Mon Sep 17 00:00:00 2001 From: Payon Date: Mon, 18 Mar 2024 21:07:27 +0800 Subject: [PATCH 04/16] fix: resolve conflict --- library/unittest.mock.po | 41 +++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 5e022de4aa..1ae5f3be71 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-02-21 00:26+0800\n" +"PO-Revision-Date: 2024-02-21 21:59+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2044,7 +2044,7 @@ msgid "" msgstr "" "數值方法(包括右側 (right hand) 和原地 (in-place) 變體):``__add__``、" "``__sub__``、``__mul__``、``__matmul__``、``__truediv__``、" -"``__floordiv__``、 ``__mod__``、``__divmod__``、``__lshift__``、" +"``__floordiv__``、``__mod__``、``__divmod__``、``__lshift__``、" "``__rshift__``、``__and__``、``__xor__``、``__or__`` 和 ``__pow__``" #: ../../library/unittest.mock.rst:2030 @@ -2363,7 +2363,7 @@ msgid "" "`copied ` or :mod:`pickled `." msgstr "" "``哨兵``\\ 屬性現在在是 :mod:`copied ` 或 :mod:`pickled ` 時保" -"留其標識 (identity)。" +"留其識別性。" #: ../../library/unittest.mock.rst:2203 msgid "" @@ -2374,7 +2374,7 @@ msgid "" msgstr "" "在測試時,有時你需要測試特定物件是否作為引數被傳遞給另一個方法或回傳。建立命" "名的哨兵物件來測試這一點是常見的。:data:`sentinel` 提供了一種建立和測試此類物" -"件標識的便利方式。" +"件識別性的便利方式。" #: ../../library/unittest.mock.rst:2208 msgid "" @@ -2483,18 +2483,22 @@ 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 "" +"使用另一個物件作為規格建立一個 mock 物件。Mock 上的屬性將使用 *spec* 物件上的" +"對應屬性作為其規格。" #: ../../library/unittest.mock.rst:2327 msgid "" "Functions or methods being mocked will have their arguments checked to " "ensure that they are called with the correct signature." -msgstr "" +msgstr "被 mock 的函式或方法將檢查其引數,以確保他們被使用正確的簽名來呼叫。" #: ../../library/unittest.mock.rst:2330 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 "" +"如果 *spec_set* 為 ``True``,則嘗試設定規格物件上不存在的屬性將引發 :exc:" +"`AttributeError`。" #: ../../library/unittest.mock.rst:2333 msgid "" @@ -2503,24 +2507,33 @@ msgid "" "an instance object by passing ``instance=True``. The returned mock will only " "be callable if instances of the mock are callable." msgstr "" +"如果一個類別作為規格使用,則 mock(該類別的實例)的回傳值將具有相同的規格。你" +"可以透過傳遞 ``instance=True`` 來使用一個類別作為一個實例物件的規格。只有當 " +"mock 的實例是可呼叫物件時,回傳的 mock 才可以被呼叫。" #: ../../library/unittest.mock.rst:2338 msgid "" ":func:`create_autospec` also takes arbitrary keyword arguments that are " "passed to the constructor of the created mock." msgstr "" +":func:`create_autospec` 也接受任意的關鍵字引數,這些引數會傳遞給已建立的 " +"mock 的建構函式。" #: ../../library/unittest.mock.rst:2341 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 "" +"請參閱 :ref:`auto-speccing` 以得知如何以 :func:`create_autospec` 使用自動規格" +"以及如何在 :func:`patch` 中使用 *autospec* 引數的範例。" #: ../../library/unittest.mock.rst:2347 msgid "" ":func:`create_autospec` now returns an :class:`AsyncMock` if the target is " "an async function." msgstr "" +"如果目標是一個非同步函式,:func:`create_autospec` 現在會回傳一個 :class:" +"`AsyncMock`。" #: ../../library/unittest.mock.rst:2352 msgid "ANY" @@ -2533,6 +2546,8 @@ msgid "" "pull them individually out of :attr:`~Mock.call_args` and make more complex " "assertions on them." msgstr "" +"有時你可能需要對 mock 的呼叫中的\\ *某些*\\ 引數進行斷言,但你不在意其他的某" +"些引數,或想將它們單獨從 :attr:`~Mock.call_args` 中取出並進行更加複雜的斷言。" #: ../../library/unittest.mock.rst:2361 msgid "" @@ -2540,12 +2555,16 @@ msgid "" "*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 "" +"要忽略某些引數,你可以傳入對\\ *所有物件*\\ 來說都相等的物件。那麼無論傳入什" +"麼內容,對 :meth:`~Mock.assert_used_with` 和 :meth:`~Mock." +"assert_used_once_with` 的呼叫都會成功。" #: ../../library/unittest.mock.rst:2370 msgid "" ":data:`ANY` can also be used in comparisons with call lists like :attr:" "`~Mock.mock_calls`:" msgstr "" +":data:`ANY` 也可以用來與呼叫串列進行比較,例如 :attr:`~Mock.mock_calls`:" #: ../../library/unittest.mock.rst:2380 msgid "" @@ -2565,6 +2584,10 @@ msgid "" "filtering, or need to switch it off for diagnostic purposes, then set ``mock." "FILTER_DIR = False``." msgstr "" +":data:`FILTER_DIR` 是一個模組級別的變數,用於控制 mock 物件響應 :func:`dir`的" +"方式。其預設值為 ``True``,它使用以下描述的過濾方式來只顯示有用的成員。如果你" +"不喜歡這個過濾方式,或由於診斷意圖而需要將其關閉,請設定 ``mock.FILTER_DIR = " +"False``。" #: ../../library/unittest.mock.rst:2401 msgid "" @@ -2574,6 +2597,9 @@ msgid "" "attributes from the original are shown, even if they haven't been accessed " "yet:" msgstr "" +"當過濾方式開啟時, ``dir(some_mock)`` 僅會顯示有用的屬性,並將包括通常不會顯" +"示的任何動態建立的屬性。如果 mock 是使用 *spec*\\ (或 *autospec*\\ )來建立" +"的,那麼源頭的所有屬性都會顯示,即使它們尚未被存取:" #: ../../library/unittest.mock.rst:2428 msgid "" @@ -2583,6 +2609,9 @@ msgid "" "dislike this behaviour you can switch it off by setting the module level " "switch :data:`FILTER_DIR`:" msgstr "" +"許多不是很有用的(對 :class:`Mock` 來說是私有的,而不是被 mock 的東西)底線和" +"雙底線前綴屬性已從在 :class:`Mock` 上呼叫 :func:`dir` 的結果中濾除。如果你不" +"喜歡這種特性,可以透過設定模組級別開關 :data:`FILTER_DIR` 來將其關閉:" #: ../../library/unittest.mock.rst:2449 msgid "" @@ -2590,6 +2619,8 @@ msgid "" "``dir(type(my_mock))`` (type members) to bypass the filtering irrespective " "of :const:`mock.FILTER_DIR`." msgstr "" +"或者,你可以只使用 ``vars(my_mock)`` (實例成員)和 ``dir(type(my_mock))``" +"(型別成員)來略過過濾,而不考慮 :const:`mock.FILTER_DIR`。" #: ../../library/unittest.mock.rst:2455 msgid "mock_open" From d8524ef1fab4d7602e24e764a198031e66f5c0d7 Mon Sep 17 00:00:00 2001 From: Payon Date: Wed, 21 Feb 2024 22:04:57 +0800 Subject: [PATCH 05/16] fix: try to fix render error --- library/unittest.mock.po | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 1ae5f3be71..41854af584 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-02-21 21:59+0800\n" +"PO-Revision-Date: 2024-02-21 22:04+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2619,8 +2619,9 @@ msgid "" "``dir(type(my_mock))`` (type members) to bypass the filtering irrespective " "of :const:`mock.FILTER_DIR`." msgstr "" -"或者,你可以只使用 ``vars(my_mock)`` (實例成員)和 ``dir(type(my_mock))``" -"(型別成員)來略過過濾,而不考慮 :const:`mock.FILTER_DIR`。" +"或者,你可以只使用 ``vars(my_mock)``\\ (實例成員)和 " +"``dir(type(my_mock))``\\ (型別成員)來略過過濾,而不考慮 :const:`mock." +"FILTER_DIR`。" #: ../../library/unittest.mock.rst:2455 msgid "mock_open" From 507c8939e38cf604a1c13f3dbbd7cae02cacf299 Mon Sep 17 00:00:00 2001 From: Payon Date: Thu, 22 Feb 2024 22:28:31 +0800 Subject: [PATCH 06/16] feat: to the end --- library/unittest.mock.po | 111 +++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 10 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 41854af584..32c73fcb53 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-02-21 22:04+0800\n" +"PO-Revision-Date: 2024-02-22 22:28+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2632,6 +2632,8 @@ 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 "" +"用於建立取代 :func:`open` 用途的 mock 的輔助函式。它適用於直接呼叫或用作情境" +"管理器的 :func:`open`。" #: ../../library/unittest.mock.rst:2462 msgid "" @@ -2639,6 +2641,8 @@ msgid "" "default) then a :class:`MagicMock` will be created for you, with the API " "limited to methods or attributes available on standard file handles." msgstr "" +"*mock* 引數是要配置的 mock 物件。如果其 ``None``\\ (預設值),那麼就會為你建" +"立一個 :class:`MagicMock`,其 API 限制在標準檔案處理上可用的方法或屬性。" #: ../../library/unittest.mock.rst:2466 msgid "" @@ -2652,6 +2656,13 @@ msgid "" "in-memory filesystem packages on `PyPI `_ can offer a " "realistic filesystem for testing." msgstr "" +"*read_data*\\ 是一個檔案處理的 :meth:`~io.IOBase.read`、:meth:`~io.IOBase." +"readline` 和 :meth:`~io.IOBase.readlines` 方法的回傳字串。對這些方法的呼叫將" +"從\\ *read_data*\\ 取得資料,直到資料耗盡。對這些方法的 mock 非常單純:每次呼" +"叫\\ *mock*\\ 時,*read_data* 都會倒回到起點。如果你需要對提供給測試程式碼的" +"資料進行更多控制,你會需要自行客製化這個 mock。如果這樣還不夠,`PyPI " +"`_ 上的其中一個記憶體內檔案系統套件 (in-memory filesystem) " +"可以提供用於測試的真實檔案系統。" #: ../../library/unittest.mock.rst:2476 msgid "" @@ -2659,22 +2670,29 @@ msgid "" "The mock of :meth:`~io.IOBase.read` changed to consume *read_data* rather " "than returning it on each call." msgstr "" +"新增對 :meth:`~io.IOBase.readline` 和 :meth:`~io.IOBase.readlines` 的支援。:" +"meth:`~io.IOBase.read` 的 mock 更改為消耗\\ *read_data*\\ 而不是在每次呼叫時" +"回傳它。" #: ../../library/unittest.mock.rst:2481 msgid "*read_data* is now reset on each call to the *mock*." -msgstr "" +msgstr "現在,每次呼叫 *mock* 時都會重置 *read_data*。" #: ../../library/unittest.mock.rst:2484 msgid "" "Added :meth:`~container.__iter__` to implementation so that iteration (such " "as in for loops) correctly consumes *read_data*." msgstr "" +"新增 :meth:`~container.__iter__` 到實作中,以便使疊代(例如在 for 迴圈中)正" +"確地消耗 *read_data*。" #: ../../library/unittest.mock.rst:2488 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 "" +"使用 :func:`open` 作為情境管理器是確保檔案處理正確關閉的好方式,且這種方式正" +"在變得普遍: ::" #: ../../library/unittest.mock.rst:2494 msgid "" @@ -2682,20 +2700,25 @@ msgid "" "*returned object* that is used as a context manager (and has :meth:`~object." "__enter__` and :meth:`~object.__exit__` called)." msgstr "" +"問題是,即使你 mock 了對 :func:`open` 的呼叫,它也是作為情境管理器使用的 *回" +"傳物件*\\ (且其 :meth:`~object.__enter__` 和 :meth:`~ object.__exit__ ` 已被" +"呼叫)。" #: ../../library/unittest.mock.rst:2498 msgid "" "Mocking context managers with a :class:`MagicMock` is common enough and " "fiddly enough that a helper function is useful. ::" msgstr "" +"使用 :class:`MagicMock` mock 情境管理器相當常見並且精細,因此輔助函式就非常有" +"用。: ::" #: ../../library/unittest.mock.rst:2515 msgid "And for reading files::" -msgstr "" +msgstr "為了讀取檔案: ::" #: ../../library/unittest.mock.rst:2528 msgid "Autospeccing" -msgstr "" +msgstr "Autospeccing (自動規格)" #: ../../library/unittest.mock.rst:2530 msgid "" @@ -2706,10 +2729,14 @@ msgid "" "methods have the same call signature as the original so they raise a :exc:" "`TypeError` if they are called incorrectly." msgstr "" +"自動規格以 mock 現有的 :attr:`spec` 功能作為基礎。它將 mock 的 api 限制為原始" +"物件(規格)的 api,但它是遞迴的(惰性 (lazily) 實現),因此 mock 的屬性僅具" +"有與規格的屬性相同的 api。此外,被 mock 的函式/方法具有與原始的函式/方法相同" +"的呼叫簽名,因此如果他們被不正確地呼叫,就會引發 :exc:`TypeError`。" #: ../../library/unittest.mock.rst:2537 msgid "Before I explain how auto-speccing works, here's why it is needed." -msgstr "" +msgstr "在解釋自動規格如何運作之前,我們先解釋為什麼需要它。" #: ../../library/unittest.mock.rst:2539 msgid "" @@ -2718,6 +2745,9 @@ msgid "" "these flaws is specific to the :class:`Mock` api and the other is a more " "general problem with using mock objects." msgstr "" +":class:`Mock` 是一個非常強大且靈活的物件,但是當用於從被測試的系統中 mock " +"out 物件時,它有兩個缺陷。其中一個缺陷是 :class:`Mock` api 特有的,另一個缺陷" +"是使用 mock 物件時出現的更普遍的問題。" #: ../../library/unittest.mock.rst:2544 msgid "" @@ -2725,6 +2755,8 @@ msgid "" "methods that are extremely handy: :meth:`~Mock.assert_called_with` and :meth:" "`~Mock.assert_called_once_with`." msgstr "" +"首先是 :class:`Mock` 特有的問題。:class:`Mock` 有兩個非常方便的斷言方法::" +"meth:`~Mock.assert_used_with` 和 :meth:`~Mock.assert_used_once_with`。" #: ../../library/unittest.mock.rst:2557 msgid "" @@ -2732,10 +2764,12 @@ msgid "" "with arbitrary arguments, if you misspell one of these assert methods then " "your assertion is gone:" msgstr "" +"因為 mock 會根據需要自動建立屬性,並允許你使用任意引數呼叫它們,所以如果你拼" +"錯了其中一個斷言方法,那麼你的斷言就不見了:" #: ../../library/unittest.mock.rst:2567 msgid "Your tests can pass silently and incorrectly because of the typo." -msgstr "" +msgstr "由於拼字錯誤,你的測試可能會安靜且錯誤地通過。" #: ../../library/unittest.mock.rst:2569 msgid "" @@ -2744,6 +2778,9 @@ msgid "" "*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 "" +"第二個問題對於 mock 來說更為普遍。如果你重構某些程式碼、重新命名成員等等,則" +"任何對仍然使用\\ *舊 api*\\ 但使用 mock 而不是真實物件的程式碼地測試仍然會通" +"過。這意味著即使你的程式碼已經壞了,你的測試也可以全部通過。" #: ../../library/unittest.mock.rst:2574 msgid "" @@ -2752,6 +2789,8 @@ msgid "" "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:2579 msgid "" @@ -2759,12 +2798,15 @@ msgid "" "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 "" +":mod:`mock` 已經提供了一個功能來幫助解決這個問題,其稱為 speccing。如果你使用" +"類別或實例作為 mock 的 :attr:`spec`,那麼你在 mock 上只能存取真實類別中存在的" +"屬性:" #: ../../library/unittest.mock.rst:2590 msgid "" "The spec only applies to the mock itself, so we still have the same issue " "with any methods on the mock:" -msgstr "" +msgstr "該規格僅適用於 mock 本身,因此在 mock 上的任何方法仍然有相同的問題:" #: ../../library/unittest.mock.rst:2599 msgid "" @@ -2777,10 +2819,16 @@ msgid "" "complex or deeply nested objects (like modules that import modules that " "import modules) without a big performance hit." msgstr "" +"自動規格解決了這個問題。你可以將 ``autospec=True`` 傳遞給 :func:`patch` / :" +"func:`patch.object` 或使用 :func:`create_autospec` 函式建立帶有規格的 mock。" +"如果你對 :func:`patch` 使用 ``autospec=True`` 引數,則被取代的物件將作為規格" +"物件使用。因為規格是「惰性」完成的(規格是在 mock 被存取時作為屬性被建立" +"的),所以你可以將它與非常複雜或深度巢狀使用的物件(例如連續引用的模組)一起" +"使用,而不會過於影響性能。" #: ../../library/unittest.mock.rst:2608 msgid "Here's an example of it in use::" -msgstr "" +msgstr "這是一個正在使用的例子: ::" #: ../../library/unittest.mock.rst:2618 msgid "" @@ -2788,12 +2836,15 @@ msgid "" "Request` takes two arguments in the constructor (one of which is *self*). " "Here's what happens if we try to call it incorrectly::" msgstr "" +"你可以看到 :class:`request.Request` 有一個規格。:class:`request.Request` 在建" +"構函式中接受兩個引數(其中之一是 *self*\\ )。如果我們錯誤地呼叫它,會發生以" +"下情況: ::" #: ../../library/unittest.mock.rst:2627 msgid "" "The spec also applies to instantiated classes (i.e. the return value of " "specced mocks)::" -msgstr "" +msgstr "此規格也適用於實例化的類別(即有規格的 mock 的回傳值): ::" #: ../../library/unittest.mock.rst:2634 msgid "" @@ -2802,6 +2853,9 @@ msgid "" "mock. With the spec in place any typos in our asserts will raise the correct " "error::" msgstr "" +":class:`Request` 物件不是可呼叫物件,因此實例化我們 mock out 的 :class:" +"`request.Request` 的回傳值是不可呼叫的 mock。規格到位後,斷言中的任何拼字錯誤" +"都會引發正確的錯誤: ::" #: ../../library/unittest.mock.rst:2646 msgid "" @@ -2809,12 +2863,16 @@ msgid "" "existing :func:`patch` calls and then be protected against bugs due to typos " "and api changes." msgstr "" +"在許多情況下,你只需要將 ``autospec=True`` 新增至現有的 :func:`patch` 呼叫" +"中,然後就可以防止因拼字錯誤和 api 變更而導致的錯誤。" #: ../../library/unittest.mock.rst:2650 msgid "" "As well as using *autospec* through :func:`patch` there is a :func:" "`create_autospec` for creating autospecced mocks directly:" msgstr "" +"除了透過 :func:`patch` 使用 *autospec 之外,還有一個 :func:`create_autospec` " +"用於直接建立有自動規格的 mock:" #: ../../library/unittest.mock.rst:2658 msgid "" @@ -2827,6 +2885,11 @@ msgid "" "be able to use autospec. On the other hand it is much better to design your " "objects so that introspection is safe [#]_." msgstr "" +"然而,這並非完全沒有限制,這就是為什麼它不是預設的行為。為了理解規格物件上有" +"哪些可用屬性,autospec 必須內省(存取屬性)規格。當你遍歷 mock 上的屬性時,原" +"始物件的對應遍歷正在默默發生。如果你的規格物件具有可以觸發程式碼執行的屬性或" +"描述器,那麼你可能無法使用 autospec。換句話說,設計你的物件讓內省是安全的 " +"[#]_ 會比較好。" #: ../../library/unittest.mock.rst:2667 msgid "" @@ -2835,6 +2898,9 @@ msgid "" "at all. *autospec* can't know about any dynamically created attributes and " "restricts the api to visible attributes. ::" msgstr "" +"一個更嚴重的問題是,實例屬性通常是在 :meth:`~object.__init__` 方法中建立的," +"且根本不存在於類別中。*autospec* 無法了解任何動態建立的屬性,並將 api 限制為" +"可見的屬性。: ::" #: ../../library/unittest.mock.rst:2684 msgid "" @@ -2844,6 +2910,9 @@ msgid "" "you to fetch attributes that don't exist on the spec it doesn't prevent you " "setting them::" msgstr "" +"有幾種不同的方法可以解決這個問題。最簡單但不一定是最不煩人的方法是在建立後簡" +"單地在 mock 上設定所需的屬性。因為雖然 *autospec* 不允許你取得規格中不存在的" +"屬性,但是它不會阻止你設定它們: ::" #: ../../library/unittest.mock.rst:2695 msgid "" @@ -2852,6 +2921,9 @@ msgid "" "ensure your code only *sets* valid attributes too, but obviously it prevents " "this particular scenario:" msgstr "" +"*spec* 和 *autospec* 有一個更激進的版本,它會 *確實地* 阻止你設定不存在的屬" +"性。如果你想確保你的程式碼僅能\\ *設定*\\ 有根據的屬性,那麼這會很有用,但顯" +"然它也順便阻止了這個特殊情況:" #: ../../library/unittest.mock.rst:2708 msgid "" @@ -2861,6 +2933,9 @@ msgid "" "then providing them via class attributes (shared between instances of " "course) is faster too. e.g." msgstr "" +"解決問題的最佳方法可能是新增類別屬性作為在 :meth:`~object.__init__` 中初始化" +"的實例成員的預設值。請注意,如果你僅在 :meth:`!__init__` 中設定預設屬性,那麼" +"透過類別屬性(當然在實例之間共用)提供它們也會更快。例如:" #: ../../library/unittest.mock.rst:2719 msgid "" @@ -2872,6 +2947,11 @@ msgid "" "type, autospec doesn't use a spec for members that are set to ``None``. " "These will just be ordinary mocks (well - MagicMocks):" msgstr "" +"這就帶來了另一個問題。為稍後將成為不同型別的物件的成員提供預設值 “None” 是相" +"對常見的。``None`` 作為規格是無效的,因為它不允許你存取其上的\\ *任何*\\ 屬性" +"或方法。由於 ``None`` 作為規格\\ *永遠不會*\\ 有用,並且可能表示通常屬於其他" +"型別的成員,因此自動規格不會對設定為 ``None`` 的成員使用規格。這些會只是普通" +"的 mock(通常是 MagicMocks):" #: ../../library/unittest.mock.rst:2734 msgid "" @@ -2883,6 +2963,11 @@ msgid "" "the spec. Thankfully :func:`patch` supports this - you can simply pass the " "alternative object as the *autospec* argument::" msgstr "" +"如果修改正式生產 (production) 類別以新增預設值不符合你的喜好,那麼還有更多選" +"擇。其中之一就是簡單地使用實例作為規格而不是使用類別。另一種是建立一個正式生" +"產類別的子類別,並將預設值新增至子別中,而不影響正式生產類別。這兩個都需要你" +"使用替代物件作為規格。值得慶幸的是 :func:`patch` 支援這一點 - 您可以簡單地將" +"替代物件作為 *autospec* 引數傳遞: ::" #: ../../library/unittest.mock.rst:2755 msgid "" @@ -2890,10 +2975,12 @@ msgid "" "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 "" +"這只適用於類別或已經實例化的物件。呼叫一個被 mock 的類別來建立一個 mock 實例" +"\\ *不會*\\ 建立真的實例。它僅查找屬性及呼叫已完成的 :func:`dir`。" #: ../../library/unittest.mock.rst:2760 msgid "Sealing mocks" -msgstr "" +msgstr "密封 mock" #: ../../library/unittest.mock.rst:2769 msgid "" @@ -2901,6 +2988,8 @@ msgid "" "attribute of the mock being sealed or any of its attributes that are already " "mocks recursively." msgstr "" +"當存取被密封的 mock 的屬性或其任何已經遞迴 mock 的屬性時,seal 將停用 mock 的" +"自動建立。" #: ../../library/unittest.mock.rst:2772 msgid "" @@ -2908,3 +2997,5 @@ msgid "" "won't be considered in the sealing chain. This allows one to prevent seal " "from fixing part of the mock object. ::" msgstr "" +"如果將具有名稱或規格的 mock 實例指派給屬性,則不會出現在密封鏈中。這表示可藉" +"由固定 mock 物件的一部分來防止密封。: ::" From 738c9207a4383d0534a1b09a63c46dd35223aac6 Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 23 Feb 2024 00:13:52 +0800 Subject: [PATCH 07/16] fix: try to fix render error --- library/unittest.mock.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 32c73fcb53..e964500dc5 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-02-22 22:28+0800\n" +"PO-Revision-Date: 2024-02-23 00:13+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2700,9 +2700,9 @@ msgid "" "*returned object* that is used as a context manager (and has :meth:`~object." "__enter__` and :meth:`~object.__exit__` called)." msgstr "" -"問題是,即使你 mock 了對 :func:`open` 的呼叫,它也是作為情境管理器使用的 *回" -"傳物件*\\ (且其 :meth:`~object.__enter__` 和 :meth:`~ object.__exit__ ` 已被" -"呼叫)。" +"問題是,即使你 mock 了對 :func:`open` 的呼叫,它也是作為情境管理器使用的\\ *" +"回傳物件*\\ (且其 :meth:`~object.__enter__` 和 :meth:`~ object.__exit__ ` 已" +"被呼叫)。" #: ../../library/unittest.mock.rst:2498 msgid "" @@ -2710,7 +2710,7 @@ msgid "" "fiddly enough that a helper function is useful. ::" msgstr "" "使用 :class:`MagicMock` mock 情境管理器相當常見並且精細,因此輔助函式就非常有" -"用。: ::" +"用: ::" #: ../../library/unittest.mock.rst:2515 msgid "And for reading files::" From 1b9233ee32aa6c4235a3d2b351a791cc20d75cf9 Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 23 Feb 2024 00:14:36 +0800 Subject: [PATCH 08/16] fix: try to fix render error --- library/unittest.mock.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index e964500dc5..3efdeb39a0 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -2701,7 +2701,7 @@ msgid "" "__enter__` and :meth:`~object.__exit__` called)." msgstr "" "問題是,即使你 mock 了對 :func:`open` 的呼叫,它也是作為情境管理器使用的\\ *" -"回傳物件*\\ (且其 :meth:`~object.__enter__` 和 :meth:`~ object.__exit__ ` 已" +"回傳物件*\\ (且其 :meth:`~object.__enter__` 和 :meth:`~ object.__exit__` 已" "被呼叫)。" #: ../../library/unittest.mock.rst:2498 From 8ed84af78fc9ef5e5727b7888bb9562892d9e942 Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 23 Feb 2024 00:19:49 +0800 Subject: [PATCH 09/16] fix: try to fix render error --- library/unittest.mock.po | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 3efdeb39a0..e597e65abd 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-02-23 00:13+0800\n" +"PO-Revision-Date: 2024-02-23 00:19+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2871,8 +2871,8 @@ msgid "" "As well as using *autospec* through :func:`patch` there is a :func:" "`create_autospec` for creating autospecced mocks directly:" msgstr "" -"除了透過 :func:`patch` 使用 *autospec 之外,還有一個 :func:`create_autospec` " -"用於直接建立有自動規格的 mock:" +"除了透過 :func:`patch` 使用 *autospec* 之外,還有一個 :func:" +"`create_autospec` 用於直接建立有自動規格的 mock:" #: ../../library/unittest.mock.rst:2658 msgid "" @@ -2910,9 +2910,9 @@ msgid "" "you to fetch attributes that don't exist on the spec it doesn't prevent you " "setting them::" msgstr "" -"有幾種不同的方法可以解決這個問題。最簡單但不一定是最不煩人的方法是在建立後簡" -"單地在 mock 上設定所需的屬性。因為雖然 *autospec* 不允許你取得規格中不存在的" -"屬性,但是它不會阻止你設定它們: ::" +"有幾種不同的方法可以解決這個問題。最簡單但可能有點煩人的方法是在建立後簡單地" +"在 mock 上設定所需的屬性。因為雖然 *autospec* 不允許你取得規格中不存在的屬" +"性,但是它不會阻止你設定它們: ::" #: ../../library/unittest.mock.rst:2695 msgid "" From 7601f0b37409a4ed994c69f8b326c5f166a23a4f Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 23 Feb 2024 09:38:49 +0800 Subject: [PATCH 10/16] Update library/unittest.mock.po --- library/unittest.mock.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index e597e65abd..98e52a04bd 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -2597,7 +2597,7 @@ msgid "" "attributes from the original are shown, even if they haven't been accessed " "yet:" msgstr "" -"當過濾方式開啟時, ``dir(some_mock)`` 僅會顯示有用的屬性,並將包括通常不會顯" +"當過濾方式開啟時,``dir(some_mock)`` 僅會顯示有用的屬性,並將包括通常不會顯" "示的任何動態建立的屬性。如果 mock 是使用 *spec*\\ (或 *autospec*\\ )來建立" "的,那麼源頭的所有屬性都會顯示,即使它們尚未被存取:" From a982888545d388f9ab6ac0220e62f37ed088dd82 Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 23 Feb 2024 09:38:56 +0800 Subject: [PATCH 11/16] Update library/unittest.mock.po --- library/unittest.mock.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 98e52a04bd..6446405b5c 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -2641,7 +2641,7 @@ msgid "" "default) then a :class:`MagicMock` will be created for you, with the API " "limited to methods or attributes available on standard file handles." msgstr "" -"*mock* 引數是要配置的 mock 物件。如果其 ``None``\\ (預設值),那麼就會為你建" +"*mock* 引數是要配置的 mock 物件。如果其為 ``None``\\ (預設值),那麼就會為你建" "立一個 :class:`MagicMock`,其 API 限制在標準檔案處理上可用的方法或屬性。" #: ../../library/unittest.mock.rst:2466 From ee00ebed443ce40468fc7c067dd52339902d8c32 Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 23 Feb 2024 09:39:02 +0800 Subject: [PATCH 12/16] Update library/unittest.mock.po --- library/unittest.mock.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 6446405b5c..2da14c2120 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -2921,7 +2921,7 @@ msgid "" "ensure your code only *sets* valid attributes too, but obviously it prevents " "this particular scenario:" msgstr "" -"*spec* 和 *autospec* 有一個更激進的版本,它會 *確實地* 阻止你設定不存在的屬" +"*spec* 和 *autospec* 有一個更激進的版本,它會\\ *確實地*\\ 阻止你設定不存在的屬" "性。如果你想確保你的程式碼僅能\\ *設定*\\ 有根據的屬性,那麼這會很有用,但顯" "然它也順便阻止了這個特殊情況:" From d6ec40aaa7b2bd2f096f3efcd13569229b4e579d Mon Sep 17 00:00:00 2001 From: Payon Date: Mon, 18 Mar 2024 00:52:17 +0800 Subject: [PATCH 13/16] Apply suggestions from code review for reviewer's suggestions, part 1. Co-authored-by: mindihx --- library/unittest.mock.po | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 2da14c2120..b509c517e9 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -2362,7 +2362,7 @@ msgid "" "The ``sentinel`` attributes now preserve their identity when they are :mod:" "`copied ` or :mod:`pickled `." msgstr "" -"``哨兵``\\ 屬性現在在是 :mod:`copied ` 或 :mod:`pickled ` 時保" +"``哨兵``\\ 屬性現在當被\\ :mod:`複製 `\\ 或\\ :mod:`序列化 `\\ 時會保" "留其識別性。" #: ../../library/unittest.mock.rst:2203 @@ -2373,7 +2373,7 @@ msgid "" "creating and testing the identity of objects like this." msgstr "" "在測試時,有時你需要測試特定物件是否作為引數被傳遞給另一個方法或回傳。建立命" -"名的哨兵物件來測試這一點是常見的。:data:`sentinel` 提供了一種建立和測試此類物" +"名的哨兵物件來測試這一點是常見的。:data:`sentinel` 提供了一種此類建立和測試物" "件識別性的便利方式。" #: ../../library/unittest.mock.rst:2208 @@ -2419,7 +2419,7 @@ msgid "" "a list of all the intermediate calls as well as the final call." msgstr "" "對於表示多個呼叫的 call 物件,:meth:`call_list` 回傳所有中間呼叫以及最終呼叫" -"的清單。" +"的串列。" #: ../../library/unittest.mock.rst:2252 msgid "" @@ -2429,7 +2429,7 @@ msgid "" "constructing the sequence of calls can be tedious." msgstr "" "``call_list`` 在對\\ \"鍊接呼叫 (chained calls)\"\\ 進行斷言時特別有用。鍊接" -"呼叫是對單行程式碼進行的多次呼叫。這會導致 mock 上的 :attr:`~Mock." +"呼叫是在單行程式碼進行的多次呼叫。這會導致 mock 上的 :attr:`~Mock." "mock_calls` 中出現多個項目。手動建構呼叫序列會相當單調乏味。" #: ../../library/unittest.mock.rst:2257 @@ -2448,7 +2448,7 @@ msgid "" "to get at the individual arguments they contain." msgstr "" "取決於它的建構方式,一個 ``call`` 物件會是(位置引數, 關鍵字引數)的元組,或" -"是(名稱, 位置引數, 關鍵字引數)的元組。當你自己建構它們時,這並不是那麼有" +"是 (名稱, 位置引數, 關鍵字引數) 的元組。當你自己建構它們時,這並不是那麼有" "趣,但是 :attr:`Mock.call_args`、:attr:`Mock.call_args_list` 和 :attr:`Mock." "mock_calls` 屬性中的 ``call`` 物件可以被內省以取得它們包含的各個引數。" @@ -2462,7 +2462,7 @@ msgid "" msgstr "" ":attr:`Mock.call_args` 和 :attr:`Mock.call_args_list` 中的 ``call`` 物件是" "(位置引數, 關鍵字引數)的二元組,而 :attr:`Mock.mock_calls`中的 ``call`` 物" -"件以及你自己建立 ``call`` 物件是(名稱, 位置引數, 關鍵字引數)的三元組。" +"件以及你自己建立的 ``call`` 物件是(名稱, 位置引數, 關鍵字引數)的三元組。" #: ../../library/unittest.mock.rst:2286 msgid "" @@ -2509,7 +2509,7 @@ msgid "" msgstr "" "如果一個類別作為規格使用,則 mock(該類別的實例)的回傳值將具有相同的規格。你" "可以透過傳遞 ``instance=True`` 來使用一個類別作為一個實例物件的規格。只有當 " -"mock 的實例是可呼叫物件時,回傳的 mock 才可以被呼叫。" +"mock 的實例是可呼叫物件時,回傳的 mock 才會是可呼叫物件。" #: ../../library/unittest.mock.rst:2338 msgid "" @@ -2584,7 +2584,7 @@ msgid "" "filtering, or need to switch it off for diagnostic purposes, then set ``mock." "FILTER_DIR = False``." msgstr "" -":data:`FILTER_DIR` 是一個模組級別的變數,用於控制 mock 物件響應 :func:`dir`的" +":data:`FILTER_DIR` 是一個模組級別的變數,用於控制 mock 物件回應 :func:`dir`的" "方式。其預設值為 ``True``,它使用以下描述的過濾方式來只顯示有用的成員。如果你" "不喜歡這個過濾方式,或由於診斷意圖而需要將其關閉,請設定 ``mock.FILTER_DIR = " "False``。" @@ -2656,12 +2656,12 @@ msgid "" "in-memory filesystem packages on `PyPI `_ can offer a " "realistic filesystem for testing." msgstr "" -"*read_data*\\ 是一個檔案處理的 :meth:`~io.IOBase.read`、:meth:`~io.IOBase." -"readline` 和 :meth:`~io.IOBase.readlines` 方法的回傳字串。對這些方法的呼叫將" +"*read_data* 是檔案處理方法 :meth:`~io.IOBase.read`、:meth:`~io.IOBase." +"readline` 和 :meth:`~io.IOBase.readlines` 的回傳字串。對這些方法的呼叫將" "從\\ *read_data*\\ 取得資料,直到資料耗盡。對這些方法的 mock 非常單純:每次呼" "叫\\ *mock*\\ 時,*read_data* 都會倒回到起點。如果你需要對提供給測試程式碼的" "資料進行更多控制,你會需要自行客製化這個 mock。如果這樣還不夠,`PyPI " -"`_ 上的其中一個記憶體內檔案系統套件 (in-memory filesystem) " +"`_ 上的其中一個記憶體內檔案系統 (in-memory filesystem) 套件 " "可以提供用於測試的真實檔案系統。" #: ../../library/unittest.mock.rst:2476 @@ -2718,7 +2718,7 @@ msgstr "為了讀取檔案: ::" #: ../../library/unittest.mock.rst:2528 msgid "Autospeccing" -msgstr "Autospeccing (自動規格)" +msgstr "Autospeccing(自動規格)" #: ../../library/unittest.mock.rst:2530 msgid "" @@ -2732,7 +2732,7 @@ msgstr "" "自動規格以 mock 現有的 :attr:`spec` 功能作為基礎。它將 mock 的 api 限制為原始" "物件(規格)的 api,但它是遞迴的(惰性 (lazily) 實現),因此 mock 的屬性僅具" "有與規格的屬性相同的 api。此外,被 mock 的函式/方法具有與原始的函式/方法相同" -"的呼叫簽名,因此如果他們被不正確地呼叫,就會引發 :exc:`TypeError`。" +"的呼叫簽名,因此如果它們被不正確地呼叫,就會引發 :exc:`TypeError`。" #: ../../library/unittest.mock.rst:2537 msgid "Before I explain how auto-speccing works, here's why it is needed." @@ -2779,7 +2779,7 @@ msgid "" "means your tests can all pass even though your code is broken." msgstr "" "第二個問題對於 mock 來說更為普遍。如果你重構某些程式碼、重新命名成員等等,則" -"任何對仍然使用\\ *舊 api*\\ 但使用 mock 而不是真實物件的程式碼地測試仍然會通" +"任何對仍然使用\\ *舊 api* 但使用 mock 而不是真實物件的程式碼的測試仍然會通" "過。這意味著即使你的程式碼已經壞了,你的測試也可以全部通過。" #: ../../library/unittest.mock.rst:2574 @@ -2898,8 +2898,8 @@ msgid "" "at all. *autospec* can't know about any dynamically created attributes and " "restricts the api to visible attributes. ::" msgstr "" -"一個更嚴重的問題是,實例屬性通常是在 :meth:`~object.__init__` 方法中建立的," -"且根本不存在於類別中。*autospec* 無法了解任何動態建立的屬性,並將 api 限制為" +"一個更嚴重的問題是,在 :meth:`~object.__init__` 方法中建立實例屬性是常見的," +"而其根本不存在於類別中。*autospec* 無法知道任何動態建立的屬性,並將 api 限制為" "可見的屬性。: ::" #: ../../library/unittest.mock.rst:2684 @@ -2948,7 +2948,7 @@ msgid "" "These will just be ordinary mocks (well - MagicMocks):" msgstr "" "這就帶來了另一個問題。為稍後將成為不同型別的物件的成員提供預設值 “None” 是相" -"對常見的。``None`` 作為規格是無效的,因為它不允許你存取其上的\\ *任何*\\ 屬性" +"對常見的。``None`` 作為規格是無用的,因為它不允許你存取其上的\\ *任何*\\ 屬性" "或方法。由於 ``None`` 作為規格\\ *永遠不會*\\ 有用,並且可能表示通常屬於其他" "型別的成員,因此自動規格不會對設定為 ``None`` 的成員使用規格。這些會只是普通" "的 mock(通常是 MagicMocks):" @@ -2965,7 +2965,7 @@ msgid "" msgstr "" "如果修改正式生產 (production) 類別以新增預設值不符合你的喜好,那麼還有更多選" "擇。其中之一就是簡單地使用實例作為規格而不是使用類別。另一種是建立一個正式生" -"產類別的子類別,並將預設值新增至子別中,而不影響正式生產類別。這兩個都需要你" +"產類別的子類別,並將預設值新增至子類別中,而不影響正式生產類別。這兩個都需要你" "使用替代物件作為規格。值得慶幸的是 :func:`patch` 支援這一點 - 您可以簡單地將" "替代物件作為 *autospec* 引數傳遞: ::" From 606b486ccb73e5696d17cdc2f9a6d327c0a83c68 Mon Sep 17 00:00:00 2001 From: Payon Date: Mon, 18 Mar 2024 20:58:42 +0800 Subject: [PATCH 14/16] fix: for reviewer's suggestions, part 2. --- library/unittest.mock.po | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index b509c517e9..28d91317b2 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-02-23 00:19+0800\n" +"PO-Revision-Date: 2024-03-18 20:57+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -797,8 +797,8 @@ msgid "" "whether they were passed positionally or by name::" msgstr "" "在匹配對 mock 的呼叫時,使用 *spec*\\ (或 *spec_set*\\ )建立的可呼叫 mock " -"將會內省規格物件的簽名 (signature)。因此,它可以匹配實際呼叫的引數,無論它們" -"是按位置傳遞還是按名稱傳遞:\n" +"將會內省 (introspect) 規格物件的簽名 (signature)。因此,它可以匹配實際呼叫的" +"引數,無論它們是按位置傳遞還是按名稱傳遞:\n" "\n" "::" @@ -2362,8 +2362,8 @@ msgid "" "The ``sentinel`` attributes now preserve their identity when they are :mod:" "`copied ` or :mod:`pickled `." msgstr "" -"``哨兵``\\ 屬性現在當被\\ :mod:`複製 `\\ 或\\ :mod:`序列化 `\\ 時會保" -"留其識別性。" +"``哨兵``\\ 屬性現在當被\\ :mod:`複製 `\\ 或\\ :mod:`序列化 `\\ " +"時會保留其識別性。" #: ../../library/unittest.mock.rst:2203 msgid "" @@ -2428,9 +2428,9 @@ msgid "" "results in multiple entries in :attr:`~Mock.mock_calls` on a mock. Manually " "constructing the sequence of calls can be tedious." msgstr "" -"``call_list`` 在對\\ \"鍊接呼叫 (chained calls)\"\\ 進行斷言時特別有用。鍊接" -"呼叫是在單行程式碼進行的多次呼叫。這會導致 mock 上的 :attr:`~Mock." -"mock_calls` 中出現多個項目。手動建構呼叫序列會相當單調乏味。" +"``call_list`` 在對「鍊接呼叫 (chained calls)」進行斷言時特別有用。鍊接呼叫是" +"在單行程式碼進行的多次呼叫。這會導致 mock 上的 :attr:`~Mock.mock_calls` 中出" +"現多個項目。手動建構呼叫序列會相當單調乏味。" #: ../../library/unittest.mock.rst:2257 msgid "" @@ -2597,8 +2597,8 @@ msgid "" "attributes from the original are shown, even if they haven't been accessed " "yet:" msgstr "" -"當過濾方式開啟時,``dir(some_mock)`` 僅會顯示有用的屬性,並將包括通常不會顯" -"示的任何動態建立的屬性。如果 mock 是使用 *spec*\\ (或 *autospec*\\ )來建立" +"當過濾方式開啟時,``dir(some_mock)`` 僅會顯示有用的屬性,並將包括通常不會顯示" +"的任何動態建立的屬性。如果 mock 是使用 *spec*\\ (或 *autospec*\\ )來建立" "的,那麼源頭的所有屬性都會顯示,即使它們尚未被存取:" #: ../../library/unittest.mock.rst:2428 @@ -2641,8 +2641,8 @@ msgid "" "default) then a :class:`MagicMock` will be created for you, with the API " "limited to methods or attributes available on standard file handles." msgstr "" -"*mock* 引數是要配置的 mock 物件。如果其為 ``None``\\ (預設值),那麼就會為你建" -"立一個 :class:`MagicMock`,其 API 限制在標準檔案處理上可用的方法或屬性。" +"*mock* 引數是要配置的 mock 物件。如果其為 ``None``\\ (預設值),那麼就會為你" +"建立一個 :class:`MagicMock`,其 API 限制在標準檔案處理上可用的方法或屬性。" #: ../../library/unittest.mock.rst:2466 msgid "" @@ -2657,12 +2657,12 @@ msgid "" "realistic filesystem for testing." msgstr "" "*read_data* 是檔案處理方法 :meth:`~io.IOBase.read`、:meth:`~io.IOBase." -"readline` 和 :meth:`~io.IOBase.readlines` 的回傳字串。對這些方法的呼叫將" -"從\\ *read_data*\\ 取得資料,直到資料耗盡。對這些方法的 mock 非常單純:每次呼" -"叫\\ *mock*\\ 時,*read_data* 都會倒回到起點。如果你需要對提供給測試程式碼的" -"資料進行更多控制,你會需要自行客製化這個 mock。如果這樣還不夠,`PyPI " -"`_ 上的其中一個記憶體內檔案系統 (in-memory filesystem) 套件 " -"可以提供用於測試的真實檔案系統。" +"readline` 和 :meth:`~io.IOBase.readlines` 的回傳字串。對這些方法的呼叫將從\\ " +"*read_data*\\ 取得資料,直到資料耗盡。對這些方法的 mock 非常單純:每次呼叫\\ " +"*mock*\\ 時,*read_data* 都會倒回到起點。如果你需要對提供給測試程式碼的資料進" +"行更多控制,你會需要自行客製化這個 mock。如果這樣還不夠,`PyPI `_ 上的其中一個記憶體內檔案系統 (in-memory filesystem) 套件 可以提供用於" +"測試的真實檔案系統。" #: ../../library/unittest.mock.rst:2476 msgid "" @@ -2899,8 +2899,8 @@ msgid "" "restricts the api to visible attributes. ::" msgstr "" "一個更嚴重的問題是,在 :meth:`~object.__init__` 方法中建立實例屬性是常見的," -"而其根本不存在於類別中。*autospec* 無法知道任何動態建立的屬性,並將 api 限制為" -"可見的屬性。: ::" +"而其根本不存在於類別中。*autospec* 無法知道任何動態建立的屬性,並將 api 限制" +"為可見的屬性。: ::" #: ../../library/unittest.mock.rst:2684 msgid "" @@ -2921,8 +2921,8 @@ msgid "" "ensure your code only *sets* valid attributes too, but obviously it prevents " "this particular scenario:" msgstr "" -"*spec* 和 *autospec* 有一個更激進的版本,它會\\ *確實地*\\ 阻止你設定不存在的屬" -"性。如果你想確保你的程式碼僅能\\ *設定*\\ 有根據的屬性,那麼這會很有用,但顯" +"*spec* 和 *autospec* 有一個更激進的版本,它會\\ *確實地*\\ 阻止你設定不存在的" +"屬性。如果你想確保你的程式碼僅能\\ *設定*\\ 有效的屬性,那麼這會很有用,但顯" "然它也順便阻止了這個特殊情況:" #: ../../library/unittest.mock.rst:2708 @@ -2965,9 +2965,9 @@ msgid "" msgstr "" "如果修改正式生產 (production) 類別以新增預設值不符合你的喜好,那麼還有更多選" "擇。其中之一就是簡單地使用實例作為規格而不是使用類別。另一種是建立一個正式生" -"產類別的子類別,並將預設值新增至子類別中,而不影響正式生產類別。這兩個都需要你" -"使用替代物件作為規格。值得慶幸的是 :func:`patch` 支援這一點 - 您可以簡單地將" -"替代物件作為 *autospec* 引數傳遞: ::" +"產類別的子類別,並將預設值新增至子類別中,而不影響正式生產類別。這兩個都需要" +"你使用替代物件作為規格。值得慶幸的是 :func:`patch` 支援這一點 - 你可以簡單地" +"將替代物件作為 *autospec* 引數傳遞: ::" #: ../../library/unittest.mock.rst:2755 msgid "" From fdddff17cc6ca7d785b689da7a3ac4c75012e7f9 Mon Sep 17 00:00:00 2001 From: Payon Date: Tue, 19 Mar 2024 00:54:29 +0800 Subject: [PATCH 15/16] fix: try to reverse the sentence --- library/unittest.mock.po | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 28d91317b2..0badf74fe9 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-03-18 20:57+0800\n" +"PO-Revision-Date: 2024-03-19 00:53+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -2043,9 +2043,9 @@ msgid "" "``__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__``" +"``__sub__``、``__mul__``、``__matmul__``、``__truediv__``、``__floordiv__``、" +"``__mod__``、``__divmod__``、``__lshift__``、``__rshift__``、``__and__``、" +"``__xor__``、``__or__`` 和 ``__pow__``" #: ../../library/unittest.mock.rst:2030 msgid "" @@ -2408,10 +2408,10 @@ msgid "" "mock_calls` and :attr:`~Mock.method_calls`. :func:`call` can also be used " "with :meth:`~Mock.assert_has_calls`." msgstr "" -":func:`call` 是一個用於進行更簡單的斷言的輔助物件,與 :attr:`~Mock." -"call_args`、:attr:`~Mock.call_args_list`、:attr:`~Mock.mock_calls` 和 :attr:" -"`~Mock.method_calls` 相比。:func:`call` 也可以與 :meth:`~Mock." -"assert_has_calls` 一起使用。" +"與 :attr:`~Mock.call_args`、:attr:`~Mock.call_args_list`、:attr:`~Mock." +"mock_calls` 和 :attr:`~Mock.method_calls` 相比,:func:`call` 是一個用於進行更" +"簡單的斷言的輔助物件。:func:`call` 也可以與 :meth:`~Mock.assert_has_calls` 一" +"起使用。" #: ../../library/unittest.mock.rst:2248 msgid "" From 70341edaa8e060339e39f2c2ebc0c57f859b1183 Mon Sep 17 00:00:00 2001 From: Payon Date: Sun, 24 Mar 2024 22:01:35 +0800 Subject: [PATCH 16/16] Apply suggestions from code review for review p2. Co-authored-by: mindihx --- library/unittest.mock.po | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 0badf74fe9..d1cbb0496a 100644 --- a/library/unittest.mock.po +++ b/library/unittest.mock.po @@ -798,9 +798,7 @@ msgid "" msgstr "" "在匹配對 mock 的呼叫時,使用 *spec*\\ (或 *spec_set*\\ )建立的可呼叫 mock " "將會內省 (introspect) 規格物件的簽名 (signature)。因此,它可以匹配實際呼叫的" -"引數,無論它們是按位置傳遞還是按名稱傳遞:\n" -"\n" -"::" +"引數,無論它們是按位置傳遞還是按名稱傳遞: :: #: ../../library/unittest.mock.rst:812 msgid "" @@ -2657,9 +2655,9 @@ msgid "" "realistic filesystem for testing." msgstr "" "*read_data* 是檔案處理方法 :meth:`~io.IOBase.read`、:meth:`~io.IOBase." -"readline` 和 :meth:`~io.IOBase.readlines` 的回傳字串。對這些方法的呼叫將從\\ " -"*read_data*\\ 取得資料,直到資料耗盡。對這些方法的 mock 非常單純:每次呼叫\\ " -"*mock*\\ 時,*read_data* 都會倒回到起點。如果你需要對提供給測試程式碼的資料進" +"readline` 和 :meth:`~io.IOBase.readlines` 的回傳字串。對這些方法的呼叫將從 " +"*read_data* 取得資料,直到資料耗盡。對這些方法的 mock 非常單純:每次呼叫 " +"*mock* 時,*read_data* 都會倒回到起點。如果你需要對提供給測試程式碼的資料進" "行更多控制,你會需要自行客製化這個 mock。如果這樣還不夠,`PyPI `_ 上的其中一個記憶體內檔案系統 (in-memory filesystem) 套件 可以提供用於" "測試的真實檔案系統。" @@ -2671,7 +2669,7 @@ msgid "" "than returning it on each call." msgstr "" "新增對 :meth:`~io.IOBase.readline` 和 :meth:`~io.IOBase.readlines` 的支援。:" -"meth:`~io.IOBase.read` 的 mock 更改為消耗\\ *read_data*\\ 而不是在每次呼叫時" +"meth:`~io.IOBase.read` 的 mock 更改為消耗 *read_data* 而不是在每次呼叫時" "回傳它。" #: ../../library/unittest.mock.rst:2481 @@ -2714,7 +2712,7 @@ msgstr "" #: ../../library/unittest.mock.rst:2515 msgid "And for reading files::" -msgstr "為了讀取檔案: ::" +msgstr "以及讀取檔案: ::" #: ../../library/unittest.mock.rst:2528 msgid "Autospeccing" @@ -2779,7 +2777,7 @@ msgid "" "means your tests can all pass even though your code is broken." msgstr "" "第二個問題對於 mock 來說更為普遍。如果你重構某些程式碼、重新命名成員等等,則" -"任何對仍然使用\\ *舊 api* 但使用 mock 而不是真實物件的程式碼的測試仍然會通" +"對任何仍然使用\\ *舊 api* 但使用 mock 而不是真實物件的程式碼的測試仍然會通" "過。這意味著即使你的程式碼已經壞了,你的測試也可以全部通過。" #: ../../library/unittest.mock.rst:2574 @@ -2947,7 +2945,7 @@ msgid "" "type, autospec doesn't use a spec for members that are set to ``None``. " "These will just be ordinary mocks (well - MagicMocks):" msgstr "" -"這就帶來了另一個問題。為稍後將成為不同型別的物件的成員提供預設值 “None” 是相" +"這就帶來了另一個問題。為稍後將成為不同型別的物件的成員提供預設值 ``None`` 是相" "對常見的。``None`` 作為規格是無用的,因為它不允許你存取其上的\\ *任何*\\ 屬性" "或方法。由於 ``None`` 作為規格\\ *永遠不會*\\ 有用,並且可能表示通常屬於其他" "型別的成員,因此自動規格不會對設定為 ``None`` 的成員使用規格。這些會只是普通" @@ -2976,7 +2974,7 @@ msgid "" "is only attribute lookups - along with calls to :func:`dir` - that are done." msgstr "" "這只適用於類別或已經實例化的物件。呼叫一個被 mock 的類別來建立一個 mock 實例" -"\\ *不會*\\ 建立真的實例。它僅查找屬性及呼叫已完成的 :func:`dir`。" +"\\ *不會*\\ 建立真的實例。它僅查找屬性及對 :func:`dir` 的呼叫。" #: ../../library/unittest.mock.rst:2760 msgid "Sealing mocks"