Skip to content

Commit f06436f

Browse files
committed
feat: to rst:675
1 parent 53b5763 commit f06436f

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

library/unittest.mock-examples.po

Lines changed: 37 additions & 5 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-26 19:03+0800\n"
11+
"PO-Revision-Date: 2024-02-26 21:40+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"
@@ -627,7 +627,7 @@ msgstr ""
627627

628628
#: ../../library/unittest.mock-examples.rst:601
629629
msgid "Partial mocking"
630-
msgstr ""
630+
msgstr "部分 mocking"
631631

632632
#: ../../library/unittest.mock-examples.rst:603
633633
msgid ""
@@ -637,13 +637,19 @@ msgid ""
637637
"in C, and so I couldn't just monkey-patch out the static :meth:`datetime."
638638
"date.today` method."
639639
msgstr ""
640+
"在某些測試中,我們會想 mock 對 :meth:`datetime.date.today` 的呼叫以回傳一個已"
641+
"知日期,但我不想阻止測試中的程式碼建立新的日期物件。不幸的是 :class:"
642+
"`datetime.date` 是用 C 語言寫的,所以們我不能 monkey patch 靜態的 :meth:"
643+
"`datetime.date.today` 方法。"
640644

641645
#: ../../library/unittest.mock-examples.rst:608
642646
msgid ""
643647
"I found a simple way of doing this that involved effectively wrapping the "
644648
"date class with a mock, but passing through calls to the constructor to the "
645649
"real class (and returning real instances)."
646650
msgstr ""
651+
"我們找到了一種簡單的方法來做到這一點,其用 mock 有效地包裝日期類別,但將對建"
652+
"構函式的呼叫傳遞給真實的類別(並返回真實的實例)。"
647653

648654
#: ../../library/unittest.mock-examples.rst:612
649655
msgid ""
@@ -653,12 +659,18 @@ msgid ""
653659
"date. When the mock date class is called a real date will be constructed and "
654660
"returned by ``side_effect``. ::"
655661
msgstr ""
662+
"這裡使用 :func:`patch 裝飾器 <patch>` 來 mock 被測模組中的 ``date`` 類別。然"
663+
"後,mock 日期類別上的 :attr:`~Mock.side_effect` 屬性會被設定為回傳真實日期的 "
664+
"lambda 函式。當 mock 日期類別被呼叫時,將透過 ``side_effect`` 建構並回傳真實"
665+
"日期。: ::"
656666

657667
#: ../../library/unittest.mock-examples.rst:626
658668
msgid ""
659669
"Note that we don't patch :class:`datetime.date` globally, we patch ``date`` "
660670
"in the module that *uses* it. See :ref:`where to patch <where-to-patch>`."
661671
msgstr ""
672+
"注意,我們沒有全域 patch :class:`datetime.date`,而是在\\ *使用*\\ 它的模組"
673+
"中 patch ``date``。請參閱 :ref:`該 patch 何處 <where-to-patch>`。"
662674

663675
#: ../../library/unittest.mock-examples.rst:629
664676
msgid ""
@@ -667,29 +679,40 @@ msgid ""
667679
"find yourself having to calculate an expected result using exactly the same "
668680
"algorithm as the code under test, which is a classic testing anti-pattern."
669681
msgstr ""
682+
"當 ``date.today()`` 被呼叫時,一個已知日期會被回傳,但對 ``date(...)`` 建構函"
683+
"式的呼叫仍然會回傳正常日期。如果不這樣使用,你可能會發現自己必須使用與被測程"
684+
"式碼完全相同的演算法來計算預期結果,這是一個典型的測試的反面模式 (anti-"
685+
"pattern)。"
670686

