From 2d6d5df267cc02fc56157e9e381827a4be27f96e Mon Sep 17 00:00:00 2001 From: Payon Date: Sun, 14 Jan 2024 01:18:30 +0800 Subject: [PATCH 1/8] feat: to rst:590 --- library/unittest.mock-examples.po | 158 +++++++++++++++++++++++++----- 1 file changed, 132 insertions(+), 26 deletions(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index d0479ae448..79d8cdbdab 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-09-09 00:03+0000\n" -"PO-Revision-Date: 2023-11-21 22:16+0800\n" +"PO-Revision-Date: 2024-01-17 01:09+0800\n" "Last-Translator: Liang-Bo Wang \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.4\n" +"X-Generator: Poedit 3.4.1\n" #: ../../library/unittest.mock-examples.rst:2 msgid ":mod:`unittest.mock` --- getting started" @@ -131,7 +131,7 @@ msgstr "" #: ../../library/unittest.mock-examples.rst:106 msgid "Mocking Classes" -msgstr "" +msgstr "Mock 類別" #: ../../library/unittest.mock-examples.rst:108 msgid "" @@ -140,6 +140,9 @@ msgid "" "Instances are created by *calling the class*. This means you access the " "\"mock instance\" by looking at the return value of the mocked class." msgstr "" +"一個常見的例子是 mock 被測試的程式碼實例化的類別。 當你 patch 一個類別時,該" +"類別就會被替換為 mock。 實例是透過*呼叫類別*建立的。 這代表你可以透過查看被 " +"mock 的類別的回傳值來存取「mock 實例」。" #: ../../library/unittest.mock-examples.rst:113 msgid "" @@ -149,10 +152,14 @@ msgid "" "mock, so it is configured by modifying the mock :attr:`~Mock." "return_value`. ::" msgstr "" +"在下面的範例中,我們有一個函式 ``some_function``,它實例化 ``Foo`` 並呼叫它的" +"方法。 對 :func:`patch` 的呼叫將類別 ``Foo`` 替換為一個 mock。``Foo`` 實例是" +"呼叫 mock 的結果,因此它是透過修改 mock :attr:`~Mock.return_value` 來配置" +"的。: ::" #: ../../library/unittest.mock-examples.rst:130 msgid "Naming your mocks" -msgstr "" +msgstr "命名你的 mock" #: ../../library/unittest.mock-examples.rst:132 msgid "" @@ -160,10 +167,12 @@ msgid "" "the mock and can be helpful when the mock appears in test failure messages. " "The name is also propagated to attributes or methods of the mock:" msgstr "" +"為你的 mock 命名可能會很有用。 這個名稱會顯示在 mock 的 repr 中,且當 mock 出" +"現在測試的失敗訊息中時,名稱會很有幫助。 該名稱也會傳播到 mock 的屬性或方法:" #: ../../library/unittest.mock-examples.rst:144 msgid "Tracking all Calls" -msgstr "" +msgstr "追蹤所有呼叫" #: ../../library/unittest.mock-examples.rst:146 msgid "" @@ -171,6 +180,8 @@ msgid "" "`~Mock.mock_calls` attribute records all calls to child attributes of the " "mock - and also to their children." msgstr "" +"通常你會想要追蹤對一個方法的多個呼叫。:attr:`~Mock.mock_calls` 屬性記錄對 " +"mock 的子屬性以及其子屬性的所有呼叫。" #: ../../library/unittest.mock-examples.rst:158 msgid "" @@ -179,12 +190,15 @@ msgid "" "well as asserting that the calls you expected have been made, you are also " "checking that they were made in the right order and with no additional calls:" msgstr "" +"如果你對 ``mock_calls`` 做出斷言並且有任何不預期的方法被呼叫,則斷言將失敗。 " +"這很有用,因為除了斷言你期望的呼叫已經進行之外,你還可以檢查它們是否按正確的" +"順序進行,並且沒有多餘的呼叫:" #: ../../library/unittest.mock-examples.rst:163 msgid "" "You use the :data:`call` object to construct lists for comparing with " "``mock_calls``:" -msgstr "" +msgstr "你可以使用 :data:`call` 物件來建構串列以與 ``mock_calls`` 進行比較:" #: ../../library/unittest.mock-examples.rst:170 msgid "" @@ -192,26 +206,28 @@ msgid "" "it is not possible to track nested calls where the parameters used to create " "ancestors are important:" msgstr "" +"然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的祖先的" +"參數的巢狀呼叫:" #: ../../library/unittest.mock-examples.rst:181 msgid "Setting Return Values and Attributes" -msgstr "" +msgstr "設定回傳值和屬性" #: ../../library/unittest.mock-examples.rst:183 msgid "Setting the return values on a mock object is trivially easy:" -msgstr "" +msgstr "在 mock 物件上設定回傳值非常簡單:" #: ../../library/unittest.mock-examples.rst:190 msgid "Of course you can do the same for methods on the mock:" -msgstr "" +msgstr "當然,你可以對 mock 上的方法執行相同的操作:" #: ../../library/unittest.mock-examples.rst:197 msgid "The return value can also be set in the constructor:" -msgstr "" +msgstr "回傳值也可以在建構函式中設定:" #: ../../library/unittest.mock-examples.rst:203 msgid "If you need an attribute setting on your mock, just do it:" -msgstr "" +msgstr "如果你需要在 mock 上進行屬性設置,只需執行以下操作:" #: ../../library/unittest.mock-examples.rst:210 msgid "" @@ -219,22 +235,28 @@ msgid "" "``mock.connection.cursor().execute(\"SELECT 1\")``. If we wanted this call " "to return a list, then we have to configure the result of the nested call." msgstr "" +"有時你想要 mock 更複雜的情況,例如 ``mock.connection.cursor()." +"execute(\"SELECT 1\")``。 如果我們希望此呼叫回傳一個串列,那麼我們就必須配置" +"巢狀呼叫的結果。" #: ../../library/unittest.mock-examples.rst:214 msgid "" "We can use :data:`call` to construct the set of calls in a \"chained call\" " "like this for easy assertion afterwards:" msgstr "" +"如下所示,我們可以使用 :data:`call` 在「鍊接呼叫 (chained call)」中建構呼叫的" +"集合,以便在之後輕鬆的進行斷言:" #: ../../library/unittest.mock-examples.rst:228 msgid "" "It is the call to ``.call_list()`` that turns our call object into a list of " "calls representing the chained calls." msgstr "" +"正是對 ``.call_list()`` 的呼叫將我們的呼叫物件轉換為代表鍊接呼叫的呼叫串列。" #: ../../library/unittest.mock-examples.rst:233 msgid "Raising exceptions with mocks" -msgstr "" +msgstr "透過 mock 引發例外" #: ../../library/unittest.mock-examples.rst:235 msgid "" @@ -242,10 +264,12 @@ msgid "" "exception class or instance then the exception will be raised when the mock " "is called." msgstr "" +"一個有用的屬性是 :attr:`~Mock.side_effect`。如果將其設定為例外類別或實例,則" +"當 mock 被呼叫時將引發例外。" #: ../../library/unittest.mock-examples.rst:247 msgid "Side effect functions and iterables" -msgstr "" +msgstr "Side effect 函式以及可疊代物件" #: ../../library/unittest.mock-examples.rst:249 msgid "" @@ -255,6 +279,10 @@ msgid "" "set ``side_effect`` to an iterable every call to the mock returns the next " "value from the iterable:" msgstr "" +"``side_effect`` 也可以設定為函式或可疊代物件。``side_effect`` 作為可疊代物件" +"的使用案例是:當你的 mock 將會被多次呼叫,且你希望每次呼叫回傳不同的值。當你" +"將``side_effect`` 設定為可疊代物件時,對 mock 的每次呼叫都會傳回可疊代物件中" +"的下一個值:" #: ../../library/unittest.mock-examples.rst:264 msgid "" @@ -263,10 +291,13 @@ msgid "" "function. The function will be called with the same arguments as the mock. " "Whatever the function returns is what the call returns:" msgstr "" +"對於更進階的使用案例,例如根據 mock 被呼叫的內容動態變更回傳值," +"``side_effect`` 可以是一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回" +"傳的內容就會是呼叫回傳的內容:" #: ../../library/unittest.mock-examples.rst:281 msgid "Mocking asynchronous iterators" -msgstr "" +msgstr "Mock 非同步可疊代物件" #: ../../library/unittest.mock-examples.rst:283 msgid "" @@ -275,10 +306,13 @@ msgid "" "attribute of ``__aiter__`` can be used to set the return values to be used " "for iteration." msgstr "" +"從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aiter__`` 來 " +"mock :ref:`async-iterators`。``__aiter__`` 的 :attr:`~Mock.return_value` 屬性" +"可用來設定用於疊代的回傳值。" #: ../../library/unittest.mock-examples.rst:298 msgid "Mocking asynchronous context manager" -msgstr "" +msgstr "Mock 非同步情境管理器" #: ../../library/unittest.mock-examples.rst:300 msgid "" @@ -287,10 +321,13 @@ msgid "" "default, ``__aenter__`` and ``__aexit__`` are ``AsyncMock`` instances that " "return an async function." msgstr "" +"從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aenter__`` " +"和 ``__aexit__`` 來 mock :ref:`async-context-managers`。預設情況下," +"``__aenter__`` 和 ``__aexit__`` 是回傳非同步函式的 ``AsyncMock`` 實例。" #: ../../library/unittest.mock-examples.rst:322 msgid "Creating a Mock from an Existing Object" -msgstr "" +msgstr "從現有物件建立 mock" #: ../../library/unittest.mock-examples.rst:324 msgid "" @@ -301,6 +338,11 @@ msgid "" "you refactor the first class, so that it no longer has ``some_method`` - " "then your tests will continue to pass even though your code is now broken!" msgstr "" +"過度使用 mock 的一個問題是,它將你的測試與 mock 的實現結合在一起,而不是與真" +"實的程式碼結合。假設你有一個實作 ``some_method`` 的類別,在另一個類別的測試" +"中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第" +"一個類別,使其不再具有 ``some_method`` - 那麼即使你的程式碼已經損壞,你的測試" +"也將繼續通過!" #: ../../library/unittest.mock-examples.rst:331 msgid "" @@ -311,6 +353,9 @@ msgid "" "specification, then tests that use that class will start failing immediately " "without you having to instantiate the class in those tests." msgstr "" +":class:`Mock` 允許你使用 *spec* 關鍵字引數提供一個物件作為 mock 的規格。 對 " +"mock 存取規格物件上不存在的方法或屬性將立即引發一個屬性錯誤。如果你更改規格的" +"實作,那麼使用該類別的測試將立即失敗,而無需在這些測試中實例化該類別。" #: ../../library/unittest.mock-examples.rst:344 msgid "" @@ -318,12 +363,16 @@ msgid "" "mock, regardless of whether some parameters were passed as positional or " "named arguments::" msgstr "" +"使用規格還可以更聰明地匹配對 mock 的呼叫,無論引數是作為位置引數還是命名引數" +"傳遞: ::" #: ../../library/unittest.mock-examples.rst:355 msgid "" "If you want this smarter matching to also work with method calls on the " "mock, you can use :ref:`auto-speccing `." msgstr "" +"如果你希望這種更聰明的匹配也可以應用於 mock 上的方法呼叫,你可以使用\\ :ref:`" +"自動規格 `。" #: ../../library/unittest.mock-examples.rst:358 msgid "" @@ -331,10 +380,12 @@ msgid "" "arbitrary attributes as well as the getting of them then you can use " "*spec_set* instead of *spec*." msgstr "" +"如果你想要一種更強大的規格形式來防止設定任意屬性以及取得它們,那麼你可以使用 " +"*spec_set* 而不是 *spec*。" #: ../../library/unittest.mock-examples.rst:364 msgid "Using side_effect to return per file content" -msgstr "" +msgstr "使用 side_effect 回傳每一個檔案內容" #: ../../library/unittest.mock-examples.rst:366 msgid "" @@ -342,10 +393,13 @@ msgid "" "side_effect` can be used to return a new Mock object per call. This can be " "used to return different contents per file stored in a dictionary::" msgstr "" +":func:`mock_open` 是用於 patch :func:`open` 方法。:attr:`~Mock.side_effect` " +"可以用來在每次呼叫回傳一個新的 mock 物件。 這可以用於回傳儲存在字典中的每個檔" +"案的不同內容: ::" #: ../../library/unittest.mock-examples.rst:389 msgid "Patch Decorators" -msgstr "" +msgstr "Patch 裝飾器" #: ../../library/unittest.mock-examples.rst:393 msgid "" @@ -353,6 +407,9 @@ msgid "" "they are looked up. This is normally straightforward, but for a quick guide " "read :ref:`where to patch `." msgstr "" +"使用 :func:`patch` 時,需注意的是你得在被查找物件的命名空間中(in the " +"namespace where they are looked up)patch 物件。這通常很直接,但若需要快速導" +"引,請參閱\\ :ref:`該 patch 何處 `\\ 。" #: ../../library/unittest.mock-examples.rst:398 msgid "" @@ -362,6 +419,10 @@ msgid "" "on them has to be undone after the test or the patch will persist into other " "tests and cause hard to diagnose problems." msgstr "" +"測試中的常見需求是 patch 類別屬性或模組屬性,例如 patch 一個內建函式(built-" +"in)或 patch 模組中的類別以測試它是否已實例化。模組和類別實際上是全域的,因此" +"在測試後必須撤銷它們的 patch,否則 patch 將延續到其他測試中並導致難以診斷問" +"題。" #: ../../library/unittest.mock-examples.rst:404 msgid "" @@ -373,25 +434,32 @@ msgid "" "the name of the attribute you would like patched, plus optionally the value " "to patch it with." msgstr "" +"mock 為此提供了三個方便的裝飾器::func:`patch`、:func:`patch.object` 和 :" +"func:`patch.dict`。``patch`` 採用單一字串,格式為 ``package.module.Class." +"attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" +"別或其他)的值。``patch.object`` 接受一個物件和你想要 patch 的屬性的名稱,同" +"時接受要 patch 的值。" #: ../../library/unittest.mock-examples.rst:412 msgid "``patch.object``::" -msgstr "" +msgstr "``patch.object``: ::" #: ../../library/unittest.mock-examples.rst:429 msgid "" "If you are patching a module (including :mod:`builtins`) then use :func:" "`patch` instead of :func:`patch.object`:" msgstr "" +"如果你要 patch 一個模組(包括 :mod:`builtins`),請使用 :func:`patch` 而非 :" +"func:`patch.object`:" #: ../../library/unittest.mock-examples.rst:439 msgid "" "The module name can be 'dotted', in the form ``package.module`` if needed::" -msgstr "" +msgstr "如有需要,模組名稱可以含有 ``.``,形式為 “package.module”: ::" #: ../../library/unittest.mock-examples.rst:448 msgid "A nice pattern is to actually decorate test methods themselves:" -msgstr "" +msgstr "一個好的模式是實際裝飾測試方法本身:" #: ../../library/unittest.mock-examples.rst:459 msgid "" @@ -399,10 +467,13 @@ msgid "" "argument (or :func:`patch.object` with two arguments). The mock will be " "created for you and passed into the test function / method:" msgstr "" +"如果你想使用一個 mock 進行 patch,你可以使用僅帶有一個引數的 :func:`patch`/ " +"(或帶有兩個引數的 :func:`patch.object`/ )。Mock 將被建立並被傳遞到測試函" +"式 / 方法中:" #: ../../library/unittest.mock-examples.rst:471 msgid "You can stack up multiple patch decorators using this pattern::" -msgstr "" +msgstr "你可以使用這個模式堆疊多個 patch 裝飾器: ::" #: ../../library/unittest.mock-examples.rst:482 msgid "" @@ -411,6 +482,9 @@ msgid "" "decorators are applied). This means from the bottom up, so in the example " "above the mock for ``test_module.ClassName2`` is passed in first." msgstr "" +"當你嵌套 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用的正" +"常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." +"ClassName2`` 的 mock 會先被傳入。" #: ../../library/unittest.mock-examples.rst:487 msgid "" @@ -418,18 +492,23 @@ msgid "" "during a scope and restoring the dictionary to its original state when the " "test ends:" msgstr "" +"也有 :func:`patch.dict`,用於在測試範圍中設定字典內的值,並在測試結束時將其恢" +"復為原始狀態:" #: ../../library/unittest.mock-examples.rst:498 msgid "" "``patch``, ``patch.object`` and ``patch.dict`` can all be used as context " "managers." msgstr "" +"``patch``、``patch.object`` 和 ``patch.dict`` 都可以用來作為情境管理器。" #: ../../library/unittest.mock-examples.rst:500 msgid "" "Where you use :func:`patch` to create a mock for you, you can get a " "reference to the mock using the \"as\" form of the with statement:" msgstr "" +"當你使用 :func:`patch` 為你建立一個 mock 時,你可以使用 with 陳述式的 \"as\" " +"形式來取得 mock 的參照:" #: ../../library/unittest.mock-examples.rst:515 msgid "" @@ -437,18 +516,20 @@ msgid "" "as class decorators. When used in this way it is the same as applying the " "decorator individually to every method whose name starts with \"test\"." msgstr "" +"另外,“patch”、“patch.object” 和 “patch.dict” 也可以用來作為類別裝飾器。以這" +"種方式使用時,與將裝飾器單獨應用於名稱以 “test” 開頭的每個方法相同。" #: ../../library/unittest.mock-examples.rst:523 msgid "Further Examples" -msgstr "" +msgstr "更多例子" #: ../../library/unittest.mock-examples.rst:526 msgid "Here are some more examples for some slightly more advanced scenarios." -msgstr "" +msgstr "以下是一些更進階一點的情境的範例。" #: ../../library/unittest.mock-examples.rst:530 msgid "Mocking chained calls" -msgstr "" +msgstr "Mock 鍊接呼叫" #: ../../library/unittest.mock-examples.rst:532 msgid "" @@ -457,12 +538,17 @@ msgid "" "for the first time, or you fetch its ``return_value`` before it has been " "called, a new :class:`Mock` is created." msgstr "" +"一旦你了解了 :attr:`~Mock.return_value` 屬性,mock 鏈接呼叫其實就很簡單了。當" +"一個 mock 第一次被呼叫,或者你在它被呼叫之前取得其 ``return_value`` 時,一個" +"新的 :class:`Mock` 就會被建立。" #: ../../library/unittest.mock-examples.rst:537 msgid "" "This means that you can see how the object returned from a call to a mocked " "object has been used by interrogating the ``return_value`` mock:" msgstr "" +"這代表你可以透過訊問 (interrogate) / ``return_value`` mock 來了解一個對被 " +"mock 的物件的呼叫回傳的物件是如何被使用的:" #: ../../library/unittest.mock-examples.rst:545 msgid "" @@ -470,10 +556,12 @@ msgid "" "chained calls. Of course another alternative is writing your code in a more " "testable way in the first place..." msgstr "" +"從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。 當然,另一種" +"選擇是先以更容易被測試的方式撰寫程式碼..." #: ../../library/unittest.mock-examples.rst:549 msgid "So, suppose we have some code that looks a little bit like this:" -msgstr "" +msgstr "所以,假設我們有一些程式碼,看起來大概像這樣:" #: ../../library/unittest.mock-examples.rst:558 msgid "" @@ -481,6 +569,9 @@ msgid "" "``method()``? Specifically, we want to test that the code section ``# more " "code`` uses the response object in the correct way." msgstr "" +"假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``? " +"具體來說,我們要測試程式碼部分 ``# more code`` 是否以正確的方式使用 " +"``response`` 物件。" #: ../../library/unittest.mock-examples.rst:562 msgid "" @@ -491,6 +582,11 @@ msgid "" "assume the object it returns is 'file-like', so we'll ensure that our " "response object uses the builtin :func:`open` as its ``spec``." msgstr "" +"由於此呼叫鍊是從實例屬性進行的,因此我們可以在 ``Something`` 實例上 monkey " +"patch ``backend`` 屬性。在這種特定的情況下,我們只對最終呼叫 ``start_call`` " +"的回傳值感興趣,因此我們不需要做太多配置。我們假設它傳回的物件是類檔案物件 " +"(file-like),因此我們會確保我們的 response 物件使用內建的 :func:`open` 作為" +"其 ``spec``。" #: ../../library/unittest.mock-examples.rst:569 msgid "" @@ -498,18 +594,25 @@ msgid "" "response object for it. To set the response as the return value for that " "final ``start_call`` we could do this::" msgstr "" +"為此,我們建立一個 mock 實例作為我們的 mock backend,並為其建立一個 mock " +"response 物件。要將 response 設定為最後的 ``start_call`` 的回傳值,我們可以這" +"樣做: ::" #: ../../library/unittest.mock-examples.rst:575 msgid "" "We can do that in a slightly nicer way using the :meth:`~Mock." "configure_mock` method to directly set the return value for us::" msgstr "" +"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為友善一點的方式為我們直" +"接設定回傳值: ::" #: ../../library/unittest.mock-examples.rst:584 msgid "" "With these we monkey patch the \"mock backend\" in place and can make the " "real call::" msgstr "" +"有了這些,我們就可以將 \"mock backend\" monkey patch 到位,並且可以進行真正的" +"呼叫: ::" #: ../../library/unittest.mock-examples.rst:590 msgid "" @@ -518,6 +621,9 @@ msgid "" "be several entries in ``mock_calls``. We can use :meth:`call.call_list` to " "create this list of calls for us::" msgstr "" +"藉由使用 :attr:`~Mock.mock_calls`,我們可以使用一個斷言來檢查鍊接呼叫。一個鍊" +"接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個條目。我們可以" +"使用 :meth:`call.call_list` 來為我們建立這個呼叫串列: ::" #: ../../library/unittest.mock-examples.rst:601 msgid "Partial mocking" From deff356ef4d36da3412f97211aa12f4012f3b659 Mon Sep 17 00:00:00 2001 From: Payon Date: Sat, 20 Jan 2024 23:26:25 +0800 Subject: [PATCH 2/8] fix: change nest/nested translation --- library/unittest.mock-examples.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index 79d8cdbdab..3f4ef4994e 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-09-09 00:03+0000\n" -"PO-Revision-Date: 2024-01-17 01:09+0800\n" +"PO-Revision-Date: 2024-01-20 23:25+0800\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -206,7 +206,7 @@ msgid "" "it is not possible to track nested calls where the parameters used to create " "ancestors are important:" msgstr "" -"然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的祖先的" +"然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的上代的" "參數的巢狀呼叫:" #: ../../library/unittest.mock-examples.rst:181 @@ -482,8 +482,8 @@ msgid "" "decorators are applied). This means from the bottom up, so in the example " "above the mock for ``test_module.ClassName2`` is passed in first." msgstr "" -"當你嵌套 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用的正" -"常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." +"當你巢狀使用 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用" +"的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." "ClassName2`` 的 mock 會先被傳入。" #: ../../library/unittest.mock-examples.rst:487 From 421a0fb403d33b50bbe843079723ad37bed8e3c2 Mon Sep 17 00:00:00 2001 From: Payon Date: Mon, 22 Jan 2024 21:50:49 +0800 Subject: [PATCH 3/8] fix: fix some rST --- library/unittest.mock-examples.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index 3f4ef4994e..05664b1b40 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-09-09 00:03+0000\n" -"PO-Revision-Date: 2024-01-20 23:25+0800\n" +"PO-Revision-Date: 2024-01-22 21:50+0800\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -467,8 +467,8 @@ msgid "" "argument (or :func:`patch.object` with two arguments). The mock will be " "created for you and passed into the test function / method:" msgstr "" -"如果你想使用一個 mock 進行 patch,你可以使用僅帶有一個引數的 :func:`patch`/ " -"(或帶有兩個引數的 :func:`patch.object`/ )。Mock 將被建立並被傳遞到測試函" +"如果你想使用一個 mock 進行 patch,你可以使用僅帶有一個引數的 :func:`patch`\\ " +"(或帶有兩個引數的 :func:`patch.object`\\ )。Mock 將被建立並被傳遞到測試函" "式 / 方法中:" #: ../../library/unittest.mock-examples.rst:471 @@ -547,7 +547,7 @@ msgid "" "This means that you can see how the object returned from a call to a mocked " "object has been used by interrogating the ``return_value`` mock:" msgstr "" -"這代表你可以透過訊問 (interrogate) / ``return_value`` mock 來了解一個對被 " +"這代表你可以透過訊問 (interrogate) \\ ``return_value`` mock 來了解一個對被 " "mock 的物件的呼叫回傳的物件是如何被使用的:" #: ../../library/unittest.mock-examples.rst:545 From 65003c6996d3df19a16d45b9dd4651bf1e9aa109 Mon Sep 17 00:00:00 2001 From: Payon Date: Tue, 23 Jan 2024 18:42:05 +0800 Subject: [PATCH 4/8] fix: for first review --- library/unittest.mock-examples.po | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index 05664b1b40..8e3096c01c 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-09-09 00:03+0000\n" -"PO-Revision-Date: 2024-01-22 21:50+0800\n" +"PO-Revision-Date: 2024-01-23 18:41+0800\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -140,9 +140,9 @@ msgid "" "Instances are created by *calling the class*. This means you access the " "\"mock instance\" by looking at the return value of the mocked class." msgstr "" -"一個常見的例子是 mock 被測試的程式碼實例化的類別。 當你 patch 一個類別時,該" -"類別就會被替換為 mock。 實例是透過*呼叫類別*建立的。 這代表你可以透過查看被 " -"mock 的類別的回傳值來存取「mock 實例」。" +"一個常見的使用案例是在測試的時候 mock 被程式碼實例化的類別。當你 patch 一個類" +"別時,該類別就會被替換為 mock。實例是透過\\ *呼叫類別*\\ 建立的。這代表你可以" +"透過查看被 mock 的類別的回傳值來存取「mock 實例」。" #: ../../library/unittest.mock-examples.rst:113 msgid "" @@ -153,8 +153,8 @@ msgid "" "return_value`. ::" msgstr "" "在下面的範例中,我們有一個函式 ``some_function``,它實例化 ``Foo`` 並呼叫它的" -"方法。 對 :func:`patch` 的呼叫將類別 ``Foo`` 替換為一個 mock。``Foo`` 實例是" -"呼叫 mock 的結果,因此它是透過修改 mock :attr:`~Mock.return_value` 來配置" +"方法。對 :func:`patch` 的呼叫將類別 ``Foo`` 替換為一個 mock。``Foo`` 實例是呼" +"叫 mock 的結果,因此它是透過修改 mock :attr:`~Mock.return_value` 來配置" "的。: ::" #: ../../library/unittest.mock-examples.rst:130 @@ -167,8 +167,8 @@ msgid "" "the mock and can be helpful when the mock appears in test failure messages. " "The name is also propagated to attributes or methods of the mock:" msgstr "" -"為你的 mock 命名可能會很有用。 這個名稱會顯示在 mock 的 repr 中,且當 mock 出" -"現在測試的失敗訊息中時,名稱會很有幫助。 該名稱也會傳播到 mock 的屬性或方法:" +"為你的 mock 命名可能會很有用。這個名稱會顯示在 mock 的 repr 中,且當 mock 出" +"現在測試的失敗訊息中時,名稱會很有幫助。該名稱也會傳播到 mock 的屬性或方法:" #: ../../library/unittest.mock-examples.rst:144 msgid "Tracking all Calls" @@ -190,7 +190,7 @@ msgid "" "well as asserting that the calls you expected have been made, you are also " "checking that they were made in the right order and with no additional calls:" msgstr "" -"如果你對 ``mock_calls`` 做出斷言並且有任何不預期的方法被呼叫,則斷言將失敗。 " +"如果你對 ``mock_calls`` 做出斷言並且有任何不預期的方法被呼叫,則斷言將失敗。" "這很有用,因為除了斷言你期望的呼叫已經進行之外,你還可以檢查它們是否按正確的" "順序進行,並且沒有多餘的呼叫:" @@ -206,8 +206,8 @@ msgid "" "it is not possible to track nested calls where the parameters used to create " "ancestors are important:" msgstr "" -"然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的上代的" -"參數的巢狀呼叫:" +"然而,回傳 mock 的呼叫的參數不會被記錄,這代表在巢狀呼叫中,無法追蹤用於建立" +"上代的參數 important 的值:" #: ../../library/unittest.mock-examples.rst:181 msgid "Setting Return Values and Attributes" @@ -236,8 +236,8 @@ msgid "" "to return a list, then we have to configure the result of the nested call." msgstr "" "有時你想要 mock 更複雜的情況,例如 ``mock.connection.cursor()." -"execute(\"SELECT 1\")``。 如果我們希望此呼叫回傳一個串列,那麼我們就必須配置" -"巢狀呼叫的結果。" +"execute(\"SELECT 1\")``。如果我們希望此呼叫回傳一個串列,那麼我們就必須配置巢" +"狀呼叫的結果。" #: ../../library/unittest.mock-examples.rst:214 msgid "" @@ -338,11 +338,11 @@ msgid "" "you refactor the first class, so that it no longer has ``some_method`` - " "then your tests will continue to pass even though your code is now broken!" msgstr "" -"過度使用 mock 的一個問題是,它將你的測試與 mock 的實現結合在一起,而不是與真" +"過度使用 mock 的一個問題是,它將你的測試與 mock 的實作結合在一起,而不是與真" "實的程式碼結合。假設你有一個實作 ``some_method`` 的類別,在另一個類別的測試" -"中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第" -"一個類別,使其不再具有 ``some_method`` - 那麼即使你的程式碼已經損壞,你的測試" -"也將繼續通過!" +"中,你提供了一個 mock 的物件,其\\ *也*\\ 提供了 ``some_method``。如果之後你" +"重構第一個類別,使其不再具有 ``some_method`` - 那麼即使你的程式碼已經損壞,你" +"的測試也將繼續通過!" #: ../../library/unittest.mock-examples.rst:331 msgid "" @@ -353,7 +353,7 @@ msgid "" "specification, then tests that use that class will start failing immediately " "without you having to instantiate the class in those tests." msgstr "" -":class:`Mock` 允許你使用 *spec* 關鍵字引數提供一個物件作為 mock 的規格。 對 " +":class:`Mock` 允許你使用 *spec* 關鍵字引數提供一個物件作為 mock 的規格。對 " "mock 存取規格物件上不存在的方法或屬性將立即引發一個屬性錯誤。如果你更改規格的" "實作,那麼使用該類別的測試將立即失敗,而無需在這些測試中實例化該類別。" @@ -385,7 +385,7 @@ msgstr "" #: ../../library/unittest.mock-examples.rst:364 msgid "Using side_effect to return per file content" -msgstr "使用 side_effect 回傳每一個檔案內容" +msgstr "使用 side_effect 回傳各別檔案內容" #: ../../library/unittest.mock-examples.rst:366 msgid "" @@ -394,7 +394,7 @@ msgid "" "used to return different contents per file stored in a dictionary::" msgstr "" ":func:`mock_open` 是用於 patch :func:`open` 方法。:attr:`~Mock.side_effect` " -"可以用來在每次呼叫回傳一個新的 mock 物件。 這可以用於回傳儲存在字典中的每個檔" +"可以用來在每次呼叫回傳一個新的 mock 物件。這可以用於回傳儲存在字典中的各別檔" "案的不同內容: ::" #: ../../library/unittest.mock-examples.rst:389 @@ -435,7 +435,7 @@ msgid "" "to patch it with." msgstr "" "mock 為此提供了三個方便的裝飾器::func:`patch`、:func:`patch.object` 和 :" -"func:`patch.dict`。``patch`` 採用單一字串,格式為 ``package.module.Class." +"func:`patch.dict`。``patch`` 接受單一字串,格式為 ``package.module.Class." "attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" "別或其他)的值。``patch.object`` 接受一個物件和你想要 patch 的屬性的名稱,同" "時接受要 patch 的值。" @@ -556,7 +556,7 @@ msgid "" "chained calls. Of course another alternative is writing your code in a more " "testable way in the first place..." msgstr "" -"從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。 當然,另一種" +"從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種" "選擇是先以更容易被測試的方式撰寫程式碼..." #: ../../library/unittest.mock-examples.rst:549 From 2004a7137464917417933ddbdbf746836ace4e05 Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 26 Jan 2024 19:11:12 +0800 Subject: [PATCH 5/8] fix: rebase --- library/unittest.mock-examples.po | 40 +++++++++++++++---------------- library/unittest.mock.po | 10 ++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index 8e3096c01c..ad63ab6e22 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-09-09 00:03+0000\n" -"PO-Revision-Date: 2024-01-23 18:41+0800\n" +"PO-Revision-Date: 2024-01-24 18:12+0800\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -455,7 +455,7 @@ msgstr "" #: ../../library/unittest.mock-examples.rst:439 msgid "" "The module name can be 'dotted', in the form ``package.module`` if needed::" -msgstr "如有需要,模組名稱可以含有 ``.``,形式為 “package.module”: ::" +msgstr "如有需要,模組名稱可以含有 ``.``,形式為 ``package.module``: ::" #: ../../library/unittest.mock-examples.rst:448 msgid "A nice pattern is to actually decorate test methods themselves:" @@ -482,9 +482,9 @@ msgid "" "decorators are applied). This means from the bottom up, so in the example " "above the mock for ``test_module.ClassName2`` is passed in first." msgstr "" -"當你巢狀使用 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用" -"的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." -"ClassName2`` 的 mock 會先被傳入。" +"當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相" +"同(一般 *Python* 應用裝飾器的順序)。這意味著由下而上,因此在上面的範例" +"中,\\ ``module.ClassName2`` 的 mock 會先被傳入。" #: ../../library/unittest.mock-examples.rst:487 msgid "" @@ -517,11 +517,11 @@ msgid "" "decorator individually to every method whose name starts with \"test\"." msgstr "" "另外,“patch”、“patch.object” 和 “patch.dict” 也可以用來作為類別裝飾器。以這" -"種方式使用時,與將裝飾器單獨應用於名稱以 “test” 開頭的每個方法相同。" +"種方式使用時,與將裝飾器單獨應用於每個名稱以 “test” 開頭的方法相同。" #: ../../library/unittest.mock-examples.rst:523 msgid "Further Examples" -msgstr "更多例子" +msgstr "更多範例" #: ../../library/unittest.mock-examples.rst:526 msgid "Here are some more examples for some slightly more advanced scenarios." @@ -538,7 +538,7 @@ msgid "" "for the first time, or you fetch its ``return_value`` before it has been " "called, a new :class:`Mock` is created." msgstr "" -"一旦你了解了 :attr:`~Mock.return_value` 屬性,mock 鏈接呼叫其實就很簡單了。當" +"一旦你了解了 :attr:`~Mock.return_value` 屬性,mock 鍊接呼叫其實就很簡單了。當" "一個 mock 第一次被呼叫,或者你在它被呼叫之前取得其 ``return_value`` 時,一個" "新的 :class:`Mock` 就會被建立。" @@ -547,8 +547,8 @@ msgid "" "This means that you can see how the object returned from a call to a mocked " "object has been used by interrogating the ``return_value`` mock:" msgstr "" -"這代表你可以透過訊問 (interrogate) \\ ``return_value`` mock 來了解一個對被 " -"mock 的物件的呼叫回傳的物件是如何被使用的:" +"這代表你可以透過查問 ``return_value`` mock 來了解一個對被 mock 的物件的呼叫回" +"傳的物件是如何被使用的:" #: ../../library/unittest.mock-examples.rst:545 msgid "" @@ -556,8 +556,8 @@ msgid "" "chained calls. Of course another alternative is writing your code in a more " "testable way in the first place..." msgstr "" -"從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種" -"選擇是先以更容易被測試的方式撰寫程式碼..." +"這裡只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種選擇是先" +"以更容易被測試的方式撰寫程式碼..." #: ../../library/unittest.mock-examples.rst:549 msgid "So, suppose we have some code that looks a little bit like this:" @@ -569,7 +569,7 @@ msgid "" "``method()``? Specifically, we want to test that the code section ``# more " "code`` uses the response object in the correct way." msgstr "" -"假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``? " +"假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``?" "具體來說,我們要測試程式碼部分 ``# more code`` 是否以正確的方式使用 " "``response`` 物件。" @@ -603,16 +603,16 @@ msgid "" "We can do that in a slightly nicer way using the :meth:`~Mock." "configure_mock` method to directly set the return value for us::" msgstr "" -"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為友善一點的方式為我們直" -"接設定回傳值: ::" +"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為好一點的方式為我們直接" +"設定回傳值: ::" #: ../../library/unittest.mock-examples.rst:584 msgid "" "With these we monkey patch the \"mock backend\" in place and can make the " "real call::" msgstr "" -"有了這些,我們就可以將 \"mock backend\" monkey patch 到位,並且可以進行真正的" -"呼叫: ::" +"有了這些,我們就可以原地 (in place) monkey patch \"mock backend\",並且可以進" +"行真正的呼叫: ::" #: ../../library/unittest.mock-examples.rst:590 msgid "" @@ -621,9 +621,9 @@ msgid "" "be several entries in ``mock_calls``. We can use :meth:`call.call_list` to " "create this list of calls for us::" msgstr "" -"藉由使用 :attr:`~Mock.mock_calls`,我們可以使用一個斷言來檢查鍊接呼叫。一個鍊" -"接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個條目。我們可以" -"使用 :meth:`call.call_list` 來為我們建立這個呼叫串列: ::" +"藉由使用 :attr:`~Mock.mock_calls`,我們可以使用單一一個斷言來檢查鍊接呼叫。一" +"個鍊接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個項目。我們" +"可以使用 :meth:`call.call_list` 來為我們建立這個呼叫串列: ::" #: ../../library/unittest.mock-examples.rst:601 msgid "Partial mocking" diff --git a/library/unittest.mock.po b/library/unittest.mock.po index 3c9b6ebe2c..132e1a924f 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-22 21:47+0800\n" +"PO-Revision-Date: 2024-01-24 18:03+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.1\n" +"X-Generator: Poedit 3.4.2\n" #: ../../library/unittest.mock.rst:3 msgid ":mod:`unittest.mock` --- mock object library" @@ -130,9 +130,9 @@ msgid "" "decorators are applied). This means from the bottom up, so in the example " "above the mock for ``module.ClassName1`` is passed in first." msgstr "" -"當你巢狀使用 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用" -"的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." -"ClassName1`` 的 mock 會先被傳入。" +"當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相" +"同(一般 *Python* 應用裝飾器的順序)。這意味著由下而上,因此在上面的範例" +"中,``module.ClassName1`` 的 mock 會先被傳入。" #: ../../library/unittest.mock.rst:122 msgid "" From 9ca2ee23a1037ac61122df7239a16159cea309f4 Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 26 Jan 2024 08:40:33 +0800 Subject: [PATCH 6/8] Update library/unittest.mock-examples.po Co-authored-by: mindihx --- library/unittest.mock-examples.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index ad63ab6e22..494375b323 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -281,7 +281,7 @@ msgid "" msgstr "" "``side_effect`` 也可以設定為函式或可疊代物件。``side_effect`` 作為可疊代物件" "的使用案例是:當你的 mock 將會被多次呼叫,且你希望每次呼叫回傳不同的值。當你" -"將``side_effect`` 設定為可疊代物件時,對 mock 的每次呼叫都會傳回可疊代物件中" +"將 ``side_effect`` 設定為可疊代物件時,對 mock 的每次呼叫都會傳回可疊代物件中" "的下一個值:" #: ../../library/unittest.mock-examples.rst:264 From e73dde7c984386f4803284066a167af2d0d6cfaf Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 26 Jan 2024 08:42:06 +0800 Subject: [PATCH 7/8] Update library/unittest.mock-examples.po Co-authored-by: mindihx --- library/unittest.mock-examples.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index 494375b323..a0d1c32fd6 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -292,7 +292,7 @@ msgid "" "Whatever the function returns is what the call returns:" msgstr "" "對於更進階的使用案例,例如根據 mock 被呼叫的內容動態變更回傳值," -"``side_effect`` 可以是一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回" +"可以將 ``side_effect`` 設成一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回" "傳的內容就會是呼叫回傳的內容:" #: ../../library/unittest.mock-examples.rst:281 From cbfaa015f66deee9fb5c3463fc67112129b243cb Mon Sep 17 00:00:00 2001 From: Payon Date: Fri, 26 Jan 2024 19:05:51 +0800 Subject: [PATCH 8/8] fix: for third review --- library/unittest.mock-examples.po | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/unittest.mock-examples.po b/library/unittest.mock-examples.po index a0d1c32fd6..97ae5cb421 100644 --- a/library/unittest.mock-examples.po +++ b/library/unittest.mock-examples.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-09-09 00:03+0000\n" -"PO-Revision-Date: 2024-01-24 18:12+0800\n" +"PO-Revision-Date: 2024-01-26 19:03+0800\n" "Last-Translator: Liang-Bo Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -291,9 +291,9 @@ msgid "" "function. The function will be called with the same arguments as the mock. " "Whatever the function returns is what the call returns:" msgstr "" -"對於更進階的使用案例,例如根據 mock 被呼叫的內容動態變更回傳值," -"可以將 ``side_effect`` 設成一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回" -"傳的內容就會是呼叫回傳的內容:" +"對於更進階的使用案例,例如根據 mock 被呼叫的內容動態變更回傳值,可以將 " +"``side_effect`` 設成一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回傳" +"的內容就會是呼叫回傳的內容:" #: ../../library/unittest.mock-examples.rst:281 msgid "Mocking asynchronous iterators" @@ -438,7 +438,7 @@ msgstr "" "func:`patch.dict`。``patch`` 接受單一字串,格式為 ``package.module.Class." "attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" "別或其他)的值。``patch.object`` 接受一個物件和你想要 patch 的屬性的名稱,同" -"時接受要 patch 的值。" +"時也可以接受要 patch 的值。" #: ../../library/unittest.mock-examples.rst:412 msgid "``patch.object``::" @@ -483,8 +483,8 @@ msgid "" "above the mock for ``test_module.ClassName2`` is passed in first." msgstr "" "當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相" -"同(一般 *Python* 應用裝飾器的順序)。這意味著由下而上,因此在上面的範例" -"中,\\ ``module.ClassName2`` 的 mock 會先被傳入。" +"同(一般 *Python* 應用裝飾器的順序)。這意味著由下而上,因此在上面的範例中," +"``module.ClassName2`` 的 mock 會先被傳入。" #: ../../library/unittest.mock-examples.rst:487 msgid "" @@ -603,7 +603,7 @@ msgid "" "We can do that in a slightly nicer way using the :meth:`~Mock." "configure_mock` method to directly set the return value for us::" msgstr "" -"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為好一點的方式為我們直接" +"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍微好一點的方式為我們直接" "設定回傳值: ::" #: ../../library/unittest.mock-examples.rst:584