Skip to content
61 changes: 54 additions & 7 deletions library/unittest.mock.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: Python 3.12\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-22 00:04+0000\n"
"PO-Revision-Date: 2018-05-23 16:14+0000\n"
"PO-Revision-Date: 2023-08-22 15:44+0800\n"
"Last-Translator: Adrian Liaw <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
Expand All @@ -17,10 +17,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.3.2\n"

#: ../../library/unittest.mock.rst:3
msgid ":mod:`unittest.mock` --- mock object library"
msgstr ""
msgstr ":mod:`unittest.mock` — 模擬物件函式庫"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

針對 mock 翻譯成「模擬」覺得還是有點疑慮:我自己認為意思比較接近「仿造」,和 simulation 相近但不完全一樣。不過既然 patch 不翻譯的話,mock 我覺得也可以不翻譯。你覺得呢?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mock一方面是參照了樂詞網的 mock interviews (模擬面試)一詞,翻仿造又有跟 fake 搞混的可能性,好像也不太行。
mock整個不翻譯的話是一解,但我個人還是投模擬一票...,這邊看其他人有沒有想法吧。

Copy link
Collaborator

@mattwang44 mattwang44 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

認真探討 simulation 與 mock 的差異的話,兩者都是 (廣義的)模擬,但前者是追求更完整的模擬、後者只為特定目的而達成最低需求的模擬;我自己是覺得找不到中文詞彙可以呈現這種差異。
測試領域的 stub, fake, spy, mock, dummy 在口語溝通上也通常直接使用英文原文而沒有慣用翻譯,即便我們自己定義了一套對映翻譯,應也難以讓人理解這幾個詞彙間的差異。

Anyway, 如果想要徵得更多人意見的話,可以考慮在 channel 發文或者發一篇 discussion 做紀錄歐!

Copy link
Collaborator Author

@ken71301 ken71301 Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussion at #613


#: ../../library/unittest.mock.rst:13
msgid "**Source code:** :source:`Lib/unittest/mock.py`"
Expand All @@ -32,6 +33,8 @@ msgid ""
"replace parts of your system under test with mock objects and make "
"assertions about how they have been used."
msgstr ""
":mod:`unittest.mock`\\ 在 Python 中是一個用於進行測試的函式庫。 它允許你用模"
"擬物件 (mock object) 在測試中替換部分系統,並判定它們是如何被使用的。"

#: ../../library/unittest.mock.rst:21
msgid ""
Expand All @@ -41,6 +44,10 @@ msgid ""
"and arguments they were called with. You can also specify return values and "
"set needed attributes in the normal way."
msgstr ""
":mod:`unittest.mock`\\ 提供了一個以\\ :class:`Mock`\\ 為核心的類別,去除在測"
"試中建立大量 stubs 的需求。 在執行動作之後,你可以判定哪些 method (方法)/"
"屬性被使用,以及有哪些引數被呼叫。 你還可以用常規的方式指定回傳值與設定所需的"
"屬性。"

#: ../../library/unittest.mock.rst:27
msgid ""
Expand All @@ -50,23 +57,32 @@ msgid ""
"some examples of how to use :class:`Mock`, :class:`MagicMock` and :func:"
"`patch`."
msgstr ""
"此外,mock 還提供了一個\\ :func:`patch`\\ 裝飾器,用於 patching 測試範圍內對 "
"module(模組)以及 class(類別)級別的屬性,以及用於建立唯一對象的\\ :const:"
"`sentinel`\\ 。有關如何使用\\ :class:`Mock`\\、\\ :class:`MagicMock`\\ 和\\ :"
"func:`patch`\\ 的一些範例,請參閱\\ `快速導引 <quick guide_>`_。"

#: ../../library/unittest.mock.rst:33
msgid ""
"Mock is designed for use with :mod:`unittest` and is based on the 'action -> "
"assertion' pattern instead of 'record -> replay' used by many mocking "
"frameworks."
msgstr ""
"Mock 被設計用於與\\ :mod:`unittest`\\ 一起使用,並且基於 “action(操作) -> "
"assertion(判定)” 模式,而不是許多模擬框架使用的 ”record(記錄) -> replay"
"(重播)” 模式。"

#: ../../library/unittest.mock.rst:37
msgid ""
"There is a backport of :mod:`unittest.mock` for earlier versions of Python, "
"available as `mock on PyPI <https://pypi.org/project/mock>`_."
msgstr ""
"對於早期版本的 Python,有一個 backport(向後移植的)\\ :mod:`unittest."
"mock`\\ 可以使用,\\ `從 PyPI 下載 mock <https://pypi.org/project/mock>`_。"

#: ../../library/unittest.mock.rst:42
msgid "Quick Guide"
msgstr ""
msgstr "快速導引"

#: ../../library/unittest.mock.rst:60
msgid ""
Expand All @@ -75,12 +91,16 @@ msgid ""
"can configure them, to specify return values or limit what attributes are "
"available, and then make assertions about how they have been used:"
msgstr ""
":class:`Mock`\\ 和\\ :class:`MagicMock`\\ 物件在你存取它們時創建所有屬性和 "
"method(方法),並儲存它們如何被使用的詳細訊息。你可以配置它們,以指定回傳值"
"或限制可用的屬性,然後對它們的使用方式做出判定:"

#: ../../library/unittest.mock.rst:72
msgid ""
":attr:`side_effect` allows you to perform side effects, including raising an "
"exception when a mock is called:"
msgstr ""
":attr:`side_effect`\\ 允許你執行 side effects,包含在 mock 被呼叫時引發異常:"

