@@ -8,7 +8,7 @@ msgstr ""
88"Project-Id-Version : Python 3.12\n "
99"Report-Msgid-Bugs-To : \n "
1010"POT-Creation-Date : 2023-07-22 00:04+0000\n "
11- "PO-Revision-Date : 2018-05-23 16:14+0000 \n "
11+ "PO-Revision-Date : 2023-08-29 15:33+0800 \n "
1212"Last-Translator : Adrian Liaw <adrianliaw2000@gmail.com>\n "
1313"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
1414"tw)\n "
@@ -17,10 +17,11 @@ msgstr ""
1717"Content-Type : text/plain; charset=UTF-8\n "
1818"Content-Transfer-Encoding : 8bit\n "
1919"Plural-Forms : nplurals=1; plural=0;\n "
20+ "X-Generator : Poedit 3.3.2\n "
2021
2122#: ../../library/unittest.mock.rst:3
2223msgid ":mod:`unittest.mock` --- mock object library"
23- msgstr ""
24+ msgstr ":mod:`unittest.mock` — mock 物件函式庫 "
2425
2526#: ../../library/unittest.mock.rst:13
2627msgid "**Source code:** :source:`Lib/unittest/mock.py`"
@@ -32,6 +33,8 @@ msgid ""
3233"replace parts of your system under test with mock objects and make "
3334"assertions about how they have been used."
3435msgstr ""
36+ ":mod:`unittest.mock` 在 Python 中是一個用於進行測試的函式庫。 它允許你用 "
37+ "mock 物件在測試中替換部分系統,並判定它們是如何被使用的。"
3538
3639#: ../../library/unittest.mock.rst:21
3740msgid ""
@@ -41,6 +44,9 @@ msgid ""
4144"and arguments they were called with. You can also specify return values and "
4245"set needed attributes in the normal way."
4346msgstr ""
47+ ":mod:`unittest.mock` 提供了一個以 :class:`Mock` 為核心的類別,去除在測試中建"
48+ "立大量 stubs 的需求。 在執行動作之後,你可以判定哪些 method (方法)/屬性被"
49+ "使用,以及有哪些引數被呼叫。 你還可以用常規的方式指定回傳值與設定所需的屬性。"
4450
4551#: ../../library/unittest.mock.rst:27
4652msgid ""
@@ -50,23 +56,32 @@ msgid ""
5056"some examples of how to use :class:`Mock`, :class:`MagicMock` and :func:"
5157"`patch`."
5258msgstr ""
59+ "此外,mock 還提供了一個 :func:`patch` 裝飾器,用於 patching 測試範圍內對 "
60+ "module(模組)以及 class(類別)級別的屬性,以及用於建立唯一物件的 :const:"
61+ "`sentinel`\\ 。有關如何使用 :class:`Mock`\\ 、\\ :class:`MagicMock` 和 :func:"
62+ "`patch` 的一些範例,請參閱\\ `快速導引 <quick guide_>`_。"
5363
5464#: ../../library/unittest.mock.rst:33
5565msgid ""
5666"Mock is designed for use with :mod:`unittest` and is based on the 'action -> "
5767"assertion' pattern instead of 'record -> replay' used by many mocking "
5868"frameworks."
5969msgstr ""
70+ "Mock 被設計用於與 :mod:`unittest` 一起使用,並且基於 「action(操作) -> "
71+ "assertion(判定)」 模式,而不是許多 mocking 框架使用的 「record(記錄) -> "
72+ "replay(重播)」 模式。"
6073
6174#: ../../library/unittest.mock.rst:37
6275msgid ""
6376"There is a backport of :mod:`unittest.mock` for earlier versions of Python, "
6477"available as `mock on PyPI <https://pypi.org/project/mock>`_."
6578msgstr ""
79+ "對於早期版本的 Python,有一個 backport(向後移植的)\\ :mod:`unittest.mock` "
80+ "可以使用,\\ `從 PyPI 下載 mock <https://pypi.org/project/mock>`_。"
6681
6782#: ../../library/unittest.mock.rst:42
6883msgid "Quick Guide"
69- msgstr ""
84+ msgstr "快速導引 "
7085
7186#: ../../library/unittest.mock.rst:60
7287msgid ""
@@ -75,12 +90,16 @@ msgid ""
7590"can configure them, to specify return values or limit what attributes are "
7691"available, and then make assertions about how they have been used:"
7792msgstr ""
93+ ":class:`Mock` 和 :class:`MagicMock` 物件在你存取它們時建立所有屬性和 method"
94+ "(方法),並儲存它們如何被使用的詳細訊息。你可以配置它們,以指定回傳值或限制"
95+ "可用的屬性,然後對它們的使用方式做出判定:"
7896
7997#: ../../library/unittest.mock.rst:72
8098msgid ""
8199":attr:`side_effect` allows you to perform side effects, including raising an "
82100"exception when a mock is called:"
83101msgstr ""
102+ ":attr:`side_effect` 允許你執行 side effects,包含在 mock 被呼叫時引發例外:"
84103
85104#: ../../library/unittest.mock.rst:93
86105msgid ""
@@ -89,6 +108,9 @@ msgid ""
89108"from another object. Attempting to access attributes or methods on the mock "
90109"that don't exist on the spec will fail with an :exc:`AttributeError`."
91110msgstr ""
111+ "Mock 有許多其他方法可以讓你配置與控制它的行為。例如,\\ *spec* 引數可以配置 "
112+ "mock ,讓其從另一個物件獲取規格。嘗試讀取 mock 中不存在於規格中的屬性或方法將"
113+ "會失敗,並出現 :exc:`AttributeError`\\ 。"
92114
93115#: ../../library/unittest.mock.rst:98
94116msgid ""
@@ -97,6 +119,10 @@ msgid ""
97119"with a mock (or other object) during the test and restored when the test "
98120"ends::"
99121msgstr ""
122+ ":func:`patch` 裝飾器/情境管理器可以在測試中簡單的 mock 模組中的類別或物件。"
123+ "被指定的物件在測試期間會被替換為 mock(或其他物件),並在測試結束時恢復:\n"
124+ "\n"
125+ "::"
100126
101127#: ../../library/unittest.mock.rst:117
102128msgid ""
@@ -105,33 +131,43 @@ msgid ""
105131"decorators are applied). This means from the bottom up, so in the example "
106132"above the mock for ``module.ClassName1`` is passed in first."
107133msgstr ""
134+ "當你嵌套 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用的正"
135+ "常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module."
136+ "ClassName1`` 的 mock 會先被傳入。"
108137
109138#: ../../library/unittest.mock.rst:122
110139msgid ""
111140"With :func:`patch` it matters that you patch objects in the namespace where "
112141"they are looked up. This is normally straightforward, but for a quick guide "
113142"read :ref:`where to patch <where-to-patch>`."
114143msgstr ""
144+ "使用 :func:`patch` 時,需注意的是你得在被查找物件的命名空間中(in the "
145+ "namespace where they are looked up)patch 物件。這通常很直接,但若需要快速導"
146+ "引,請參閱\\ :ref:`該 patch 何處 <where-to-patch>`\\ 。"
115147
116148#: ../../library/unittest.mock.rst:126
117149msgid ""
118150"As well as a decorator :func:`patch` can be used as a context manager in a "
119151"with statement:"
120- msgstr ""
152+ msgstr "裝飾器 :func:`patch` 也可以在 with 陳述式中被用來作為情境管理器: "
121153
122154#: ../../library/unittest.mock.rst:136
123155msgid ""
124156"There is also :func:`patch.dict` for setting values in a dictionary just "
125157"during a scope and restoring the dictionary to its original state when the "
126158"test ends:"
127159msgstr ""
160+ "也有 :func:`patch.dict`\\ ,用於在測試範圍中設定 dictionary(字典)內的值,並"
161+ "在測試結束時將其恢復為原始狀態:"
128162
129163#: ../../library/unittest.mock.rst:147
130164msgid ""
131165"Mock supports the mocking of Python :ref:`magic methods <magic-methods>`. "
132166"The easiest way of using magic methods is with the :class:`MagicMock` class. "
133167"It allows you to do things like:"
134168msgstr ""
169+ "Mock 支援對 Python 的\\ :ref:`魔術方法 <magic-methods>`\\ 的 mocking。最簡單"
170+ "使用魔術方法的方式是使用 :class:`MagicMock` 類別。它允許你執行以下操作:"
135171
136172#: ../../library/unittest.mock.rst:157
137173msgid ""
@@ -140,12 +176,15 @@ msgid ""
140176"is just a Mock variant that has all of the magic methods pre-created for you "
141177"(well, all the useful ones anyway)."
142178msgstr ""
179+ "Mock 允許你將函式(或其他 Mock 實例)分配給魔術方法,並且它們將被適當地呼"
180+ "叫。\\ :class:`MagicMock` 類別是一個 Mock 的變體,它為你預先建好了所有魔術方"
181+ "法(好吧,所有有用的方法)。"
143182
144183#: ../../library/unittest.mock.rst:162
145184msgid ""
146185"The following is an example of using magic methods with the ordinary Mock "
147186"class:"
148- msgstr ""
187+ msgstr "以下是在一般 Mock 類別中使用魔術方法的範例: "
149188
150189#: ../../library/unittest.mock.rst:170
151190msgid ""
@@ -157,23 +196,30 @@ msgid ""
157196"replacing, and any functions and methods (including constructors) have the "
158197"same call signature as the real object."
159198msgstr ""
199+ "為了確保測試中的 mock 物件與它們要替換的物件具有相同的 api,你可以使用\\ :"
200+ "ref:`自動規格 <auto-speccing>`\\ 。自動規格(auto-speccing)可以通過 patch "
201+ "的 *autospec* 引數或 :func:`create_autospec` 函式來完成。自動規格建立的 "
202+ "mock 物件與它們要替換的物件具有相同的屬性和方法,並且任何函式和方法(包括建構"
203+ "函式)都具有與真實物件相同的呼叫簽名(call signature)。"
160204
161205#: ../../library/unittest.mock.rst:178
162206msgid ""
163207"This ensures that your mocks will fail in the same way as your production "
164208"code if they are used incorrectly:"
165- msgstr ""
209+ msgstr "這可以確保如果使用方法錯誤,你的 mock 會跟實際程式碼以相同的方式失敗: "
166210
167211#: ../../library/unittest.mock.rst:194
168212msgid ""
169213":func:`create_autospec` can also be used on classes, where it copies the "
170214"signature of the ``__init__`` method, and on callable objects where it "
171215"copies the signature of the ``__call__`` method."
172216msgstr ""
217+ ":func:`create_autospec` 也可以用在類別上,它複製了 ``__init__`` 方法的簽名,"
218+ "它也可以用在可呼叫物件上,其複製了 ``__call__`` 方法的簽名。"
173219
174220#: ../../library/unittest.mock.rst:201
175221msgid "The Mock Class"
176- msgstr ""
222+ msgstr "Mock 類別 "
177223
178224#: ../../library/unittest.mock.rst:212
179225msgid ""
0 commit comments