@@ -518,6 +518,8 @@ msgid ""
518518"``method()``? Specifically, we want to test that the code section ``# more "
519519"code`` uses the response object in the correct way."
520520msgstr ""
521+ "假定 ``BackendProvider`` 已经过良好测试,我们要如何测试 ``method()``? 特别地,我们希望测试代码段 ``# more "
522+ "code`` 是否以正确的方式使用了响应对象。"
521523
522524#: ../../library/unittest.mock-examples.rst:538
523525msgid ""
@@ -528,26 +530,31 @@ msgid ""
528530"assume the object it returns is 'file-like', so we'll ensure that our "
529531"response object uses the builtin :func:`open` as its ``spec``."
530532msgstr ""
533+ "由于这个链式调用来自一个实例属性我们可以对 ``backend`` 属性在 ``Something`` 实例上进行猴子式修补。 "
534+ "在这个特定情况下我们只对最后调用 ``start_call`` 的返回值感兴趣所以我们不需要进行太多的配置。 "
535+ "让我们假定它返回的是“文件类”对象,因此我们将确保我们的响应对象使用内置的 :func:`open` 作为其 ``spec``。"
531536
532537#: ../../library/unittest.mock-examples.rst:545
533538msgid ""
534539"To do this we create a mock instance as our mock backend and create a mock "
535540"response object for it. To set the response as the return value for that "
536541"final ``start_call`` we could do this::"
537542msgstr ""
543+ "为了做到这一点我们创建一个 mock 实例作为我们的 mock 后端并为它创建一个 mock 响应对象。 要将该响应对象设为最后的 "
544+ "``start_call`` 的返回值我们可以这样做::"
538545
539546#: ../../library/unittest.mock-examples.rst:551
540547msgid ""
541548"We can do that in a slightly nicer way using the "
542549":meth:`~Mock.configure_mock` method to directly set the return value for "
543550"us::"
544- msgstr ""
551+ msgstr "我们可以通过更好一些的方式做到这一点,即使用 :meth:`~Mock.configure_mock` 方法直接为我们设置返回值:: "
545552
546553#: ../../library/unittest.mock-examples.rst:560
547554msgid ""
548555"With these we monkey patch the \" mock backend\" in place and can make the "
549556"real call::"
550- msgstr ""
557+ msgstr "有了这些我们就能准备好给“mock 后端”打上猴子补丁并可以执行真正的调用:: "
551558
552559#: ../../library/unittest.mock-examples.rst:566
553560msgid ""
@@ -556,10 +563,12 @@ msgid ""
556563"be several entries in ``mock_calls``. We can use :meth:`call.call_list` to "
557564"create this list of calls for us::"
558565msgstr ""
566+ "使用 :attr:`~Mock.mock_calls` 我们可以通过一个断言来检查链式调用。 一个链式调用就是在一行代码中连续执行多个调用,所以在 "
567+ "``mock_calls`` 中将会有多个条目。 我们可以使用 :meth:`call.call_list` 来为我们创建这个调用列表::"
559568
560569#: ../../library/unittest.mock-examples.rst:577
561570msgid "Partial mocking"
562- msgstr ""
571+ msgstr "部分模拟 "
563572
564573#: ../../library/unittest.mock-examples.rst:579
565574msgid ""
@@ -569,13 +578,16 @@ msgid ""
569578"in C, and so I couldn't just monkey-patch out the static :meth:`date.today` "
570579"method."
571580msgstr ""
581+ "在某些测试中我希望模拟对 :meth:`datetime.date.today` "
582+ "的调用以返回一个已知的日期,但我又不想阻止被测试的代码创建新的日期对象。 很不幸 :class:`datetime.date` 是用 C "
583+ "语言编写的,因此我不能简单地给静态的 :meth:`date.today` 方法打上猴子补丁。"
572584
573585#: ../../library/unittest.mock-examples.rst:584
574586msgid ""
575587"I found a simple way of doing this that involved effectively wrapping the "
576588"date class with a mock, but passing through calls to the constructor to the "
577589"real class (and returning real instances)."
578- msgstr ""
590+ msgstr "我找到了实现这一点的简单方式即通过一个 mock 来实际包装日期类,但通过对构造器的调用传递给真实的类(并返回真实的实例)。 "
579591
580592#: ../../library/unittest.mock-examples.rst:588
581593msgid ""
0 commit comments