#: ../../library/unittest.mock.rst:93
msgid ""
Expand All @@ -89,6 +109,9 @@ msgid ""
"from another object. Attempting to access attributes or methods on the mock "
"that don't exist on the spec will fail with an :exc:`AttributeError`."
msgstr ""
"Mock 有許多其他方法可以讓你配置與控制它的行為。例如,\\ *spec*\\ 引數可以配"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這裡的spec是斜體,照一般英文的處理方式就可以了嗎? 這邊翻譯當下有跟特殊語法搞混,輸出html後發現好像該+空格

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

的確把它當成英文字詞就好,改成 例如,*spec* 引數 即可。

"置 mock ,讓其從另一個物件獲取規格。嘗試讀取 mock 中不存在於 spec 中的屬性或"
"方法將會失敗,並出現\\ :exc:`AttributeError`\\ 。"

#: ../../library/unittest.mock.rst:98
msgid ""
Expand All @@ -97,6 +120,10 @@ msgid ""
"with a mock (or other object) during the test and restored when the test "
"ends::"
msgstr ""
":func:`patch`\\ 裝飾器 / 情境管理器可以在測試中簡單的模擬模組中的類別或物件。"
"被指定的物件在測試期間會被替換為 mock(或其他物件),並在測試結束時恢復:\n"
"\n"
"::"

#: ../../library/unittest.mock.rst:117
msgid ""
Expand All @@ -105,33 +132,43 @@ 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 會先被傳入。"

#: ../../library/unittest.mock.rst:122
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>`\\ 。"

#: ../../library/unittest.mock.rst:126
msgid ""
"As well as a decorator :func:`patch` can be used as a context manager in a "
"with statement:"
msgstr ""
msgstr "裝飾器\\ :func:`patch`\\ 也可以在 with 陳述式中被用來作為情境管理器:"

#: ../../library/unittest.mock.rst:136
msgid ""
"There is also :func:`patch.dict` for setting values in a dictionary just "
"during a scope and restoring the dictionary to its original state when the "
"test ends:"
msgstr ""
"也有\\ :func:`patch.dict`\\ ,用於在測試範圍中設定 dictionary(字典)內的值,"
"並在測試結束時將其恢復為原始狀態:"

#: ../../library/unittest.mock.rst:147
msgid ""
"Mock supports the mocking of Python :ref:`magic methods <magic-methods>`. "
"The easiest way of using magic methods is with the :class:`MagicMock` class. "
"It allows you to do things like:"
msgstr ""
"Mock 支持對 Python的\\ :ref:`魔術方法 <magic-methods>`\\ 的模擬。最簡單使用魔"
"術方法的方式是使用\\ :class:`MagicMock`\\ 類別。它允許你執行以下操作:"

#: ../../library/unittest.mock.rst:157
msgid ""
Expand All @@ -140,12 +177,15 @@ msgid ""
"is just a Mock variant that has all of the magic methods pre-created for you "
"(well, all the useful ones anyway)."
msgstr ""
"Mock 允許你將函式(或其他 Mock 實例)分配給魔術方法,並且它們將被適當地調"
"用。\\ :class:`MagicMock`\\ 類別是一個 Mock 的變體,它為你預先建好了所有魔術"
"方法(好吧,所有有用的方法)。"

#: ../../library/unittest.mock.rst:162
msgid ""
"The following is an example of using magic methods with the ordinary Mock "
"class:"
msgstr ""
msgstr "以下是在一般 Mock 類別中使用魔術方法的範例:"

#: ../../library/unittest.mock.rst:170
msgid ""
Expand All @@ -157,23 +197,30 @@ msgid ""
"replacing, and any functions and methods (including constructors) have the "
"same call signature as the real object."
msgstr ""
"為了確保測試中的模擬物件與它們要替換的物件具有相同的 api,你可以使用\\ :ref:`"
"自動規格 <auto-speccing>`\\ 。自動規格(auto-speccing)可以通過 patch 的\\ "
"*autospec*\\ 引數或\\ :func:`create_autospec`\\ 函式來完成。自動規格創建的模"
"擬物件與它們要替換的對象具有相同的屬性和方法,並且任何函式和方法(包括建構"
"子)都具有與真實物件相同的調用簽名(call signature)。"

#: ../../library/unittest.mock.rst:178
msgid ""
"This ensures that your mocks will fail in the same way as your production "
"code if they are used incorrectly:"
msgstr ""
msgstr "這可以確保如果使用方法錯誤,你的模擬會跟實際程式碼以相同的方式失敗:"

#: ../../library/unittest.mock.rst:194
msgid ""
":func:`create_autospec` can also be used on classes, where it copies the "
"signature of the ``__init__`` method, and on callable objects where it "
"copies the signature of the ``__call__`` method."
msgstr ""
":func:`create_autospec`\\ 也可以用在類別上,它複製了\\ ``__init__``\\ 方法的"
"簽名,它也可以用在可調用物件上,其複製了\\ ``__call__``\\ 方法的簽名。"

#: ../../library/unittest.mock.rst:201
msgid "The Mock Class"
msgstr ""
msgstr "模擬類別"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這裡是不是要翻成 Mock 類別,下面是在介紹 Mock 這個 class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能先決定要怎麼翻,到時候這邊翻成 Mock(mock的翻譯)類別 之類的吧?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我的意思是這裡 Mock 應該不用翻出來,因為下面都在說明 Mock() 相關的 methods、arguments


#: ../../library/unittest.mock.rst:212
msgid ""
Expand Down