@@ -597,12 +597,17 @@ msgid ""
597597"When the mock date class is called a real date will be constructed and "
598598"returned by ``side_effect``. ::"
599599msgstr ""
600+ "这里使用 :func:`patch 装饰器 <patch>` 来模拟被测试模块中的 ``date`` 类。 模拟 date 类中的 "
601+ ":attr:`side_effect` 属性随后被设为一个返回真实日期的 lambda 函数。 当模拟 date 类被调用时将由 "
602+ "``side_effect`` 构造并返回一个真实日期。 ::"
600603
601604#: ../../library/unittest.mock-examples.rst:602
602605msgid ""
603606"Note that we don't patch :class:`datetime.date` globally, we patch ``date`` "
604607"in the module that *uses* it. See :ref:`where to patch <where-to-patch>`."
605608msgstr ""
609+ "请注意我们没有在全局范围上修补 :class:`datetime.date`,我们只是在 *使用* 它的模块中给 ``date`` 打补丁。 参见 "
610+ ":ref:`补丁的位置 <where-to-patch>`。"
606611
607612#: ../../library/unittest.mock-examples.rst:605
608613msgid ""
@@ -611,29 +616,34 @@ msgid ""
611616"find yourself having to calculate an expected result using exactly the same "
612617"algorithm as the code under test, which is a classic testing anti-pattern."
613618msgstr ""
619+ "当 ``date.today()`` 被调用时将返回一个已知的日期,但对 ``date(...)`` 构造器的调用仍会返回普通的日期。 "
620+ "如果不是这样你会发现你必须使用与被测试的代码完全相同的算法来计算出预期的结果,这是测试工作中的一个经典的反模式。"
614621
615622#: ../../library/unittest.mock-examples.rst:610
616623msgid ""
617624"Calls to the date constructor are recorded in the ``mock_date`` attributes "
618625"(``call_count`` and friends) which may also be useful for your tests."
619626msgstr ""
627+ "对 date 构造器的调用会被记录在 ``mock_date`` 属性中 (``call_count`` 等),它们也可能对你的测试有用处。"
620628
621629#: ../../library/unittest.mock-examples.rst:613
622630msgid ""
623631"An alternative way of dealing with mocking dates, or other builtin classes, "
624632"is discussed in `this blog entry <https://williambert.online/2011/07/how-to-"
625633"unit-testing-in-django-with-mocking-and-patching/>`_."
626634msgstr ""
635+ "有关处理模块日期或其他内置类的一种替代方式的讨论请参见 `这篇博客文章 <https://williambert.online/2011/07/how-"
636+ "to-unit-testing-in-django-with-mocking-and-patching/>`_。"
627637
628638#: ../../library/unittest.mock-examples.rst:619
629639msgid "Mocking a Generator Method"
630- msgstr ""
640+ msgstr "模拟生成器方法 "
631641
632642#: ../../library/unittest.mock-examples.rst:621
633643msgid ""
634644"A Python generator is a function or method that uses the :keyword:`yield` "
635645"statement to return a series of values when iterated over [#]_."
636- msgstr ""
646+ msgstr "Python 生成器是指在被迭代时使用 :keyword:`yield` 语句来返回一系列值的函数或方法 [#]_。 "
637647
638648#: ../../library/unittest.mock-examples.rst:624
639649msgid ""
@@ -642,15 +652,17 @@ msgid ""
642652"iteration is :meth:`~container.__iter__`, so we can mock this using a "
643653":class:`MagicMock`."
644654msgstr ""
655+ "调用生成器方法 / 函数将返回生成器对象。 生成器对象随后会被迭代。 迭代操作对应的协议方法是 "
656+ ":meth:`~container.__iter__`,因此我们可以使用 :class:`MagicMock` 来模拟它。"
645657
646658#: ../../library/unittest.mock-examples.rst:629
647659msgid ""
648660"Here's an example class with an \" iter\" method implemented as a generator:"
649- msgstr ""
661+ msgstr "以下是一个使用 \" iter \" 方法模拟为生成器的示例类: "
650662
651663#: ../../library/unittest.mock-examples.rst:641
652664msgid "How would we mock this class, and in particular its \" iter\" method?"
653- msgstr ""
665+ msgstr "我们要如何模拟这个类,特别是它的 \" iter \" 方法呢? "
654666
655667#: ../../library/unittest.mock-examples.rst:643
656668msgid ""
0 commit comments