@@ -3222,6 +3222,8 @@ msgid ""
3222
3222
"The mock of :meth:`~io.RawIOBase.read` changed to consume *read_data* rather"
3223
3223
" than returning it on each call."
3224
3224
msgstr ""
3225
+ "增加了对 :meth:`~io.IOBase.readline` 和 :meth:`~io.IOBase.readlines` 的支持。 对 "
3226
+ ":meth:`~io.RawIOBase.read` 的模拟被改为消耗 *read_data* 而不是每次调用时返回它。"
3225
3227
3226
3228
#: ../../library/unittest.mock.rst:2543
3227
3229
msgid "*read_data* is now reset on each call to the *mock*."
@@ -3572,6 +3574,10 @@ msgid ""
3572
3574
"... thing.a = 33\n"
3573
3575
"..."
3574
3576
msgstr ""
3577
+ ">>> with patch('__main__.Something', autospec=True):\n"
3578
+ "... thing = Something()\n"
3579
+ "... thing.a = 33\n"
3580
+ "..."
3575
3581
3576
3582
#: ../../library/unittest.mock.rst:2733
3577
3583
msgid ""
@@ -3646,6 +3652,17 @@ msgid ""
3646
3652
">>> mock.a\n"
3647
3653
"<NonCallableMagicMock name='Something.a' spec='int' id='...'>"
3648
3654
msgstr ""
3655
+ ">>> class Something:\n"
3656
+ "... def __init__(self):\n"
3657
+ "... self.a = 33\n"
3658
+ "...\n"
3659
+ ">>> class SomethingForTest(Something):\n"
3660
+ "... a = 33\n"
3661
+ "...\n"
3662
+ ">>> p = patch('__main__.Something', autospec=SomethingForTest)\n"
3663
+ ">>> mock = p.start()\n"
3664
+ ">>> mock.a\n"
3665
+ "<NonCallableMagicMock name='Something.a' spec='int' id='...'>"
3649
3666
3650
3667
#: ../../library/unittest.mock.rst:2793
3651
3668
msgid ""
@@ -3686,6 +3703,13 @@ msgid ""
3686
3703
">>> mock.submock.attribute2 # This will raise AttributeError.\n"
3687
3704
">>> mock.not_submock.attribute2 # This won't raise."
3688
3705
msgstr ""
3706
+ ">>> mock = Mock()\n"
3707
+ ">>> mock.submock.attribute1 = 2\n"
3708
+ ">>> mock.not_submock = mock.Mock(name=\" sample_name\" )\n"
3709
+ ">>> seal(mock)\n"
3710
+ ">>> mock.new_attribute # 这将引发 AttributeError。\n"
3711
+ ">>> mock.submock.attribute2 # 这将引发 AttributeError。\n"
3712
+ ">>> mock.not_submock.attribute2 # 这不会引发异常。"
3689
3713
3690
3714
#: ../../library/unittest.mock.rst:2826
3691
3715
msgid ""
0 commit comments