8000 [po] auto sync · python/python-docs-zh-cn@c25ace1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c25ace1

Browse files
[po] auto sync
1 parent 7c2549a commit c25ace1

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

.stat.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"translation": "80.40%", "updated_at": "2024-12-26T01:19:29Z"}
1+
{"translation": "80.42%", "updated_at": "2024-12-26T02:19:12Z"}

library/unittest.mock.po

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,10 @@ msgid ""
14931493
":mod:`unittest` finds tests. You can specify an alternative prefix by "
14941494
"setting ``patch.TEST_PREFIX``."
14951495
msgstr ""
1496+
"Patch 可以被用作 :class:`~unittest.TestCase` 类装饰器。 它是通过装饰类中的每个测试方法来发挥作用的。 "
1497+
"当你的测试方法共享同一个补丁集时这将减少模板代码。 :func:`patch` 会通过查找以 ``patch.TEST_PREFIX`` "
1498+
"打头的名称来找到测试。 其默认值为 ``'test'``,这与 :mod:`unittest` 找到测试的方式一致。 你可以通过设置 "
1499+
"``patch.TEST_PREFIX`` 来指定其他的前缀。"
14961500

14971501
#: ../../library/unittest.mock.rst:1465
14981502
msgid ""
@@ -1565,7 +1569,7 @@ msgstr ""
15651569
msgid ""
15661570
"To configure return values on methods of *instances* on the patched class "
15671571
"you must do this on the :attr:`~Mock.return_value`. For example::"
1568-
msgstr ""
1572+
msgstr "要在被打补丁的类的 *实例* 的方法上配置返回值你必须在 :attr:`~Mock.return_value` 进行操作。 例如::"
15691573

15701574
#: ../../library/unittest.mock.rst:1498
15711575
msgid ""
@@ -2082,6 +2086,8 @@ msgid ""
20822086
"it simpler to do patching in ``setUp`` methods or where you want to do "
20832087
"multiple patches without nesting decorators or with statements."
20842088
msgstr ""
2089+
"所有 patcher 对象都具有 :meth:`!start` 和 :meth:`!stop` 方法。 使用这些方法可以更简单地在 ``setUp`` "
2090+
"方法上打补丁,还可以让你不必嵌套使用装饰器或 with 语句就能打多重补丁。"
20852091

20862092
#: ../../library/unittest.mock.rst:1821
20872093
msgid ""
@@ -2090,6 +2096,9 @@ msgid ""
20902096
"then call :meth:`!start` to put the patch in place and :meth:`!stop` to undo"
20912097
" it."
20922098
msgstr ""
2099+
"要使用这些方法请按正常方式调用 :func:`patch`, :func:`patch.object` 或 :func:`patch.dict` "
2100+
"并保留一个指向所返回 ``patcher`` 对象的引用。 你可以随后调用 :meth:`!start` 来原地打补丁并调用 :meth:`!stop`"
2101+
" 来恢复它。"
20932102

20942103
#: ../../library/unittest.mock.rst:1825
20952104
msgid ""
@@ -2123,7 +2132,7 @@ msgstr ""
21232132
msgid ""
21242133
"A typical use case for this might be for doing multiple patches in the "
21252134
"``setUp`` method of a :class:`~unittest.TestCase`::"
2126-
msgstr ""
2135+
msgstr "此操作的一个典型应用场景是在一个 :class:`~unittest.TestCase` 的 ``setUp`` 方法中执行多重补丁::"
21272136

21282137
#: ../../library/unittest.mock.rst:1842
21292138
msgid ""
@@ -3166,6 +3175,8 @@ msgid ""
31663175
"``dir(type(my_mock))`` (type members) to bypass the filtering irrespective "
31673176
"of :const:`FILTER_DIR`."
31683177
msgstr ""
3178+
"或者你也可以直接使用 ``vars(my_mock)`` (实例成员) 和 ``dir(type(my_mock))`` (类型成员) 来绕过不考虑 "
3179+
":const:`FILTER_DIR` 的过滤。"
31693180

