-
-
Notifications
You must be signed in to change notification settings - Fork 214
Translate mock/example from rst:106 to rst:590 #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f231184
to
8a0b2db
Compare
8a0b2db
to
a7bb8e4
Compare
ready for review~ |
這週末剛好在忙,接下來兩三天應該會找時間 review~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看到 441 先存檔
library/unittest.mock-examples.po
Outdated
@@ -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 一個類別時,該" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- use case 要翻成使用案例嗎?
- 這段的句點後面都多了一個空白 (還有後面的一些翻譯都有多空白)
- 這邊我有點不太確定 by your code 的 code 是指"測試的 code",還是實際上"被測試的 code",我覺得比較像後者,目前的翻譯讀起來像前者
"一個常見的例子是 mock 被測試的程式碼實例化的類別。 當你 patch 一個類別時,該" | |
"一個常見的使用案例是在測試的時候 mock 被程式碼實例化的類別。當你 patch 一個類別時,該" |
library/unittest.mock-examples.po
Outdated
@@ -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。 實例是透過*呼叫類別*建立的。 這代表你可以透過查看被 " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這邊好像需要 escape
"類別就會被替換為 mock。 實例是透過*呼叫類別*建立的。 這代表你可以透過查看被 " | |
"類別就會被替換為 mock。實例是透過\\ *呼叫類別*\\ 建立的。 這代表你可以透過查看被 " |
|
||
#: ../../library/unittest.mock-examples.rst:146 | ||
msgid "" | ||
"Often you want to track more than a single call to a method. The :attr:" | ||
"`~Mock.mock_calls` attribute records all calls to child attributes of the " | ||
"mock - and also to their children." | ||
msgstr "" | ||
"通常你會想要追蹤對一個方法的多個呼叫。:attr:`~Mock.mock_calls` 屬性記錄對 " | ||
"mock 的子屬性以及其子屬性的所有呼叫。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
their children 的 their 是指 child attributes 嗎?不過子屬性的 children 是指什麼,是指它們的子屬性?
"mock 的子屬性以及其子屬性的所有呼叫。" | |
"mock 的子屬性以及其子屬性的子屬性(?)的所有呼叫。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes 這邊原文的範例是這樣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so children and their children
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
歐我這邊的 其 是對到 mock 的子屬性啦...
library/unittest.mock-examples.po
Outdated
|
||
#: ../../library/unittest.mock-examples.rst:170 | ||
msgid "" | ||
"However, parameters to calls that return mocks are not recorded, which means " | ||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這裡的 important 應該沒有要翻成重要的而是指下面程式裡的 important 參數?
"然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的上代的" | |
"然而,回傳 mock 的呼叫的參數不會被記錄,這代表在巢狀呼叫中,無法追蹤用於建立上代的參數 important 的值" |
library/unittest.mock-examples.po
Outdated
@@ -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``。如果之後你重構第" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第" | |
"中,你提供了一個 mock 的物件,其\\ *也*\\ 提供了 ``some_method``。如果之後你重構第" |
library/unittest.mock-examples.po
Outdated
|
||
#: ../../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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這裡的 per 感覺較偏向根據不同檔案回傳不同內容的意思而不是"每個"
msgstr "使用 side_effect 回傳每一個檔案內容" | |
msgstr "使用 side_effect 回傳各別檔案內容" |
library/unittest.mock-examples.po
Outdated
|
||
#: ../../library/unittest.mock-examples.rst:366 | ||
msgid "" | ||
":func:`mock_open` is used to patch :func:`open` method. :attr:`~Mock." | ||
"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 物件。 這可以用於回傳儲存在字典中的每個檔" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"可以用來在每次呼叫回傳一個新的 mock 物件。 這可以用於回傳儲存在字典中的每個檔" | |
"可以用來在每次呼叫回傳一個新的 mock 物件。 這可以用於回傳儲存在字典中的各別檔" |
|
||
#: ../../library/unittest.mock-examples.rst:393 | ||
msgid "" | ||
"With :func:`patch` it matters that you patch objects in the namespace where " | ||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"使用 :func:`patch` 時,需注意的是你得在被查找物件的命名空間中(in the " | |
"使用 :func:`patch` 時,重要的是你需要在查找該物件的命名空間中 patch 物件(in the " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這裏原文我是看成這樣所以有個被動式: they (objects) are looked up
library/unittest.mock-examples.po
Outdated
@@ -373,36 +434,46 @@ 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." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要統一翻成接受嗎
"func:`patch.dict`。``patch`` 採用單一字串,格式為 ``package.module.Class." | |
"func:`patch.dict`。``patch`` 接受單一字串,格式為 ``package.module.Class." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -373,36 +434,46 @@ 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 的屬性。同時它也可以接受你想要替換的屬性(或類" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
後面兩個 optionally 都不翻出來嗎~ (雖然翻出來有點怪XD)
"attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" | |
"attribute``,用來指定要 patch 的屬性。它也可選地接受你想要替換的屬性(或類" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因為翻出來真D怪
library/unittest.mock-examples.po
Outdated
|
||
#: ../../library/unittest.mock-examples.rst:439 | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msgstr "如有需要,模組名稱可以含有 ``.``,形式為 “package.module”: ::" | |
msgstr "如有需要,模組名稱可以含有 ``.``,形式為 ``package.module``: ::" |
|
||
#: ../../library/unittest.mock-examples.rst:459 | ||
msgid "" | ||
"If you want to patch with a Mock, you can use :func:`patch` with only one " | ||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不確定這邊的 mock 要不要維持大寫
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
應該不用,後面範例的 code 也沒有特別提及 Mock
|
||
#: ../../library/unittest.mock-examples.rst:459 | ||
msgid "" | ||
"If you want to patch with a Mock, you can use :func:`patch` with only one " | ||
"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 將被建立並被傳遞到測試函" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"(或帶有兩個引數的 :func:`patch.object`\\ )。Mock 將被建立並被傳遞到測試函" | |
"(或帶有兩個引數的 :func:`patch.object`)。Mock 將被建立並被傳遞到測試函" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這邊遇到括號rST會去世的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我在本地測試有活著
好像是左括號會去世但是右括號可以(?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我是覺得碰到括號就先用好惹...(怕死
library/unittest.mock-examples.po
Outdated
"當你巢狀使用 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用" | ||
"的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
括號可能括在講順序的後面會比較清楚?
"當你巢狀使用 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用" | |
"的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." | |
"當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相同(一般 *Python* 應用" | |
"裝飾器的順序)。這意味著由下而上,因此在上面的範例中,``module." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同步修改另一個檔案的譯文
library/unittest.mock-examples.po
Outdated
|
||
#: ../../library/unittest.mock-examples.rst:515 | ||
msgid "" | ||
"As an alternative ``patch``, ``patch.object`` and ``patch.dict`` can be used " | ||
"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” 開頭的每個方法相同。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"種方式使用時,與將裝飾器單獨應用於名稱以 “test” 開頭的每個方法相同。" | |
"種方式使用時,與將裝飾器單獨應用於每個名稱以 “test” 開頭的方法相同。" |
library/unittest.mock-examples.po
Outdated
|
||
#: ../../library/unittest.mock-examples.rst:558 | ||
msgid "" | ||
"Assuming that ``BackendProvider`` is already well tested, how do we 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``? " | |
"假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``?" |
library/unittest.mock-examples.po
Outdated
|
||
#: ../../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` 方法來以稍為友善一點的方式為我們直" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為友善一點的方式為我們直" | |
"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍微好一點的方式為我們直" |
library/unittest.mock-examples.po
Outdated
"藉由使用 :attr:`~Mock.mock_calls`,我們可以使用一個斷言來檢查鍊接呼叫。一個鍊" | ||
"接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個條目。我們可以" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不確定有沒有需要強調只要一個斷言
然後 entry 要翻成項目嗎,好像都差不多就是了~
"藉由使用 :attr:`~Mock.mock_calls`,我們可以使用一個斷言來檢查鍊接呼叫。一個鍊" | |
"接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個條目。我們可以" | |
"藉由使用 :attr:`~Mock.mock_calls`,我們可以使用單一一個斷言來檢查鍊接呼叫。一個鍊" | |
"接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個項目。我們可以" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
項目吧
library/unittest.mock-examples.po
Outdated
|
||
#: ../../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 到位,並且可以進行真正的" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這裡的 in place 比較像是原地修改的意思比較不像到位?
"有了這些,我們就可以將 \"mock backend\" monkey patch 到位,並且可以進行真正的" | |
"有了這些,我們就可以原地 (in place) monkey patch \"mock backend\",並且可以進行真正的" |
library/unittest.mock-examples.po
Outdated
|
||
#: ../../library/unittest.mock-examples.rst:545 | ||
msgid "" | ||
"From here it is a simple step to configure and then make assertions about " | ||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不確定這樣有沒有翻譯到它的意思...
"從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種" | |
"這裡只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。當然,另一種" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那個from here我是覺得可有可無(翻成中文的話)
|
||
#: ../../library/unittest.mock-examples.rst:393 | ||
msgid "" | ||
"With :func:`patch` it matters that you patch objects in the namespace where " | ||
"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 " | ||
"namespace where they are looked up)patch 物件。這通常很直接,但若需要快速導" | ||
"引,請參閱\\ :ref:`該 patch 何處 <where-to-patch>`\\ 。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"引,請參閱\\ :ref:`該 patch 何處 <where-to-patch>`\\ 。" | |
"引,請參閱\\ :ref:`該 patch 何處 <where-to-patch>`。" |
library/unittest.mock-examples.po
Outdated
"func:`patch.dict`。``patch`` 接受單一字串,格式為 ``package.module.Class." | ||
"attribute``,用來指定要 patch 的屬性。同時它也可以接受你想要替換的屬性(或類" | ||
"別或其他)的值。``patch.object`` 接受一個物件和你想要 patch 的屬性的名稱,同" | ||
"時接受要 patch 的值。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"時接受要 patch 的值。" | |
"時也可以接受要 patch 的值。" |
library/unittest.mock-examples.po
Outdated
@@ -411,44 +482,54 @@ 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 會先被傳入。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"中,\\ ``module.ClassName2`` 的 mock 會先被傳入。" | |
"中,``module.ClassName2`` 的 mock 會先被傳入。" |
library/unittest.mock-examples.po
Outdated
|
||
#: ../../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` 方法來以稍為好一點的方式為我們直接" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
還是 稍為
好像也說得通?
"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為好一點的方式為我們直接" | |
"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍微好一點的方式為我們直接" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
應該是稍微沒錯,又打錯字啦
"的正常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module." | ||
"ClassName1`` 的 mock 會先被傳入。" | ||
|
||
"當你巢狀使用 patch 裝飾器時,mock 傳遞到被裝飾函式的順序會跟其被應用的順序相" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
725 行還有一個 嵌套
要順便改一下嗎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那邊之前改過惹 rebase解決~
Co-authored-by: mindihx <[email protected]>
Co-authored-by: mindihx <[email protected]>
6ae5103
to
cbfaa01
Compare
#693