Skip to content

Commit 61d570a

Browse files
authored
Translate mock from rst:212 to rst:369 (#647)
* docs: mock 翻譯 translate from 212 to 248 * docs: mock 翻譯 translate from 254 to 369 * docs: mock 翻譯 remove comment * docs: mock 翻譯 修正用詞 * docs: mock 翻譯 根據review修正 * docs: mock 翻譯 根據review修正
1 parent 6a0b70f commit 61d570a

File tree

1 file changed

+63
-10
lines changed

1 file changed

+63
-10
lines changed

library/unittest.mock.po

+63-10
Original file line numberDiff line numberDiff line change
@@ -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: 2023-08-29 15:33+0800\n"
11+
"PO-Revision-Date: 2023-09-09 23:07+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"
@@ -198,9 +198,9 @@ msgid ""
198198
msgstr ""
199199
"為了確保測試中的 mock 物件與它們要替換的物件具有相同的 api,你可以使用\\ :"
200200
"ref:`自動規格 <auto-speccing>`\\ 。自動規格(auto-speccing)可以通過 patch "
201-
"的 *autospec* 引數或 :func:`create_autospec` 函式來完成。自動規格建立的 "
202-
"mock 物件與它們要替換的物件具有相同的屬性和方法,並且任何函式和方法(包括建構"
203-
"函式)都具有與真實物件相同的呼叫簽名(call signature)。"
201+
"的 *autospec* 引數或 :func:`create_autospec` 函式來完成。自動規格建立的 mock "
202+
"物件與它們要替換的物件具有相同的屬性和方法,並且任何函式和方法(包括建構函"
203+
")都具有與真實物件相同的呼叫簽名(call signature)。"
204204

205205
#: ../../library/unittest.mock.rst:178
206206
msgid ""
@@ -229,6 +229,10 @@ msgid ""
229229
"attribute will always return the same mock. Mocks record how you use them, "
230230
"allowing you to make assertions about what your code has done to them."
231231
msgstr ""
232+
":class:`Mock` 是一個彈性的的 mock 物件,旨在代替程式碼中 stubs 和 test "
233+
"doubles (測試替身)的使用。Mock 是可呼叫的,並在你存取它們時將屬性建立為新"
234+
"的 mock [#]_。存取相同的屬性將永遠回傳相同的 mock。Mock 記錄了你如何使用它"
235+
"們,允許你判定你的程式碼對 mock 的行為。"
232236

233237
#: ../../library/unittest.mock.rst:218
234238
msgid ""
@@ -237,6 +241,9 @@ msgid ""
237241
"when you are mocking out objects that aren't callable: :class:"
238242
"`NonCallableMock` and :class:`NonCallableMagicMock`"
239243
msgstr ""
244+
":class:`MagicMock` 是 :class:`Mock` 的子類別,其中所有魔術方法均已預先建立並"
245+
"可供使用。也有不可呼叫的變體,在你 mock 無法呼叫的物件時很有用::class:"
246+
"`NonCallableMock` 和 :class:`NonCallableMagicMock`"
240247

241248
#: ../../library/unittest.mock.rst:223
242249
msgid ""
@@ -245,12 +252,17 @@ msgid ""
245252
"will create a :class:`MagicMock` for you. You can specify an alternative "
246253
"class of :class:`Mock` using the *new_callable* argument to :func:`patch`."
247254
msgstr ""
255+
":func:`patch` 裝飾器可以輕鬆地用 :class:`Mock` 物件臨時替換特定模組中的類別。"
256+
"預設情況下,:func:`patch` 會為你建立一個 :class:`MagicMock`。你可以使"
257+
"用 :func:`patch` 的 *new_callable* 引數指定 :class:`Mock` 的替代類別。"
248258

249259
#: ../../library/unittest.mock.rst:231
250260
msgid ""
251261
"Create a new :class:`Mock` object. :class:`Mock` takes several optional "
252262
"arguments that specify the behaviour of the Mock object:"
253263
msgstr ""
264+
"建立一個新的 :class:`Mock` 物件。:class:`Mock` 接受數個可選的引數來指定 "
265+
"Mock 物件的行為:"
254266

255267
#: ../../library/unittest.mock.rst:234
256268
msgid ""
@@ -260,20 +272,30 @@ msgid ""
260272
"(excluding unsupported magic attributes and methods). Accessing any "
261273
"attribute not in this list will raise an :exc:`AttributeError`."
262274
msgstr ""
275+
"*spec*:這可以是字串的 list(串列),也可以是充當 mock 物件規格的現有物件(類"
276+
"別或實例)。如果傳入一個物件,則通過對該物件呼叫 dir 來形成字串的串列(不包括"
277+
"不支援的魔術屬性和方法)。存取不在此串列中的任何屬性都會引發 :exc:"
278+
"`AttributeError`\\ 。"
263279

264280
#: ../../library/unittest.mock.rst:240
265281
msgid ""
266282
"If *spec* is an object (rather than a list of strings) then :attr:`~instance."
267283
"__class__` returns the class of the spec object. This allows mocks to pass :"
268284
"func:`isinstance` tests."
269285
msgstr ""
286+
"如果 *spec* 是一個物件(而不是一個字串的串列),那麼 :attr:`~instance."
287+
"__class__` 會回傳 spec 物件的類別。這允許 mocks 通過 :func:`isinstance` 測"
288+
"試。"
270289

271290
#: ../../library/unittest.mock.rst:244
272291
msgid ""
273292
"*spec_set*: A stricter variant of *spec*. If used, attempting to *set* or "
274293
"get an attribute on the mock that isn't on the object passed as *spec_set* "
275294
"will raise an :exc:`AttributeError`."
276295
msgstr ""
296+
"*spec_set*:*spec* 的一個更嚴格的變體。如果使用 *spec_set*,在 mock 上嘗試 "
297+
"*set* 或取得不在傳遞給 *spec_set* 的物件上的屬性將會引發 :exc:"
298+
"`AttributeError`。"
277299

278300
#: ../../library/unittest.mock.rst:248
279301
msgid ""
@@ -283,29 +305,38 @@ msgid ""
283305
"arguments as the mock, and unless it returns :data:`DEFAULT`, the return "
284306
"value of this function is used as the return value."
285307
msgstr ""
308+
"*side_effect*:每當呼叫 Mock 時要呼叫的函式,參見 :attr:`~Mock.side_effect` "
309+
"屬性,用於引發例外或動態變更回傳值。該函式使用與 mock 相同的引數呼叫,且除非"
310+
"它回傳 :data:`DEFAULT`,否則此函式的回傳值將用作回傳值。"
286311

287312
#: ../../library/unittest.mock.rst:254
288313
msgid ""
289314
"Alternatively *side_effect* can be an exception class or instance. In this "
290315
"case the exception will be raised when the mock is called."
291316
msgstr ""
317+
"*side_effect* 也可以是一個例外的類別或實例。在這種情況下,當呼叫 mock 時,該"
318+
"例外將被引發。"
292319

293320
#: ../../library/unittest.mock.rst:257
294321
msgid ""
295322
"If *side_effect* is an iterable then each call to the mock will return the "
296323
"next value from the iterable."
297324
msgstr ""
325+
"如果 *side_effect* 是一個可疊代物件,那麼對 mock 的每次呼叫將回傳可疊代物件中"
326+
"的下一個值。"
298327

299328
#: ../../library/unittest.mock.rst:260
300329
msgid "A *side_effect* can be cleared by setting it to ``None``."
301-
msgstr ""
330+
msgstr "*side_effect* 可以通過將其設置為 ``None`` 來清除。"
302331

303332
#: ../../library/unittest.mock.rst:262
304333
msgid ""
305334
"*return_value*: The value returned when the mock is called. By default this "
306335
"is a new Mock (created on first access). See the :attr:`return_value` "
307336
"attribute."
308337
msgstr ""
338+
"*return_value*:當呼叫 mock 時回傳的值。預設情況下,這是一個新的 Mock(在首次"
339+
"存取時建立)。參見 :attr:`return_value` 屬性。"
309340

310341
#: ../../library/unittest.mock.rst:266
311342
msgid ""
@@ -314,6 +345,9 @@ msgid ""
314345
"`AttributeError`. Passing ``unsafe=True`` will allow access to these "
315346
"attributes."
316347
msgstr ""
348+
"*unsafe*:預設情況下,存取任何以 *assert*、*assret*、*asert*、*aseert* 或 "
349+
"*assrt* 開頭的屬性將引發 :exc:`AttributeError`。如果傳遞 ``unsafe=True``\\ ,"
350+
"將會允許存取這些屬性。"
317351

318352
#: ../../library/unittest.mock.rst:273
319353
msgid ""
@@ -324,49 +358,59 @@ msgid ""
324358
"to access an attribute that doesn't exist will raise an :exc:"
325359
"`AttributeError`)."
326360
msgstr ""
361+
"*wraps*:被 mock 物件包裝的項目。如果 *wraps* 不是 ``None``,那麼呼叫 Mock 將"
362+
"通過被包裝的物件(回傳真實結果)。存取 mock 的屬性將會回傳一個 Mock 物件,該"
363+
"物件包裝了被包裝物件的對應屬性(因此嘗試存取不存在的屬性將引發 :exc:"
364+
"`AttributeError`\\ )。"
327365

328366
#: ../../library/unittest.mock.rst:280
329367
msgid ""
330368
"If the mock has an explicit *return_value* set then calls are not passed to "
331369
"the wrapped object and the *return_value* is returned instead."
332370
msgstr ""
371+
"如果 mock 已經明確設定了 *return_value*,那麼呼叫並不會被傳遞到被包裝的物件,"
372+
"而是回傳已設定好的 *return_value*。"
333373

334374
#: ../../library/unittest.mock.rst:283
335375
msgid ""
336376
"*name*: If the mock has a name then it will be used in the repr of the mock. "
337377
"This can be useful for debugging. The name is propagated to child mocks."
338378
msgstr ""
379+
"*name*:如果 mock 有一個名稱,那麼它會被用於 mock 的 repr。這對於除錯很有用。"
380+
"此名稱將被傳播到子 mocks。"
339381

340382
#: ../../library/unittest.mock.rst:287
341383
msgid ""
342384
"Mocks can also be called with arbitrary keyword arguments. These will be "
343385
"used to set attributes on the mock after it is created. See the :meth:"
344386
"`configure_mock` method for details."
345387
msgstr ""
388+
"Mocks 還可以使用任意的關鍵字引數進行呼叫。這些關鍵字引數將在建立 mock 之後用"
389+
"於設定 mock 的屬性。欲知更多,請參見 :meth:`configure_mock` 方法。"
346390

347391
#: ../../library/unittest.mock.rst:293
348392
msgid "Assert that the mock was called at least once."
349-
msgstr ""
393+
msgstr "確認 mock 至少被呼叫一次。"
350394

351395
#: ../../library/unittest.mock.rst:304
352396
msgid "Assert that the mock was called exactly once."
353-
msgstr ""
397+
msgstr "確認 mock 只被呼叫一次。"
354398

355399
#: ../../library/unittest.mock.rst:322
356400
msgid ""
357401
"This method is a convenient way of asserting that the last call has been "
358402
"made in a particular way:"
359-
msgstr ""
403+
msgstr "這個方法是一個便利的方式,用來斷言最後一次呼叫是以特定方式進行的:"
360404

361405
#: ../../library/unittest.mock.rst:332
362406
msgid ""
363407
"Assert that the mock was called exactly once and that call was with the "
364408
"specified arguments."
365-
msgstr ""
409+
msgstr "確認 mock 只被呼叫一次,且該次呼叫使用了指定的引數。"
366410

367411
#: ../../library/unittest.mock.rst:347
368412
msgid "assert the mock has been called with the specified arguments."
369-
msgstr ""
413+
msgstr "斷言 mock 已經被使用指定的引數呼叫。"
370414

371415
#: ../../library/unittest.mock.rst:349
372416
msgid ""
@@ -375,24 +419,33 @@ msgid ""
375419
"the call is the most recent one, and in the case of :meth:"
376420
"`assert_called_once_with` it must also be the only call."
377421
msgstr ""
422+
"這個斷言在 mock 曾經被呼叫過時通過,不同於 :meth:`assert_called_with` 和 :"
423+
"meth:`assert_called_once_with`,他們針對的是最近的一次的呼叫,而且對於 :meth:"
424+
"`assert_called_once_with`,最近一次的呼叫還必須也是唯一一次的呼叫。"
378425

379426
#: ../../library/unittest.mock.rst:362
380427
msgid ""
381428
"assert the mock has been called with the specified calls. The :attr:"
382429
"`mock_calls` list is checked for the calls."
383430
msgstr ""
431+
"斷言 mock 已經使用指定的呼叫方式來呼叫。此斷言會檢查 :attr:`mock_calls` 串列中的"
432+
"呼叫。"
384433

385434
#: ../../library/unittest.mock.rst:365
386435
msgid ""
387436
"If *any_order* is false then the calls must be sequential. There can be "
388437
"extra calls before or after the specified calls."
389438
msgstr ""
439+
"如果 *any_order* 為 false,那麼這些呼叫必須按照順序。在指定的呼叫之前或之後可"
440+
"以有額外的呼叫。"
390441

391442
#: ../../library/unittest.mock.rst:369
392443
msgid ""
393444
"If *any_order* is true then the calls can be in any order, but they must all "
394445
"appear in :attr:`mock_calls`."
395446
msgstr ""
447+
"如果 *any_order* 為 true,那麼這些呼叫可以以任何順序出現,但它們必須全部出現"
448+
"在 :attr:`mock_calls` 中。"
396449

397450
#: ../../library/unittest.mock.rst:384
398451
msgid "Assert the mock was never called."

0 commit comments

Comments
 (0)