@@ -530,26 +530,31 @@ msgid ""
530530"assume the object it returns is 'file-like', so we'll ensure that our "
531531"response object uses the builtin :func:`open` as its ``spec``."
532532msgstr ""
533+ "由于这个链式调用来自一个实例属性我们可以对 ``backend`` 属性在 ``Something`` 实例上进行猴子式修补。 "
534+ "在这个特定情况下我们只对最后调用 ``start_call`` 的返回值感兴趣所以我们不需要进行太多的配置。 "
535+ "让我们假定它返回的是“文件类”对象,因此我们将确保我们的响应对象使用内置的 :func:`open` 作为其 ``spec``。"
533536
534537#: ../../library/unittest.mock-examples.rst:545
535538msgid ""
536539"To do this we create a mock instance as our mock backend and create a mock "
537540"response object for it. To set the response as the return value for that "
538541"final ``start_call`` we could do this::"
539542msgstr ""
543+ "为了做到这一点我们创建一个 mock 实例作为我们的 mock 后端并为它创建一个 mock 响应对象。 要将该响应对象设为最后的 "
544+ "``start_call`` 的返回值我们可以这样做::"
540545
541546#: ../../library/unittest.mock-examples.rst:551
542547msgid ""
543548"We can do that in a slightly nicer way using the "
544549":meth:`~Mock.configure_mock` method to directly set the return value for "
545550"us::"
546- msgstr ""
551+ msgstr "我们可以通过更好一些的方式做到这一点,即使用 :meth:`~Mock.configure_mock` 方法直接为我们设置返回值:: "
547552
548553#: ../../library/unittest.mock-examples.rst:560
549554msgid ""
550555"With these we monkey patch the \" mock backend\" in place and can make the "
551556"real call::"
552- msgstr ""
557+ msgstr "有了这些我们就能准备好给“mock 后端”打上猴子补丁并可以执行真正的调用:: "
553558
554559#: ../../library/unittest.mock-examples.rst:566
555560msgid ""
@@ -558,10 +563,12 @@ msgid ""
558563"be several entries in ``mock_calls``. We can use :meth:`call.call_list` to "
559564"create this list of calls for us::"
560565msgstr ""
566+ "使用 :attr:`~Mock.mock_calls` 我们可以通过一个断言来检查链式调用。 一个链式调用就是在一行代码中连续执行多个调用,所以在 "
567+ "``mock_calls`` 中将会有多个条目。 我们可以使用 :meth:`call.call_list` 来为我们创建这个调用列表::"
561568
562569#: ../../library/unittest.mock-examples.rst:577
563570msgid "Partial mocking"
564- msgstr ""
571+ msgstr "部分模拟 "
565572
566573#: ../../library/unittest.mock-examples.rst:579
567574msgid ""
@@ -571,13 +578,16 @@ msgid ""
571578"in C, and so I couldn't just monkey-patch out the static :meth:`date.today` "
572579"method."
573580msgstr ""
581+ "在某些测试中我希望模拟对 :meth:`datetime.date.today` "
582+ "的调用以返回一个已知的日期,但我又不想阻止被测试的代码创建新的日期对象。 很不幸 :class:`datetime.date` 是用 C "
583+ "语言编写的,因此我不能简单地给静态的 :meth:`date.today` 方法打上猴子补丁。"
574584
575585#: ../../library/unittest.mock-examples.rst:584
576586msgid ""
577587"I found a simple way of doing this that involved effectively wrapping the "
578588"date class with a mock, but passing through calls to the constructor to the "
579589"real class (and returning real instances)."
580- msgstr ""
590+ msgstr "我找到了实现这一点的简单方式即通过一个 mock 来实际包装日期类,但通过对构造器的调用传递给真实的类(并返回真实的实例)。 "
581591
582592#: ../../library/unittest.mock-examples.rst:588
583593msgid ""
0 commit comments