Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9302b6

Browse files
committed
feat: to rst:358
1 parent6f3a72f commitb9302b6

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

‎library/unittest.mock-examples.po

Lines changed: 35 additions & 6 deletions
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-09-09 00:03+0000\n"
11-
"PO-Revision-Date:2024-01-1401:14+0800\n"
11+
"PO-Revision-Date:2024-01-1418:14+0800\n"
1212
"Last-Translator:Liang-Bo Wang <me@liang2.tw>\n"
1313
"Language-Team:Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -256,18 +256,20 @@ msgstr ""
256256

257257
#:../../library/unittest.mock-examples.rst:233
258258
msgid"Raising exceptions with mocks"
259-
msgstr""
259+
msgstr"透過 mock 引發例外"
260260

261261
#:../../library/unittest.mock-examples.rst:235
262262
msgid""
263263
"A useful attribute is :attr:`~Mock.side_effect`. If you set this to an "
264264
"exception class or instance then the exception will be raised when the mock "
265265
"is called."
266266
msgstr""
267+
"一個有用的屬性是 :attr:`~Mock.side_effect`。如果將其設定為例外類別或實例,則"
268+
"當 mock 被呼叫時將引發例外。"
267269

268270
#:../../library/unittest.mock-examples.rst:247
269271
msgid"Side effect functions and iterables"
270-
msgstr""
272+
msgstr"Side effect 函式以及可疊代物件"
271273

272274
#:../../library/unittest.mock-examples.rst:249
273275
msgid""
@@ -277,6 +279,10 @@ msgid ""
277279
"set ``side_effect`` to an iterable every call to the mock returns the next "
278280
"value from the iterable:"
279281
msgstr""
282+
"``side_effect`` 也可以設定為函式或可疊代物件。``side_effect`` 作為可疊代物件"
283+
"的使用案例是:當你的 mock 將會被多次呼叫,且你希望每次呼叫回傳不同的值。當你"
284+
"將``side_effect`` 設定為可疊代物件時,對 mock 的每次呼叫都會傳回可疊代物件中"
285+
"的下一個值:"
280286

281287
#:../../library/unittest.mock-examples.rst:264
282288
msgid""
@@ -285,10 +291,13 @@ msgid ""
285291
"function. The function will be called with the same arguments as the mock. "
286292
"Whatever the function returns is what the call returns:"
287293
msgstr""
294+
"對於更進階的使用案例,例如根據 mock 被呼叫的內容動態變更回傳值,"
295+
"``side_effect`` 可以是一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回"
296+
"傳的內容就會是呼叫回傳的內容:"
288297

289298
#:../../library/unittest.mock-examples.rst:281
290299
msgid"Mocking asynchronous iterators"
291-
msgstr""
300+
msgstr"Mock 非同步可疊代物件"
292301

293302
#:../../library/unittest.mock-examples.rst:283
294303
msgid""
@@ -297,10 +306,13 @@ msgid ""
297306
"attribute of ``__aiter__`` can be used to set the return values to be used "
298307
"for iteration."
299308
msgstr""
309+
"從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aiter__`` 來 "
310+
"mock :ref:`async-iterators`。``__aiter__`` 的 :attr:`~Mock.return_value` 屬性"
311+
"可用來設定用於疊代的回傳值。"
300312

301313
#:../../library/unittest.mock-examples.rst:298
302314
msgid"Mocking asynchronous context manager"
303-
msgstr""
315+
msgstr"Mock 非同步情境管理器"
304316

305317
#:../../library/unittest.mock-examples.rst:300
306318
msgid""
@@ -309,10 +321,13 @@ msgid ""
309321
"default, ``__aenter__`` and ``__aexit__`` are ``AsyncMock`` instances that "
310322
"return an async function."
311323
msgstr""
324+
"從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aenter__`` "
325+
"和 ``__aexit__`` 來 mock :ref:`async-context-managers`。預設情況下,"
326+
"``__aenter__`` 和 ``__aexit__`` 是回傳非同步函式的 ``AsyncMock`` 實例。"
312327

313328
#:../../library/unittest.mock-examples.rst:322
314329
msgid"Creating a Mock from an Existing Object"
315-
msgstr""
330+
msgstr"從現有物件建立 mock"
316331

317332
#:../../library/unittest.mock-examples.rst:324
318333
msgid""
@@ -323,6 +338,11 @@ msgid ""
323338
"you refactor the first class, so that it no longer has ``some_method`` - "
324339
"then your tests will continue to pass even though your code is now broken!"
325340
msgstr""
341+
"過度使用 mock 的一個問題是,它將你的測試與 mock 的實現結合在一起,而不是與真"
342+
"實的程式碼結合。假設你有一個實作 ``some_method`` 的類別,在另一個類別的測試"
343+
"中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第"
344+
"一個類別,使其不再具有 ``some_method`` - 那麼即使你的程式碼已經損壞,你的測試"
345+
"也將繼續通過!"
326346

327347
#:../../library/unittest.mock-examples.rst:331
328348
msgid""
@@ -333,26 +353,35 @@ msgid ""
333353
"specification, then tests that use that class will start failing immediately "
334354
"without you having to instantiate the class in those tests."
335355
msgstr""
356+
":class:`Mock` 允許你使用 *spec* 關鍵字引數提供一個物件作為 mock 的規格。 對 "
357+
"mock 存取規格物件上不存在的方法或屬性將立即引發一個屬性錯誤。如果你更改規格的"
358+
"實作,那麼使用該類別的測試將立即失敗,而無需在這些測試中實例化該類別。"
336359

337360
#:../../library/unittest.mock-examples.rst:344
338361
msgid""
339362
"Using a specification also enables a smarter matching of calls made to the "
340363
"mock, regardless of whether some parameters were passed as positional or "
341364
"named arguments::"
342365
msgstr""
366+
"使用規格還可以更聰明地匹配對 mock 的呼叫,無論引數是作為位置引數還是命名引數"
367+
"傳遞: ::"
343368

344369
#:../../library/unittest.mock-examples.rst:355
345370
msgid""
346371
"If you want this smarter matching to also work with method calls on the "
347372
"mock, you can use :ref:`auto-speccing <auto-speccing>`."
348373
msgstr""
374+
"如果你希望這種更聰明的匹配也可以應用於 mock 上的方法呼叫,你可以使用\\ :ref:`"
375+
"自動規格 <auto-speccing>`。"
349376

350377
#:../../library/unittest.mock-examples.rst:358
351378
msgid""
352379
"If you want a stronger form of specification that prevents the setting of "
353380
"arbitrary attributes as well as the getting of them then you can use "
354381
"*spec_set* instead of *spec*."
355382
msgstr""
383+
"如果你想要一種更強大的規格形式來防止設定任意屬性以及取得它們,那麼你可以使用 "
384+
"*spec_set* 而不是 *spec*。"
356385

357386
#:../../library/unittest.mock-examples.rst:364
358387
msgid"Using side_effect to return per file content"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp