Skip to content

Commit 8a0b2db

Browse files
committed
feat: to rst:590
1 parent a2cf7ca commit 8a0b2db

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

library/unittest.mock-examples.po

Lines changed: 44 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-14 23:14+0800\n"
11+
"PO-Revision-Date: 2024-01-17 01:09+0800\n"
1212
"Last-Translator: Liang-Bo Wang <[email protected]>\n"
1313
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -467,10 +467,13 @@ msgid ""
467467
"argument (or :func:`patch.object` with two arguments). The mock will be "
468468
"created for you and passed into the test function / method:"
469469
msgstr ""
470+
"如果你想使用一個 mock 進行 patch,你可以使用僅帶有一個引數的 :func:`patch`/ "
471+
"(或帶有兩個引數的 :func:`patch.object`/ )。Mock 將被建立並被傳遞到測試函"
472+
"式 / 方法中:"
470473

471474
#: ../../library/unittest.mock-examples.rst:471
472475
msgid "You can stack up multiple patch decorators using this pattern::"
473-
msgstr ""
476+
msgstr "你可以使用這個模式堆疊多個 patch 裝飾器: ::"
474477

475478
#: ../../library/unittest.mock-examples.rst:482
476479
msgid ""
@@ -479,44 +482,54 @@ msgid ""
479482
"decorators are applied). This means from the bottom up, so in the example "
480483
"above the mock for ``test_module.ClassName2`` is passed in first."
481484
msgstr ""
485+
"當你嵌套 patch 裝飾器時,mock 會以被應用的順序傳遞到裝飾函數(裝飾器應用的正"
486+
"常 *Python* 順序)。這意味著由下而上,因此在上面的範例中,\\ ``module."
487+
"ClassName2`` 的 mock 會先被傳入。"
482488

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

490498
#: ../../library/unittest.mock-examples.rst:498
491499
msgid ""
492500
"``patch``, ``patch.object`` and ``patch.dict`` can all be used as context "
493501
"managers."
494502
msgstr ""
503+
"``patch``、``patch.object`` 和 ``patch.dict`` 都可以用來作為情境管理器。"
495504

496505
#: ../../library/unittest.mock-examples.rst:500
497506
msgid ""
498507
"Where you use :func:`patch` to create a mock for you, you can get a "
499508
"reference to the mock using the \"as\" form of the with statement:"
500509
msgstr ""
510+
"當你使用 :func:`patch` 為你建立一個 mock 時,你可以使用 with 陳述式的 \"as\" "
511+
"形式來取得 mock 的參照:"
501512

502513
#: ../../library/unittest.mock-examples.rst:515
503514
msgid ""
504515
"As an alternative ``patch``, ``patch.object`` and ``patch.dict`` can be used "
505516
"as class decorators. When used in this way it is the same as applying the "
506517
"decorator individually to every method whose name starts with \"test\"."
507518
msgstr ""
519+
"另外,“patch”、“patch.object” 和 “patch.dict” 也可以用來作為類別裝飾器。以這"
520+
"種方式使用時,與將裝飾器單獨應用於名稱以 “test” 開頭的每個方法相同。"
508521

509522
#: ../../library/unittest.mock-examples.rst:523
510523
msgid "Further Examples"
511-
msgstr ""
524+
msgstr "更多例子"
512525

513526
#: ../../library/unittest.mock-examples.rst:526
514527
msgid "Here are some more examples for some slightly more advanced scenarios."
515-
msgstr ""
528+
msgstr "以下是一些更進階一點的情境的範例。"
516529

517530
#: ../../library/unittest.mock-examples.rst:530
518531
msgid "Mocking chained calls"
519-
msgstr ""
532+
msgstr "Mock 鍊接呼叫"
520533

521534
#: ../../library/unittest.mock-examples.rst:532
522535
msgid ""
@@ -525,30 +538,40 @@ msgid ""
525538
"for the first time, or you fetch its ``return_value`` before it has been "
526539
"called, a new :class:`Mock` is created."
527540
msgstr ""
541+
"一旦你了解了 :attr:`~Mock.return_value` 屬性,mock 鏈接呼叫其實就很簡單了。當"
542+
"一個 mock 第一次被呼叫,或者你在它被呼叫之前取得其 ``return_value`` 時,一個"
543+
"新的 :class:`Mock` 就會被建立。"
528544

529545
#: ../../library/unittest.mock-examples.rst:537
530546
msgid ""
531547
"This means that you can see how the object returned from a call to a mocked "
532548
"object has been used by interrogating the ``return_value`` mock:"
533549
msgstr ""
550+
"這代表你可以透過訊問 (interrogate) / ``return_value`` mock 來了解一個對被 "
551+
"mock 的物件的呼叫回傳的物件是如何被使用的:"
534552

535553
#: ../../library/unittest.mock-examples.rst:545
536554
msgid ""
537555
"From here it is a simple step to configure and then make assertions about "
538556
"chained calls. Of course another alternative is writing your code in a more "
539557
"testable way in the first place..."
540558
msgstr ""
559+
"從這裡開始,只需一個簡單的步驟即可進行配置並對鍊接呼叫進行斷言。 當然,另一種"
560+
"選擇是先以更容易被測試的方式撰寫程式碼..."
541561

542562
#: ../../library/unittest.mock-examples.rst:549
543563
msgid "So, suppose we have some code that looks a little bit like this:"
544-
msgstr ""
564+
msgstr "所以,假設我們有一些程式碼,看起來大概像這樣:"
545565

546566
#: ../../library/unittest.mock-examples.rst:558
547567
msgid ""
548568
"Assuming that ``BackendProvider`` is already well tested, how do we test "
549569
"``method()``? Specifically, we want to test that the code section ``# more "
550570
"code`` uses the response object in the correct way."
551571
msgstr ""
572+
"假設 ``BackendProvider`` 已經經過充分測試,那麼我們該如何測試 ``method()``? "
573+
"具體來說,我們要測試程式碼部分 ``# more code`` 是否以正確的方式使用 "
574+
"``response`` 物件。"
552575

553576
#: ../../library/unittest.mock-examples.rst:562
554577
msgid ""
@@ -559,25 +582,37 @@ msgid ""
559582
"assume the object it returns is 'file-like', so we'll ensure that our "
560583
"response object uses the builtin :func:`open` as its ``spec``."
561584
msgstr ""
585+
"由於此呼叫鍊是從實例屬性進行的,因此我們可以在 ``Something`` 實例上 monkey "
586+
"patch ``backend`` 屬性。在這種特定的情況下,我們只對最終呼叫 ``start_call`` "
587+
"的回傳值感興趣,因此我們不需要做太多配置。我們假設它傳回的物件是類檔案物件 "
588+
"(file-like),因此我們會確保我們的 response 物件使用內建的 :func:`open` 作為"
589+
"其 ``spec``。"
562590

563591
#: ../../library/unittest.mock-examples.rst:569
564592
msgid ""
565593
"To do this we create a mock instance as our mock backend and create a mock "
566594
"response object for it. To set the response as the return value for that "
567595
"final ``start_call`` we could do this::"
568596
msgstr ""
597+
"為此,我們建立一個 mock 實例作為我們的 mock backend,並為其建立一個 mock "
598+
"response 物件。要將 response 設定為最後的 ``start_call`` 的回傳值,我們可以這"
599+
"樣做: ::"
569600

570601
#: ../../library/unittest.mock-examples.rst:575
571602
msgid ""
572603
"We can do that in a slightly nicer way using the :meth:`~Mock."
573604
"configure_mock` method to directly set the return value for us::"
574605
msgstr ""
606+
"我們可以使用 :meth:`~Mock.configure_mock` 方法來以稍為友善一點的方式為我們直"
607+
"接設定回傳值: ::"
575608

576609
#: ../../library/unittest.mock-examples.rst:584
577610
msgid ""
578611
"With these we monkey patch the \"mock backend\" in place and can make the "
579612
"real call::"
580613
msgstr ""
614+
"有了這些,我們就可以將 \"mock backend\" monkey patch 到位,並且可以進行真正的"
615+
"呼叫: ::"
581616

582617
#: ../../library/unittest.mock-examples.rst:590
583618
msgid ""
@@ -586,6 +621,9 @@ msgid ""
586621
"be several entries in ``mock_calls``. We can use :meth:`call.call_list` to "
587622
"create this list of calls for us::"
588623
msgstr ""
624+
"藉由使用 :attr:`~Mock.mock_calls`,我們可以使用一個斷言來檢查鍊接呼叫。一個鍊"
625+
"接呼叫是一行程式碼中的多個呼叫,因此 ``mock_calls`` 中會有多個條目。我們可以"
626+
"使用 :meth:`call.call_list` 來為我們建立這個呼叫串列: ::"
589627

590628
#: ../../library/unittest.mock-examples.rst:601
591629
msgid "Partial mocking"

0 commit comments

Comments
 (0)