Translate mock/example from rst:106 to rst:590#799
Conversation
f231184 to
8a0b2db
Compare
8a0b2db to
a7bb8e4
Compare
|
ready for review~ |
|
這週末剛好在忙,接下來兩三天應該會找時間 review~ |
| "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 一個類別時,該" |
There was a problem hiding this comment.
- use case 要翻成使用案例嗎?
- 這段的句點後面都多了一個空白 (還有後面的一些翻譯都有多空白)
- 這邊我有點不太確定 by your code 的 code 是指"測試的 code",還是實際上"被測試的 code",我覺得比較像後者,目前的翻譯讀起來像前者
| "一個常見的例子是 mock 被測試的程式碼實例化的類別。 當你 patch 一個類別時,該" | |
| "一個常見的使用案例是在測試的時候 mock 被程式碼實例化的類別。當你 patch 一個類別時,該" |
| "\"mock instance\" by looking at the return value of the mocked class." | ||
| msgstr "" | ||
| "一個常見的例子是 mock 被測試的程式碼實例化的類別。 當你 patch 一個類別時,該" | ||
| "類別就會被替換為 mock。 實例是透過*呼叫類別*建立的。 這代表你可以透過查看被 " |
There was a problem hiding this comment.
這邊好像需要 escape
| "類別就會被替換為 mock。 實例是透過*呼叫類別*建立的。 這代表你可以透過查看被 " | |
| "類別就會被替換為 mock。實例是透過\\ *呼叫類別*\\ 建立的。 這代表你可以透過查看被 " |
| "mock - and also to their children." | ||
| msgstr "" | ||
| "通常你會想要追蹤對一個方法的多個呼叫。:attr:`~Mock.mock_calls` 屬性記錄對 " | ||
| "mock 的子屬性以及其子屬性的所有呼叫。" |
There was a problem hiding this comment.
their children 的 their 是指 child attributes 嗎?不過子屬性的 children 是指什麼,是指它們的子屬性?
| "mock 的子屬性以及其子屬性的所有呼叫。" | |
| "mock 的子屬性以及其子屬性的子屬性(?)的所有呼叫。" |
There was a problem hiding this comment.
so children and their children
There was a problem hiding this comment.
歐我這邊的 其 是對到 mock 的子屬性啦...
| "it is not possible to track nested calls where the parameters used to create " | ||
| "ancestors are important:" | ||
| msgstr "" | ||
| "然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的上代的" |
There was a problem hiding this comment.
這裡的 important 應該沒有要翻成重要的而是指下面程式裡的 important 參數?
| "然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的上代的" | |
| "然而,回傳 mock 的呼叫的參數不會被記錄,這代表在巢狀呼叫中,無法追蹤用於建立上代的參數 important 的值" |
| msgstr "" | ||
| "過度使用 mock 的一個問題是,它將你的測試與 mock 的實現結合在一起,而不是與真" | ||
| "實的程式碼結合。假設你有一個實作 ``some_method`` 的類別,在另一個類別的測試" | ||
| "中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第" |
There was a problem hiding this comment.
| "中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第" | |
| "中,你提供了一個 mock 的物件,其\\ *也*\\ 提供了 ``some_method``。如果之後你重構第" |
| #: ../../library/unittest.mock-examples.rst:364 | ||
| msgid "Using side_effect to return per file content" | ||
| msgstr "" | ||
| msgstr "使用 side_effect 回傳每一個檔案內容" |
There was a problem hiding this comment.
這裡的 per 感覺較偏向根據不同檔案回傳不同內容的意思而不是"每個"
| msgstr "使用 side_effect 回傳每一個檔案內容" | |
| msgstr "使用 side_effect 回傳各別檔案內容" |
| "used to return different contents per file stored in a dictionary::" | ||
| msgstr "" | ||
| ":func:`mock_open` 是用於 patch :func:`open` 方法。:attr:`~Mock.side_effect` " | ||
| "可以用來在每次呼叫回傳一個新的 mock 物件。 這可以用於回傳儲存在字典中的每個檔" |
There was a problem hiding this comment.
| "可以用來在每次呼叫回傳一個新的 mock 物件。 這可以用於回傳儲存在字典中的每個檔" | |
| "可以用來在每次呼叫回傳一個新的 mock 物件。 這可以用於回傳儲存在字典中的各別檔" |
| "they are looked up. This is normally straightforward, but for a quick guide " | ||
| "read :ref:`where to patch <where-to-patch>`." | ||
| msgstr "" | ||
| "使用 :func:`patch` 時,需注意的是你得在被查找物件的命名空間中(in the " |
There was a problem hiding this comment.
| "使用 :func:`patch` 時,需注意的是你得在被查找物件的命名空間中(in the " | |
| "使用 :func:`patch` 時,重要的是你需要在查找該物件的命名空間中 patch 物件(in the " |
There was a problem hiding this comment.
這裏原文我是看成這樣所以有個被動式: they (objects) are looked up
| "to patch it with." | ||
| msgstr "" | ||
| "mock 為此提供了三個方便的裝飾器::func:`patch`、:func:`patch.object` 和 :" | ||
| "func:`patch.dict`。``patch`` 採用單一字串,格式為 ``package.module.Class." |
There was a problem hiding this comment.
要統一翻成接受嗎
| "func:`patch.dict`。``patch`` 採用單一字串,格式為 ``package.module.Class." | |
| "func:`patch.dict`。``patch`` 接受單一字串,格式為 ``package.module.Class." |
| msgstr "" | ||
| "mock 為此提供了三個方便的裝飾器::func:`patch`、:func:`patch.object` 和 :" | ||
| "func:`patch.dict`。``patch`` 採用單一字串,格式為 ``package.module.Class." | ||
| "attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" |
There was a problem hiding this comment.
後面兩個 optionally 都不翻出來嗎~ (雖然翻出來有點怪XD)
| "attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" | |
| "attribute``,用來指定要 patch 的屬性。它也可選地接受你想要替換的屬性(或類" |
| msgid "" | ||
| "The module name can be 'dotted', in the form ``package.module`` if needed::" | ||
| msgstr "" | ||
| msgstr "如有需要,模組名稱可以含有 ``.``,形式為 “package.module”: ::" |
There was a problem hiding this comment.
| msgstr "如有需要,模組名稱可以含有 ``.``,形式為 “package.module”: ::" | |
| msgstr "如有需要,模組名稱可以含有 ``.``,形式為 ``package.module``: ::" |
| "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`\\ " |
There was a problem hiding this comment.
應該不用,後面範例的 code 也沒有特別提及 Mock
| "created for you and passed into the test function / method:" | ||
| msgstr "" | ||
| "如果你想使用一個 mock 進行 patch,你可以使用僅帶有一個引數的 :func:`patch`\\ " | ||
| "(或帶有兩個引數的 :func:`patch.object`\\ )。Mock 將被建立並被傳遞到測試函" |
There was a problem hiding this comment.
| "(或帶有兩個引數的 :func:`patch.object`\\ )。Mock 將被建立並被傳遞到測試函" | |
| "(或帶有兩個引數的 :func:`patch.object`)。Mock 將被建立並被傳遞到測試函" |
There was a problem hiding this comment.
我在本地測試有活著
好像是左括號會去世但是右括號可以(?)
There was a problem hiding this comment.
我是覺得碰到括號就先用好惹...(怕死
| "當你巢狀使用 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用" | ||
| "的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." |
There was a problem hiding this comment.
括號可能括在講順序的後面會比較清楚?
| "當你巢狀使用 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用" | |
| "的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." | |
| "當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相同(一般 *Python* 應用" | |
| "裝飾器的順序)。這意味著由下而上,因此在上面的範例中,``module." |
| "decorator individually to every method whose name starts with \"test\"." | ||
| msgstr "" | ||
| "另外,“patch”、“patch.object” 和 “patch.dict” 也可以用來作為類別裝飾器。以這" | ||
| "種方式使用時,與將裝飾器單獨應用於名稱以 “test” 開頭的每個方法相同。" |
There was a problem hiding this comment.
| "種方式使用時,與將裝飾器單獨應用於名稱以 “test” 開頭的每個方法相同。" | |
| "種方式使用時,與將裝飾器單獨應用於每個名稱以 “test” 開頭的方法相同。" |
| "``method()``? Specifically, we want to test that the code section ``# more " | ||
| "code`` uses the response object in the correct way." | ||
| msgstr "" | ||
| "假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``? " |
There was a problem hiding this comment.
| "假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``? " | |
| "假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``?" |
| "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` 方法來以稍為友善一點的方式為我們直" |
There was a problem hiding this comment.
| "我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為友善一點的方式為我們直" | |
| "我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍微好一點的方式為我們直" |
| "藉由使用 :attr:`~Mock.mock_calls`,我們可以使用一個斷言來檢查鍊接呼叫。一個鍊" | ||
| "接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個條目。我們可以" |
There was a problem hiding this comment.
不確定有沒有需要強調只要一個斷言
然後 entry 要翻成項目嗎,好像都差不多就是了~
| "藉由使用 :attr:`~Mock.mock_calls`,我們可以使用一個斷言來檢查鍊接呼叫。一個鍊" | |
| "接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個條目。我們可以" | |
| "藉由使用 :attr:`~Mock.mock_calls`,我們可以使用單一一個斷言來檢查鍊接呼叫。一個鍊" | |
| "接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個項目。我們可以" |
| "With these we monkey patch the \"mock backend\" in place and can make the " | ||
| "real call::" | ||
| msgstr "" | ||
| "有了這些,我們就可以將 \"mock backend\" monkey patch 到位,並且可以進行真正的" |
There was a problem hiding this comment.
這裡的 in place 比較像是原地修改的意思比較不像到位?
| "有了這些,我們就可以將 \"mock backend\" monkey patch 到位,並且可以進行真正的" | |
| "有了這些,我們就可以原地 (in place) monkey patch \"mock backend\",並且可以進行真正的" |
| "chained calls. Of course another alternative is writing your code in a more " | ||
| "testable way in the first place..." | ||
| msgstr "" | ||
| "從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種" |
There was a problem hiding this comment.
不確定這樣有沒有翻譯到它的意思...
| "從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種" | |
| "這裡只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種" |
There was a problem hiding this comment.
那個from here我是覺得可有可無(翻成中文的話)
| msgstr "" | ||
| "使用 :func:`patch` 時,需注意的是你得在被查找物件的命名空間中(in the " | ||
| "namespace where they are looked up)patch 物件。這通常很直接,但若需要快速導" | ||
| "引,請參閱\\ :ref:`該 patch 何處 <where-to-patch>`\\ 。" |
There was a problem hiding this comment.
| "引,請參閱\\ :ref:`該 patch 何處 <where-to-patch>`\\ 。" | |
| "引,請參閱\\ :ref:`該 patch 何處 <where-to-patch>`。" |
| "func:`patch.dict`。``patch`` 接受單一字串,格式為 ``package.module.Class." | ||
| "attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" | ||
| "別或其他)的值。``patch.object`` 接受一個物件和你想要 patch 的屬性的名稱,同" | ||
| "時接受要 patch 的值。" |
There was a problem hiding this comment.
| "時接受要 patch 的值。" | |
| "時也可以接受要 patch 的值。" |
| msgstr "" | ||
| "當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相" | ||
| "同(一般 *Python* 應用裝飾器的順序)。這意味著由下而上,因此在上面的範例" | ||
| "中,\\ ``module.ClassName2`` 的 mock 會先被傳入。" |
There was a problem hiding this comment.
| "中,\\ ``module.ClassName2`` 的 mock 會先被傳入。" | |
| "中,``module.ClassName2`` 的 mock 會先被傳入。" |
| "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` 方法來以稍為好一點的方式為我們直接" |
There was a problem hiding this comment.
還是 稍為 好像也說得通?
| "我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為好一點的方式為我們直接" | |
| "我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍微好一點的方式為我們直接" |
| "的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." | ||
| "ClassName1`` 的 mock 會先被傳入。" | ||
|
|
||
| "當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相" |
There was a problem hiding this comment.
那邊之前改過惹 rebase解決~
Co-authored-by: mindihx <ymhuang.ymh@gmail.com>
Co-authored-by: mindihx <ymhuang.ymh@gmail.com>
6ae5103 to
cbfaa01
Compare

#693