31703181
#: ../../library/unittest.mock.rst:2517
31713182
msgid "mock_open"
@@ -3199,6 +3210,11 @@ msgid ""
31993210
"that is insufficient, one of the in-memory filesystem packages on `PyPI "
32003211
"<https://pypi.org>`_ can offer a realistic filesystem for testing."
32013212
msgstr ""
3213+
"*read_data* 是供文件句柄的 :meth:`~io.RawIOBase.read`, :meth:`~io.IOBase.readline` "
3214+
"和 :meth:`~io.IOBase.readlines` 方法返回的字符串。 调用这些方法将会从 *read_data* 获取数据直到它被耗尽。 "
3215+
"对这些方法的模拟是相当简化的:每次 *mock* 被调用时,*read_data* 都将从头开始。 "
3216+
"如果你需要对你提供给测试代码的数据有更多控制那么你将需要自行定制这个 mock。 如果这还不够用,那么通过一些 `PyPI "
3217+
"<https://pypi.org>`_ 上的内存文件系统包可以提供更真实的测试用文件系统。"
32023218

32033219
#: ../../library/unittest.mock.rst:2538
32043220
msgid ""
@@ -3423,6 +3439,10 @@ msgid ""
34233439
" ...\n"
34243440
"TypeError: <lambda>() takes at least 2 arguments (1 given)"
34253441
msgstr ""
3442+
">>> req = request.Request()\n"
3443+
"Traceback (most recent call last):\n"
3444+
" ...\n"
3445+
"TypeError: <lambda>() takes at least 2 arguments (1 given)"
34263446

34273447
#: ../../library/unittest.mock.rst:2665
34283448
msgid ""
@@ -3436,6 +3456,9 @@ msgid ""
34363456
">>> req\n"
34373457
"<NonCallableMagicMock name='request.Request()' spec='Request' id='...'>"
34383458
msgstr ""
3459+
">>> req = request.Request('foo')\n"
3460+
">>> req\n"
3461+
"<NonCallableMagicMock name='request.Request()' spec='Request' id='...'>"
34393462

34403463
#: ../../library/unittest.mock.rst:2672
34413464
msgid ""
@@ -3455,6 +3478,13 @@ msgid ""
34553478
"AttributeError: Mock object has no attribute 'assret_called_with'\n"
34563479
">>> req.add_header.assert_called_with('spam', 'eggs')"
34573480
msgstr ""
3481+
">>> req.add_header('spam', 'eggs')\n"
3482+
"<MagicMock name='request.Request().add_header()' id='...'>\n"
3483+
">>> req.add_header.assret_called_with # 故意的拼写错误!\n"
3484+
"Traceback (most recent call last):\n"
3485+
" ...\n"
3486+
"AttributeError: Mock object has no attribute 'assret_called_with'\n"
3487+
">>> req.add_header.assert_called_with('spam', 'eggs')"
34583488

34593489
#: ../../library/unittest.mock.rst:2684
34603490
msgid ""
@@ -3512,6 +3542,17 @@ msgid ""
35123542
" ...\n"
35133543
"AttributeError: Mock object has no attribute 'a'"
35143544
msgstr ""
3545+
">>> class Something:\n"
3546+
"... def __init__(self):\n"
3547+
"... self.a = 33\n"
3548+
"...\n"
3549+
">>> with patch('__main__.Something', autospec=True):\n"
3550+
"... thing = Something()\n"
3551+
"... thing.a\n"
3552+
"...\n"
3553+
"Traceback (most recent call last):\n"
3554+
" ...\n"
3555+
"AttributeError: Mock object has no attribute 'a'"
35153556

35163557
#: ../../library/unittest.mock.rst:2722
35173558
msgid ""

0 commit comments

Comments
 (0)
0