671687
#: ../../library/unittest.mock-examples.rst:634
672688
msgid ""
673689
"Calls to the date constructor are recorded in the ``mock_date`` attributes "
674690
"(``call_count`` and friends) which may also be useful for your tests."
675691
msgstr ""
692+
"對日期建構函式的呼叫被記錄在 ``mock_date`` 屬性(\\ ``call_count`` 和它的朋友"
693+
"們)中,這對你的測試也可能有用處。"
676694

677695
#: ../../library/unittest.mock-examples.rst:637
678696
msgid ""
679697
"An alternative way of dealing with mocking dates, or other builtin classes, "
680698
"is discussed in `this blog entry <https://williambert.online/2011/07/how-to-"
681699
"unit-testing-in-django-with-mocking-and-patching/>`_."
682700
msgstr ""
701+
"處理 mock 日期或其他內建類別的另一種方法在 `這個 blog <https://williambert."
702+
"online/2011/07/how-to-unit-testing-in-django-with-mocking-and-patching/>`_ 中"
703+
"討論。"
683704

684705
#: ../../library/unittest.mock-examples.rst:643
685706
msgid "Mocking a Generator Method"
686-
msgstr ""
707+
msgstr "Mock 產生器方法"
687708

688709
#: ../../library/unittest.mock-examples.rst:645
689710
msgid ""
690711
"A Python generator is a function or method that uses the :keyword:`yield` "
691712
"statement to return a series of values when iterated over [#]_."
692713
msgstr ""
714+
"Python 產生器是一個函式或方法,它使用 :keyword:`yield` 陳述式在疊代 [#]_ 時回"
715+
"傳一系列的值。"
693716

694717
#: ../../library/unittest.mock-examples.rst:648
695718
msgid ""
@@ -698,22 +721,27 @@ msgid ""
698721
"iteration is :meth:`~container.__iter__`, so we can mock this using a :class:"
699722
"`MagicMock`."
700723
msgstr ""
724+
"產生器方法 / 函式會被呼叫以回傳產生器物件。之後此產生器會進行疊代。疊代的協定"
725+
"方法是 :meth:`~container.__iter__`,所以我們可以使用 :class:`MagicMock` 來 "
726+
"mock 它。"
701727

702728
#: ../../library/unittest.mock-examples.rst:653
703729
msgid ""
704730
"Here's an example class with an \"iter\" method implemented as a generator:"
705-
msgstr ""
731+
msgstr "下面是一個範例類別,其包含實作產生器的一個 \"iter\" 方法:"
706732

707733
#: ../../library/unittest.mock-examples.rst:665
708734
msgid "How would we mock this class, and in particular its \"iter\" method?"
709-
msgstr ""
735+
msgstr "我們該如何 mock 這個類別,特別是它的 \"iter\" 方法呢?"
710736

711737
#: ../../library/unittest.mock-examples.rst:667
712738
msgid ""
713739
"To configure the values returned from the iteration (implicit in the call "
714740
"to :class:`list`), we need to configure the object returned by the call to "
715741
"``foo.iter()``."
716742
msgstr ""
743+
"要配置從疊代回傳的值(隱含在對 :class:`list` 的呼叫中),我們需要配置呼叫 "
744+
"``foo.iter()`` 所回傳的物件。"
717745

718746
#: ../../library/unittest.mock-examples.rst:675
719747
msgid ""
@@ -723,6 +751,10 @@ msgid ""
723751
"they are is: `Generator Tricks for Systems Programmers <http://www.dabeaz."
724752
"com/generators/>`_."
725753
msgstr ""
754+
"還有關於產生器運算式及產生器的更多 `進階用法 <http://www.dabeaz.com/"
755+
"coroutines/index.html>`_ ,但我們在這裡不考慮它們。一個關於產生器及其強大功能"
756+
"的優良說明是:`Generator Tricks for Systems Programmers <http://www.dabeaz."
757+
"com/generators/>`_。"
726758

727759
#: ../../library/unittest.mock-examples.rst:683
728760
msgid "Applying the same patch to every test method"

0 commit comments

Comments
 (0)