-
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathdoctest.po
More file actions
2390 lines (2085 loc) · 122 KB
/
doctest.po
File metadata and controls
2390 lines (2085 loc) · 122 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2025, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# python-doc bot, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.9\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-03 16:35+0000\n"
"PO-Revision-Date: 2025-09-22 17:54+0000\n"
"Last-Translator: python-doc bot, 2025\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../library/doctest.rst:2
msgid ":mod:`doctest` --- Test interactive Python examples"
msgstr ":mod:`doctest` --- 测试交互式的 Python 示例"
#: ../../library/doctest.rst:12
msgid "**Source code:** :source:`Lib/doctest.py`"
msgstr "**源代码:** :source:`Lib/doctest.py`"
#: ../../library/doctest.rst:16
msgid ""
"The :mod:`doctest` module searches for pieces of text that look like "
"interactive Python sessions, and then executes those sessions to verify that"
" they work exactly as shown. There are several common ways to use doctest:"
msgstr ""
":mod:`doctest` "
"模块寻找像Python交互式代码的文本,然后执行这些代码来确保它们的确就像展示的那样正确运行,有许多方法来使用doctest:"
#: ../../library/doctest.rst:20
msgid ""
"To check that a module's docstrings are up-to-date by verifying that all "
"interactive examples still work as documented."
msgstr "通过验证所有交互式示例仍然按照记录的方式工作,以此来检查模块的文档字符串是否是最新的。"
#: ../../library/doctest.rst:23
msgid ""
"To perform regression testing by verifying that interactive examples from a "
"test file or a test object work as expected."
msgstr "通过验证来自一个测试文件或一个测试对象的交互式示例按预期工作,来进行回归测试。"
#: ../../library/doctest.rst:26
msgid ""
"To write tutorial documentation for a package, liberally illustrated with "
"input-output examples. Depending on whether the examples or the expository "
"text are emphasized, this has the flavor of \"literate testing\" or "
"\"executable documentation\"."
msgstr "为一个包写指导性的文档,用输入输出的例子来说明。 取决于是强调例子还是说明性的文字,这有一种 \"文本测试 \"或 \"可执行文档 \"的风格。"
#: ../../library/doctest.rst:31
msgid "Here's a complete but small example module::"
msgstr "下面是一个小却完整的示例模块::"
#: ../../library/doctest.rst:88
msgid ""
"If you run :file:`example.py` directly from the command line, :mod:`doctest`"
" works its magic:"
msgstr "如果你直接在命令行里运行 :file:`example.py` , :mod:`doctest` 将发挥它的作用。"
#: ../../library/doctest.rst:96
msgid ""
"There's no output! That's normal, and it means all the examples worked. "
"Pass ``-v`` to the script, and :mod:`doctest` prints a detailed log of what "
"it's trying, and prints a summary at the end:"
msgstr ""
"没有输出! 这很正常,这意味着所有的例子都成功了。 把 ``-v`` 传给脚本,:mod:`doctest` "
"会打印出它所尝试的详细日志,并在最后打印出一个总结。"
#: ../../library/doctest.rst:114
msgid "And so on, eventually ending with:"
msgstr "以此类推,最终以:"
#: ../../library/doctest.rst:133
msgid ""
"That's all you need to know to start making productive use of "
":mod:`doctest`! Jump in. The following sections provide full details. Note"
" that there are many examples of doctests in the standard Python test suite "
"and libraries. Especially useful examples can be found in the standard test "
"file :file:`Lib/test/test_doctest.py`."
msgstr ""
"这就是对于高效地使用 :mod:`doctest` 你所需要知道的一切!开始上手吧。 下面的章节提供了完整的细节。 请注意,在标准的 Python "
"测试套件和库中有许多 doctest 的例子。特别有用的例子可以在标准测试文件 :file:`Lib/test/test_doctest.py` "
"中找到。"
#: ../../library/doctest.rst:143
msgid "Simple Usage: Checking Examples in Docstrings"
msgstr "简单用法:检查Docstrings中的示例"
#: ../../library/doctest.rst:145
msgid ""
"The simplest way to start using doctest (but not necessarily the way you'll "
"continue to do it) is to end each module :mod:`M` with::"
msgstr "开始使用doctest的最简单方法(但不一定是你将继续这样做的方式)是结束每个模块 :mod:`M` 使用::"
#: ../../library/doctest.rst:152
msgid ":mod:`doctest` then examines docstrings in module :mod:`M`."
msgstr ":mod:`doctest` 会随后检查模块 :mod:`M` 中的文档字符串。"
#: ../../library/doctest.rst:154
msgid ""
"Running the module as a script causes the examples in the docstrings to get "
"executed and verified::"
msgstr "以脚本形式运行该模块会使文档中的例子得到执行和验证::"
#: ../../library/doctest.rst:159
msgid ""
"This won't display anything unless an example fails, in which case the "
"failing example(s) and the cause(s) of the failure(s) are printed to stdout,"
" and the final line of output is ``***Test Failed*** N failures.``, where "
"*N* is the number of examples that failed."
msgstr ""
"这不会显示任何东西,除非一个例子失败了,在这种情况下,失败的例子和失败的原因会被打印到stdout,最后一行的输出是 ``***Test "
"Failed*** N failures.``,其中 *N* 是失败的例子的数量。"
#: ../../library/doctest.rst:164
msgid "Run it with the ``-v`` switch instead::"
msgstr "用 ``-v`` 来运行它来切换,而不是::"
#: ../../library/doctest.rst:168
msgid ""
"and a detailed report of all examples tried is printed to standard output, "
"along with assorted summaries at the end."
msgstr "并将所有尝试过的例子的详细报告打印到标准输出,最后还有各种总结。"
#: ../../library/doctest.rst:171
msgid ""
"You can force verbose mode by passing ``verbose=True`` to :func:`testmod`, "
"or prohibit it by passing ``verbose=False``. In either of those cases, "
"``sys.argv`` is not examined by :func:`testmod` (so passing ``-v`` or not "
"has no effect)."
msgstr ""
"你可以通过向 :func:`testmod` 传递 ``verbose=True`` 来强制执行 verbose 模式,或者通过传递 "
"``verbose=False`` 来禁止它。 在这两种情况下,``sys.argv`` 都不会被 :func:`testmod` 检查(所以传递 "
"``-v`` 或不传递都没有影响)。"
#: ../../library/doctest.rst:176
msgid ""
"There is also a command line shortcut for running :func:`testmod`. You can "
"instruct the Python interpreter to run the doctest module directly from the "
"standard library and pass the module name(s) on the command line::"
msgstr ""
"还有一个命令行快捷方式用于运行 :func:`testmod`。 "
"你可以指示Python解释器直接从标准库中运行doctest模块,并在命令行中传递模块名称::"
#: ../../library/doctest.rst:182
msgid ""
"This will import :file:`example.py` as a standalone module and run "
":func:`testmod` on it. Note that this may not work correctly if the file is"
" part of a package and imports other submodules from that package."
msgstr ""
"这将导入 :file:`example.py` 作为一个独立的模块,并对其运行 :func:`testmod`。 "
"注意,如果该文件是一个包的一部分,并且从该包中导入了其他子模块,这可能无法正确工作。"
#: ../../library/doctest.rst:186
msgid ""
"For more information on :func:`testmod`, see section :ref:`doctest-basic-"
"api`."
msgstr "关于 :func:`testmod` 的更多信息,请参见 :ref:`doctest-basic-api` 部分。"
#: ../../library/doctest.rst:192
msgid "Simple Usage: Checking Examples in a Text File"
msgstr "简单的用法:检查文本文件中的例子"
#: ../../library/doctest.rst:194
msgid ""
"Another simple application of doctest is testing interactive examples in a "
"text file. This can be done with the :func:`testfile` function::"
msgstr "doctest 的另一个简单应用是测试文本文件中的交互式例子。 这可以用 :func:`testfile` 函数来完成::"
#: ../../library/doctest.rst:200
msgid ""
"That short script executes and verifies any interactive Python examples "
"contained in the file :file:`example.txt`. The file content is treated as "
"if it were a single giant docstring; the file doesn't need to contain a "
"Python program! For example, perhaps :file:`example.txt` contains this:"
msgstr ""
"这个简短的脚本执行并验证文件 :file:`example.txt` 中包含的任何交互式 Python "
"示例。该文件的内容被当作一个巨大的文档串来处理;该文件不需要包含一个Python程序!例如,也许 :file:`example.txt` 包含以下内容:"
#: ../../library/doctest.rst:223
msgid ""
"Running ``doctest.testfile(\"example.txt\")`` then finds the error in this "
"documentation::"
msgstr "运行 ``doctest.testfile(\"example.txt\")``,然后发现这个文档中的错误::"
#: ../../library/doctest.rst:234
msgid ""
"As with :func:`testmod`, :func:`testfile` won't display anything unless an "
"example fails. If an example does fail, then the failing example(s) and the"
" cause(s) of the failure(s) are printed to stdout, using the same format as "
":func:`testmod`."
msgstr ""
"与 :func:`testmod` 一样, :func:`testfile` 不会显示任何东西,除非一个例子失败。 "
"如果一个例子失败了,那么失败的例子和失败的原因将被打印到stdout,使用的格式与 :func:`testmod` 相同。"
#: ../../library/doctest.rst:239
msgid ""
"By default, :func:`testfile` looks for files in the calling module's "
"directory. See section :ref:`doctest-basic-api` for a description of the "
"optional arguments that can be used to tell it to look for files in other "
"locations."
msgstr ""
"默认情况下,:func:`testfile` 在调用模块的目录中寻找文件。参见章节 :ref:`doctest-basic-"
"api`,了解可用于告诉它在其他位置寻找文件的可选参数的描述。"
#: ../../library/doctest.rst:243
msgid ""
"Like :func:`testmod`, :func:`testfile`'s verbosity can be set with the "
"``-v`` command-line switch or with the optional keyword argument *verbose*."
msgstr ""
"像 :func:`testmod` 一样,:func:`testfile` 的详细程度可以通过命令行 ``-v`` 切换或可选的关键字参数 "
"*verbose* 来设置。"
#: ../../library/doctest.rst:247
msgid ""
"There is also a command line shortcut for running :func:`testfile`. You can"
" instruct the Python interpreter to run the doctest module directly from the"
" standard library and pass the file name(s) on the command line::"
msgstr ""
"还有一个命令行快捷方式用于运行 :func:`testfile`。 "
"你可以指示Python解释器直接从标准库中运行doctest模块,并在命令行中传递文件名::"
#: ../../library/doctest.rst:253
msgid ""
"Because the file name does not end with :file:`.py`, :mod:`doctest` infers "
"that it must be run with :func:`testfile`, not :func:`testmod`."
msgstr ""
"因为文件名没有以 :file:`.py` 结尾,:mod:`doctest` 推断它必须用 :func:`testfile` 运行,而不是 "
":func:`testmod`。"
#: ../../library/doctest.rst:256
msgid ""
"For more information on :func:`testfile`, see section :ref:`doctest-basic-"
"api`."
msgstr "关于 :func:`testfile` 的更多信息,请参见 :ref:`doctest-basic-api` 一节。"
#: ../../library/doctest.rst:262
msgid "How It Works"
msgstr "它是如何工作的"
#: ../../library/doctest.rst:264
msgid ""
"This section examines in detail how doctest works: which docstrings it looks"
" at, how it finds interactive examples, what execution context it uses, how "
"it handles exceptions, and how option flags can be used to control its "
"behavior. This is the information that you need to know to write doctest "
"examples; for information about actually running doctest on these examples, "
"see the following sections."
msgstr ""
"这一节详细研究了doctest的工作原理:它查看哪些文档串,它如何找到交互式的用例,它使用什么执行环境,它如何处理异常,以及如何用选项标志来控制其行为。这是你写doctest例子所需要知道的信息;关于在这些例子上实际运行doctest的信息,请看下面的章节。"
#: ../../library/doctest.rst:275
msgid "Which Docstrings Are Examined?"
msgstr "哪些文件串被检查了?"
#: ../../library/doctest.rst:277
msgid ""
"The module docstring, and all function, class and method docstrings are "
"searched. Objects imported into the module are not searched."
msgstr "模块的文档串以及所有函数、类和方法的文档串都将被搜索。 导入模块的对象不被搜索。"
#: ../../library/doctest.rst:280
msgid ""
"In addition, if ``M.__test__`` exists and \"is true\", it must be a dict, "
"and each entry maps a (string) name to a function object, class object, or "
"string. Function and class object docstrings found from ``M.__test__`` are "
"searched, and strings are treated as if they were docstrings. In output, a "
"key ``K`` in ``M.__test__`` appears with name ::"
msgstr ""
"此外,如果 ``M.__test__`` 存在并且 "
"\"为真值\",则它必须是一个字典,其中每个条目都将一个(字符串)名称映射到一个函数对象、类对象或字符串。 从 ``M.__test__`` "
"找到的函数和类对象的文档字符串会被搜索,而字符串会被当作文档字符串来处理。 在输出时,每个键 ``K`` 在 ``M.__test__`` "
"中都显示为其名称 ::"
#: ../../library/doctest.rst:288
msgid ""
"Any classes found are recursively searched similarly, to test docstrings in "
"their contained methods and nested classes."
msgstr "任何发现的类都会以类似的方式进行递归搜索,以测试其包含的方法和嵌套类中的文档串。"
#: ../../library/doctest.rst:299
msgid "How are Docstring Examples Recognized?"
msgstr "文档串的例子是如何被识别的?"
#: ../../library/doctest.rst:301
msgid ""
"In most cases a copy-and-paste of an interactive console session works fine,"
" but doctest isn't trying to do an exact emulation of any specific Python "
"shell."
msgstr ""
"在大多数情况下,对交互式控制台会话的复制和粘贴功能工作得很好,但是 doctest 并不试图对任何特定的 Python shell 进行精确的模拟。"
#: ../../library/doctest.rst:326
msgid ""
"Any expected output must immediately follow the final ``'>>> '`` or ``'... "
"'`` line containing the code, and the expected output (if any) extends to "
"the next ``'>>> '`` or all-whitespace line."
msgstr ""
"任何预期的输出必须紧随包含代码的最后 ``'>>> '`` 或 ``'... '`` 行,预期的输出(如果有的话)延伸到下一 ``'>>> '`` "
"行或全空白行。"
#: ../../library/doctest.rst:330
msgid "The fine print:"
msgstr "fine输出:"
#: ../../library/doctest.rst:332
msgid ""
"Expected output cannot contain an all-whitespace line, since such a line is "
"taken to signal the end of expected output. If expected output does contain"
" a blank line, put ``<BLANKLINE>`` in your doctest example each place a "
"blank line is expected."
msgstr ""
"预期输出不能包含一个全白的行,因为这样的行被认为是预期输出的结束信号。 如果预期的输出包含一个空行,在你的测试例子中,在每一个预期有空行的地方加上 "
"``<BLANKLINE>``。"
#: ../../library/doctest.rst:337
msgid ""
"All hard tab characters are expanded to spaces, using 8-column tab stops. "
"Tabs in output generated by the tested code are not modified. Because any "
"hard tabs in the sample output *are* expanded, this means that if the code "
"output includes hard tabs, the only way the doctest can pass is if the "
":const:`NORMALIZE_WHITESPACE` option or :ref:`directive <doctest-"
"directives>` is in effect. Alternatively, the test can be rewritten to "
"capture the output and compare it to an expected value as part of the test."
" This handling of tabs in the source was arrived at through trial and "
"error, and has proven to be the least error prone way of handling them. It "
"is possible to use a different algorithm for handling tabs by writing a "
"custom :class:`DocTestParser` class."
msgstr ""
"所有硬制表符都被扩展为空格,使用 8 列的制表符。由测试代码生成的输出中的制表符不会被修改。 "
"因为样本输出中的任何硬制表符都会被扩展,这意味着如果代码输出包括硬制表符,文档测试通过的唯一方法是 "
":const:`NORMALIZE_WHITESPACE` 选项或者 :ref:`指令 <doctest-directives>` 是有效的。 "
"另外,测试可以被重写,以捕获输出并将其与预期值进行比较,作为测试的一部分。这种对源码中标签的处理是通过试错得出的,并被证明是最不容易出错的处理方式。通过编写一个自定义的"
" :class:`DocTestParser` 类,可以使用一个不同的算法来处理标签。"
#: ../../library/doctest.rst:349
msgid ""
"Output to stdout is captured, but not output to stderr (exception tracebacks"
" are captured via a different means)."
msgstr "向stdout的输出被捕获,但不向stderr输出(异常回溯通过不同的方式被捕获)。"
#: ../../library/doctest.rst:352
msgid ""
"If you continue a line via backslashing in an interactive session, or for "
"any other reason use a backslash, you should use a raw docstring, which will"
" preserve your backslashes exactly as you type them::"
msgstr "如果你在交互式会话中通过反斜线续行,或出于任何其他原因使用反斜线,你应该使用原始文件串,它将完全保留你输入的反斜线::"
#: ../../library/doctest.rst:361
msgid ""
"Otherwise, the backslash will be interpreted as part of the string. For "
"example, the ``\\n`` above would be interpreted as a newline character. "
"Alternatively, you can double each backslash in the doctest version (and not"
" use a raw string)::"
msgstr ""
"否则,反斜杠将被解释为字符串的一部分。例如,上面的 ``\\n`` 会被解释为一个换行符。 "
"另外,你可以在doctest版本中把每个反斜杠加倍(而不使用原始字符串)::"
#: ../../library/doctest.rst:370
msgid "The starting column doesn't matter::"
msgstr "起始列并不重要::"
#: ../../library/doctest.rst:377
msgid ""
"and as many leading whitespace characters are stripped from the expected "
"output as appeared in the initial ``'>>> '`` line that started the example."
msgstr "并从预期的输出中剥离出与开始该例子的初始 ``'>>> '`` 行中出现的同样多的前导空白字符。"
#: ../../library/doctest.rst:384
msgid "What's the Execution Context?"
msgstr "什么是执行上下文?"
#: ../../library/doctest.rst:386
msgid ""
"By default, each time :mod:`doctest` finds a docstring to test, it uses a "
"*shallow copy* of :mod:`M`'s globals, so that running tests doesn't change "
"the module's real globals, and so that one test in :mod:`M` can't leave "
"behind crumbs that accidentally allow another test to work. This means "
"examples can freely use any names defined at top-level in :mod:`M`, and "
"names defined earlier in the docstring being run. Examples cannot see names "
"defined in other docstrings."
msgstr ""
"默认情况下,每次 :mod:`doctest` 找到要测试的文档串时,它都会使用 :mod:`M` "
"的*浅层副本*,这样运行测试就不会改变模块的真正全局变量,而且 :mod:`M` "
"的一个测试也不会留下临时变量,从而意外地让另一个测试通过。这意味着例子可以自由地使用 :mod:`M` "
"中的任何顶级定义的名字,以及正在运行的文档串中早期定义的名字。用例不能看到其他文档串中定义的名字。"
#: ../../library/doctest.rst:394
msgid ""
"You can force use of your own dict as the execution context by passing "
"``globs=your_dict`` to :func:`testmod` or :func:`testfile` instead."
msgstr ""
"你可以通过将 ``globs=your_dict`` 传递给 :func:`testmod` 或 :func:`testfile` "
"来强制使用你自己的dict作为执行环境。"
#: ../../library/doctest.rst:401
msgid "What About Exceptions?"
msgstr "异常如何处理?"
#: ../../library/doctest.rst:403
msgid ""
"No problem, provided that the traceback is the only output produced by the "
"example: just paste in the traceback. [#]_ Since tracebacks contain details"
" that are likely to change rapidly (for example, exact file paths and line "
"numbers), this is one case where doctest works hard to be flexible in what "
"it accepts."
msgstr ""
"没问题,只要回溯是这个例子产生的唯一输出:只要粘贴回溯即可。[#]_ "
"由于回溯所包含的细节可能会迅速变化(例如,确切的文件路径和行号),这是doctest努力使其接受的内容具有灵活性的一种情况。"
#: ../../library/doctest.rst:409
msgid "Simple example::"
msgstr "简单实例::"
#: ../../library/doctest.rst:416
msgid ""
"That doctest succeeds if :exc:`ValueError` is raised, with the "
"``list.remove(x): x not in list`` detail as shown."
msgstr ""
"如果 :exc:`ValueError` 被触发,该测试就会成功,``list.remove(x): x not in list`` 的细节如图所示。"
#: ../../library/doctest.rst:419
msgid ""
"The expected output for an exception must start with a traceback header, "
"which may be either of the following two lines, indented the same as the "
"first line of the example::"
msgstr "异常的预期输出必须以回溯头开始,可以是以下两行中的任何一行,缩进程度与例子中的第一行相同::"
#: ../../library/doctest.rst:426
msgid ""
"The traceback header is followed by an optional traceback stack, whose "
"contents are ignored by doctest. The traceback stack is typically omitted, "
"or copied verbatim from an interactive session."
msgstr "回溯头的后面是一个可选的回溯堆栈,其内容被doctest忽略。 回溯堆栈通常是省略的,或者从交互式会话中逐字复制的。"
#: ../../library/doctest.rst:430
msgid ""
"The traceback stack is followed by the most interesting part: the line(s) "
"containing the exception type and detail. This is usually the last line of "
"a traceback, but can extend across multiple lines if the exception has a "
"multi-line detail::"
msgstr "回溯堆栈的后面是最有用的部分:包含异常类型和细节的一行(几行)。 这通常是回溯的最后一行,但如果异常有多行细节,则可以延伸到多行::"
#: ../../library/doctest.rst:442
msgid ""
"The last three lines (starting with :exc:`ValueError`) are compared against "
"the exception's type and detail, and the rest are ignored."
msgstr "最后三行(以 :exc:`ValueError` 开头)将与异常的类型和细节进行比较,其余的被忽略。"
#: ../../library/doctest.rst:445
msgid ""
"Best practice is to omit the traceback stack, unless it adds significant "
"documentation value to the example. So the last example is probably better "
"as::"
msgstr "最佳实践是省略回溯栈,除非它为这个例子增加了重要的文档价值。 因此,最后一个例子可能更好,因为::"
#: ../../library/doctest.rst:455
msgid ""
"Note that tracebacks are treated very specially. In particular, in the "
"rewritten example, the use of ``...`` is independent of doctest's "
":const:`ELLIPSIS` option. The ellipsis in that example could be left out, "
"or could just as well be three (or three hundred) commas or digits, or an "
"indented transcript of a Monty Python skit."
msgstr ""
"请注意,回溯的处理方式非常特别。 特别是,在重写的例子中,``...`` 的使用与 doctest 的 :const:`ELLIPSIS` 选项无关。 "
"该例子中的省略号可以不写,也可以是三个(或三百个)逗号或数字,或者是一个缩进的 Monty Python 短剧的剧本。"
#: ../../library/doctest.rst:461
msgid "Some details you should read once, but won't need to remember:"
msgstr "有些细节你应该读一遍,但不需要记住:"
#: ../../library/doctest.rst:463
msgid ""
"Doctest can't guess whether your expected output came from an exception "
"traceback or from ordinary printing. So, e.g., an example that expects "
"``ValueError: 42 is prime`` will pass whether :exc:`ValueError` is actually "
"raised or if the example merely prints that traceback text. In practice, "
"ordinary output rarely begins with a traceback header line, so this doesn't "
"create real problems."
msgstr ""
"Doctest 不能猜测你的预期输出是来自异常回溯还是来自普通打印。 因此,例如,一个期望 ``ValueError: 42 is prime`` "
"的用例将通过测试,无论 :exc:`ValueError` 是真的被触发,或者该用例只是打印了该回溯文本。 "
"在实践中,普通输出很少以回溯标题行开始,所以这不会产生真正的问题。"
#: ../../library/doctest.rst:470
msgid ""
"Each line of the traceback stack (if present) must be indented further than "
"the first line of the example, *or* start with a non-alphanumeric character."
" The first line following the traceback header indented the same and "
"starting with an alphanumeric is taken to be the start of the exception "
"detail. Of course this does the right thing for genuine tracebacks."
msgstr ""
"回溯堆栈的每一行(如果有的话)必须比例子的第一行缩进, *或者* "
"以一个非字母数字的字符开始。回溯头之后的第一行缩进程度相同,并且以字母数字开始,被认为是异常细节的开始。当然,这对真正的回溯来说是正确的事情。"
#: ../../library/doctest.rst:476
msgid ""
"When the :const:`IGNORE_EXCEPTION_DETAIL` doctest option is specified, "
"everything following the leftmost colon and any module information in the "
"exception name is ignored."
msgstr ""
"当 :const:`IGNORE_EXCEPTION_DETAIL` doctest "
"选项被指定时,最左边的冒号后面的所有内容以及异常名称中的任何模块信息都被忽略。"
#: ../../library/doctest.rst:480
msgid ""
"The interactive shell omits the traceback header line for some "
":exc:`SyntaxError`\\ s. But doctest uses the traceback header line to "
"distinguish exceptions from non-exceptions. So in the rare case where you "
"need to test a :exc:`SyntaxError` that omits the traceback header, you will "
"need to manually add the traceback header line to your test example."
msgstr ""
"交互式 shell 省略了一些 :exc:`SyntaxError` 的回溯头行。但 doctest "
"使用回溯头行来区分异常和非异常。所以在罕见的情况下,如果你需要测试一个省略了回溯头的 "
":exc:`SyntaxError`,你将需要手动添加回溯头行到你的测试用例中。"
#: ../../library/doctest.rst:488
msgid ""
"For some :exc:`SyntaxError`\\ s, Python displays the character position of "
"the syntax error, using a ``^`` marker::"
msgstr "对于一些 :exc:`SyntaxError`,Python 使用 ``^`` 标记显示语法错误的字符位置::"
#: ../../library/doctest.rst:497
msgid ""
"Since the lines showing the position of the error come before the exception "
"type and detail, they are not checked by doctest. For example, the "
"following test would pass, even though it puts the ``^`` marker in the wrong"
" location::"
msgstr ""
"由于显示错误位置的行在异常类型和细节之前,它们不被doctest检查。 例如,下面的测试会通过,尽管它把 ``^`` 标记放在了错误的位置::"
#: ../../library/doctest.rst:513
msgid "Option Flags"
msgstr "选项标记"
#: ../../library/doctest.rst:515
msgid ""
"A number of option flags control various aspects of doctest's behavior. "
"Symbolic names for the flags are supplied as module constants, which can be "
":ref:`bitwise ORed <bitwise>` together and passed to various functions. The "
"names can also be used in :ref:`doctest directives <doctest-directives>`, "
"and may be passed to the doctest command line interface via the ``-o`` "
"option."
msgstr ""
"一系列选项旗标控制着 doctest 的各方面行为。 旗标的符号名称以模块常量的形式提供,可以一起 :ref:`bitwise ORed "
"<bitwise>` 并传递给各种函数。 这些名称也可以在 :ref:`doctest directives <doctest-directives>`"
" 中使用,并且可以通过 ``-o`` 选项传递给 doctest 命令行接口。"
#: ../../library/doctest.rst:521
msgid "The ``-o`` command line option."
msgstr "命令行选项 ``-o`` 。"
#: ../../library/doctest.rst:524
msgid ""
"The first group of options define test semantics, controlling aspects of how"
" doctest decides whether actual output matches an example's expected output:"
msgstr "第一组选项定义了测试语义,控制doctest如何决定实际输出是否与用例的预期输出相匹配方面的问题。"
#: ../../library/doctest.rst:530
msgid ""
"By default, if an expected output block contains just ``1``, an actual "
"output block containing just ``1`` or just ``True`` is considered to be a "
"match, and similarly for ``0`` versus ``False``. When "
":const:`DONT_ACCEPT_TRUE_FOR_1` is specified, neither substitution is "
"allowed. The default behavior caters to that Python changed the return type"
" of many functions from integer to boolean; doctests expecting \"little "
"integer\" output still work in these cases. This option will probably go "
"away, but not for several years."
msgstr ""
"默认情况下,如果一个预期的输出块只包含 ``1``,那么实际的输出块只包含 ``1`` 或只包含 ``True`` 就被认为是匹配的,同样,``0`` "
"与 ``False`` 也是如此。 当 :const:`DONT_ACCEPT_TRUE_FOR_1` 被指定时,两种替换都不允许。 "
"默认行为是为了适应 Python 将许多函数的返回类型从整数改为布尔值;期望 \"小整数\" 输出的测试在这些情况下仍然有效。 "
"这个选项可能会消失,但不会在几年内消失。"
#: ../../library/doctest.rst:542
msgid ""
"By default, if an expected output block contains a line containing only the "
"string ``<BLANKLINE>``, then that line will match a blank line in the actual"
" output. Because a genuinely blank line delimits the expected output, this "
"is the only way to communicate that a blank line is expected. When "
":const:`DONT_ACCEPT_BLANKLINE` is specified, this substitution is not "
"allowed."
msgstr ""
"默认情况下,如果一个预期输出块包含一个只包含字符串 ``<BLANKLINE>`` 的行,那么该行将与实际输出中的一个空行相匹配。 "
"因为一个真正的空行是对预期输出的限定,这是传达预期空行的唯一方法。 当 :const:`DONT_ACCEPT_BLANKLINE` "
"被指定时,这种替换是不允许的。"
#: ../../library/doctest.rst:551
msgid ""
"When specified, all sequences of whitespace (blanks and newlines) are "
"treated as equal. Any sequence of whitespace within the expected output "
"will match any sequence of whitespace within the actual output. By default, "
"whitespace must match exactly. :const:`NORMALIZE_WHITESPACE` is especially "
"useful when a line of expected output is very long, and you want to wrap it "
"across multiple lines in your source."
msgstr ""
"当指定时,所有的空白序列(空白和换行)都被视为相等。预期输出中的任何空白序列将与实际输出中的任何空白序列匹配。默认情况下,空白必须完全匹配。 "
":const:`NORMALIZE_WHITESPACE` 在预期输出非常长的一行,而你想把它包在源代码的多行中时特别有用。"
#: ../../library/doctest.rst:562
msgid ""
"When specified, an ellipsis marker (``...``) in the expected output can "
"match any substring in the actual output. This includes substrings that "
"span line boundaries, and empty substrings, so it's best to keep usage of "
"this simple. Complicated uses can lead to the same kinds of \"oops, it "
"matched too much!\" surprises that ``.*`` is prone to in regular "
"expressions."
msgstr ""
"当指定时,预期输出中的省略号( ``...`` )可以匹配实际输出中的任何子串。这包括跨行的子串和空子串,所以最好保持简单的用法。复杂的用法会导致与 "
"``.*`` 在正则表达式中容易出现的 \"oops, it matched too much!\"相同的意外情况。"
#: ../../library/doctest.rst:571
msgid ""
"When specified, doctests expecting exceptions pass so long as an exception "
"of the expected type is raised, even if the details (message and fully-"
"qualified exception name) don't match."
msgstr "当被指定时,只要有预期类型的异常被引发 doctests 就会预期异常测试通过,即使细节(消息和完整限定异常名称)不匹配。"
#: ../../library/doctest.rst:575
msgid ""
"For example, an example expecting ``ValueError: 42`` will pass if the actual"
" exception raised is ``ValueError: 3*14``, but will fail if, say, a "
":exc:`TypeError` is raised instead. It will also ignore any fully-qualified "
"name included before the exception class, which can vary between "
"implementations and versions of Python and the code/libraries in use. Hence,"
" all three of these variations will work with the flag specified:"
msgstr ""
"举例来说,一个例子预期 ``ValueError: 42`` 将通过,如果实际引发的异常是 ``ValueError: 3*14``,但是如果引发的是 "
":exc:`TypeError` 则将失败。 它也将忽略任何包括在异常类前面的完整限定名称,该名称在所使用的不同 Python "
"版本和代码/库中可能会不同。 因此,以下三种形式对于指定的旗标均有效:"
#: ../../library/doctest.rst:597
msgid ""
"Note that :const:`ELLIPSIS` can also be used to ignore the details of the "
"exception message, but such a test may still fail based on whether the "
"module name is present or matches exactly."
msgstr ""
"请注意 :const:`ELLIPSIS` 也可以被用来忽略异常消息中的细节,但这样的测试仍然可能根据特定模块名称是否存在或是否完全匹配而失败。"
#: ../../library/doctest.rst:601
msgid ""
":const:`IGNORE_EXCEPTION_DETAIL` now also ignores any information relating "
"to the module containing the exception under test."
msgstr ":const:`IGNORE_EXCEPTION_DETAIL` 现在也忽略了与包含被测异常的模块有关的任何信息。"
#: ../../library/doctest.rst:608
msgid ""
"When specified, do not run the example at all. This can be useful in "
"contexts where doctest examples serve as both documentation and test cases, "
"and an example should be included for documentation purposes, but should not"
" be checked. E.g., the example's output might be random; or the example "
"might depend on resources which would be unavailable to the test driver."
msgstr ""
"当指定时,完全不运行这个用例。 "
"这在doctest用例既是文档又是测试案例的情况下很有用,一个例子应该包括在文档中,但不应该被检查。例如,这个例子的输出可能是随机的;或者这个例子可能依赖于测试驱动程序所不能使用的资源。"
#: ../../library/doctest.rst:614
msgid ""
"The SKIP flag can also be used for temporarily \"commenting out\" examples."
msgstr "SKIP标志也可用于临时 \"注释\" 用例。"
#: ../../library/doctest.rst:619
msgid "A bitmask or'ing together all the comparison flags above."
msgstr "一个比特或运算将上述所有的比较标志放在一起。"
#: ../../library/doctest.rst:621
msgid "The second group of options controls how test failures are reported:"
msgstr "第二组选项控制测试失败的报告方式:"
#: ../../library/doctest.rst:626
msgid ""
"When specified, failures that involve multi-line expected and actual outputs"
" are displayed using a unified diff."
msgstr "当指定时,涉及多行预期和实际输出的故障将使用统一的差异来显示。"
#: ../../library/doctest.rst:632
msgid ""
"When specified, failures that involve multi-line expected and actual outputs"
" will be displayed using a context diff."
msgstr "当指定时,涉及多行预期和实际输出的故障将使用上下文差异来显示。"
#: ../../library/doctest.rst:638
msgid ""
"When specified, differences are computed by ``difflib.Differ``, using the "
"same algorithm as the popular :file:`ndiff.py` utility. This is the only "
"method that marks differences within lines as well as across lines. For "
"example, if a line of expected output contains digit ``1`` where actual "
"output contains letter ``l``, a line is inserted with a caret marking the "
"mismatching column positions."
msgstr ""
"当指定时,差异由 ``difflib.Differ`` "
"来计算,使用与流行的:file:`ndiff.py`工具相同的算法。这是唯一一种标记行内和行间差异的方法。 例如,如果一行预期输出包含数字 ``1`` "
",而实际输出包含字母 ``l`` ,那么就会插入一行,用圆点标记不匹配的列位置。"
#: ../../library/doctest.rst:647
msgid ""
"When specified, display the first failing example in each doctest, but "
"suppress output for all remaining examples. This will prevent doctest from "
"reporting correct examples that break because of earlier failures; but it "
"might also hide incorrect examples that fail independently of the first "
"failure. When :const:`REPORT_ONLY_FIRST_FAILURE` is specified, the "
"remaining examples are still run, and still count towards the total number "
"of failures reported; only the output is suppressed."
msgstr ""
"当指定时,在每个 doctest 中显示第一个失败的用例,但隐藏所有其余用例的输出。 这将防止 doctest "
"报告由于先前的失败而中断的正确用例;但也可能隐藏独立于第一个失败的不正确用例。 当 :const:`REPORT_ONLY_FIRST_FAILURE`"
" 被指定时,其余的用例仍然被运行,并且仍然计入报告的失败总数;只是输出被隐藏了。"
#: ../../library/doctest.rst:658
msgid ""
"When specified, exit after the first failing example and don't attempt to "
"run the remaining examples. Thus, the number of failures reported will be at"
" most 1. This flag may be useful during debugging, since examples after the"
" first failure won't even produce debugging output."
msgstr ""
"当指定时,在第一个失败的用例后退出,不尝试运行其余的用例。因此,报告的失败次数最多为1。这个标志在调试时可能很有用,因为第一个失败后的用例甚至不会产生调试输出。"
#: ../../library/doctest.rst:663
msgid ""
"The doctest command line accepts the option ``-f`` as a shorthand for ``-o "
"FAIL_FAST``."
msgstr "doctest 命令行接受选项 ``-f`` 作为 ``-o FAIL_FAST`` 的简洁形式。"
#: ../../library/doctest.rst:671
msgid "A bitmask or'ing together all the reporting flags above."
msgstr "一个比特或操作将上述所有的报告标志组合在一起。"
#: ../../library/doctest.rst:674
msgid ""
"There is also a way to register new option flag names, though this isn't "
"useful unless you intend to extend :mod:`doctest` internals via subclassing:"
msgstr "还有一种方法可以注册新的选项标志名称,不过这并不有用,除非你打算通过子类来扩展 :mod:`doctest` 内部。"
#: ../../library/doctest.rst:680
msgid ""
"Create a new option flag with a given name, and return the new flag's "
"integer value. :func:`register_optionflag` can be used when subclassing "
":class:`OutputChecker` or :class:`DocTestRunner` to create new options that "
"are supported by your subclasses. :func:`register_optionflag` should always"
" be called using the following idiom::"
msgstr ""
"用给定的名称创建一个新的选项标志,并返回新标志的整数值。 :func:`register_optionflag` 可以在继承 "
":class:`OutputChecker` 或 :class:`DocTestRunner` 时使用,以创建子类支持的新选项。 "
":func:`register_optionflag` 应始终使用以下方式调用::"
#: ../../library/doctest.rst:696
msgid "Directives"
msgstr "指令"
#: ../../library/doctest.rst:698
msgid ""
"Doctest directives may be used to modify the :ref:`option flags <doctest-"
"options>` for an individual example. Doctest directives are special Python "
"comments following an example's source code:"
msgstr ""
"Doctest指令可以用来修改单个例子的 :ref:`option flags <doctest-options>` 。 "
"Doctest指令是在一个用例的源代码后面的特殊Python注释。"
#: ../../library/doctest.rst:709
msgid ""
"Whitespace is not allowed between the ``+`` or ``-`` and the directive "
"option name. The directive option name can be any of the option flag names "
"explained above."
msgstr "``+`` 或 ``-`` 与指令选项名称之间不允许有空格。 指令选项名称可以是上面解释的任何一个选项标志名称。"
#: ../../library/doctest.rst:713
msgid ""
"An example's doctest directives modify doctest's behavior for that single "
"example. Use ``+`` to enable the named behavior, or ``-`` to disable it."
msgstr ""
"一个用例的 doctest 指令可以修改 doctest 对该用例的行为。 使用 ``+`` 来启用指定的行为,或者使用 ``-`` 来禁用它。"
#: ../../library/doctest.rst:716
msgid "For example, this test passes::"
msgstr "例如,这个测试将会通过::"
#: ../../library/doctest.rst:722
msgid ""
"Without the directive it would fail, both because the actual output doesn't "
"have two blanks before the single-digit list elements, and because the "
"actual output is on a single line. This test also passes, and also requires"
" a directive to do so::"
msgstr ""
"如果没有这个指令,它就会失败,这是因为实际的输出在个位数的列表元素前没有两个空格,也因为实际的输出是在单行上。 "
"这个测试也通过了,而且也需要一个指令来完成::"
#: ../../library/doctest.rst:730
msgid ""
"Multiple directives can be used on a single physical line, separated by "
"commas::"
msgstr "在一个物理行上可以使用多个指令,用逗号分隔::"
#: ../../library/doctest.rst:736
msgid ""
"If multiple directive comments are used for a single example, then they are "
"combined::"
msgstr "如果在一个用例中使用了多个指令注释,那么它们将被合并::"
#: ../../library/doctest.rst:743
msgid ""
"As the previous example shows, you can add ``...`` lines to your example "
"containing only directives. This can be useful when an example is too long "
"for a directive to comfortably fit on the same line::"
msgstr "正如前面的例子所示,你可以在你的用例中添加只包含指令的行。 当一个用例太长,指令不能舒适地放在同一行时,这可能很有用::"
#: ../../library/doctest.rst:751
msgid ""
"Note that since all options are disabled by default, and directives apply "
"only to the example they appear in, enabling options (via ``+`` in a "
"directive) is usually the only meaningful choice. However, option flags can"
" also be passed to functions that run doctests, establishing different "
"defaults. In such cases, disabling an option via ``-`` in a directive can "
"be useful."
msgstr ""
"请注意,由于所有的选项都是默认禁用的,而指令只适用于它们出现的用例,所以启用选项 (通过指令中的 ``+``) 通常是唯一有意义的选择。 "
"然而,选项标志也可以被传递给运行测试的函数,建立不同的默认值。 在这种情况下,通过指令中的 ``-`` 来禁用一个选项可能是有用的。"
#: ../../library/doctest.rst:761
msgid "Warnings"
msgstr "警告"
#: ../../library/doctest.rst:763
msgid ""
":mod:`doctest` is serious about requiring exact matches in expected output."
" If even a single character doesn't match, the test fails. This will "
"probably surprise you a few times, as you learn exactly what Python does and"
" doesn't guarantee about output. For example, when printing a set, Python "
"doesn't guarantee that the element is printed in any particular order, so a "
"test like ::"
msgstr ""
":mod:`doctest` 是严格地要求在预期输出中完全匹配。 如果哪怕只有一个字符不匹配,测试就会失败。 这可能会让你吃惊几次,在你确切地了解到 "
"Python 对输出的保证和不保证之前。 例如,当打印一个集合时,Python 不保证元素以任何特定的顺序被打印出来,所以像::"
#: ../../library/doctest.rst:772
msgid "is vulnerable! One workaround is to do ::"
msgstr "是不可靠的!一个变通方法是用::"
#: ../../library/doctest.rst:777
msgid "instead. Another is to do ::"
msgstr "来取代。另一个是使用"
#: ../../library/doctest.rst:785
msgid ""
"Before Python 3.6, when printing a dict, Python did not guarantee that the "
"key-value pairs was printed in any particular order."
msgstr "在 Python 3.6 之前,当打印一个 dict 时,Python 并不保证键值对以任何特定的顺序被打印。"
#: ../../library/doctest.rst:788
msgid "There are others, but you get the idea."
msgstr "还有其他的问题,但你会明白的。"
#: ../../library/doctest.rst:790
msgid ""
"Another bad idea is to print things that embed an object address, like ::"
msgstr "另一个不好的做法是打印嵌入了对象地址的变量,如::"
#: ../../library/doctest.rst:798
msgid ""
"The :const:`ELLIPSIS` directive gives a nice approach for the last example::"
msgstr ":const:`ELLIPSIS` 指令为最后一个例子提供了一个不错的方法::"
#: ../../library/doctest.rst:803
msgid ""
"Floating-point numbers are also subject to small output variations across "
"platforms, because Python defers to the platform C library for float "
"formatting, and C libraries vary widely in quality here. ::"
msgstr "浮点数在不同的平台上也会有小的输出变化,因为Python在浮点数的格式化上依赖于平台的C库,而C库在这个问题上的质量差异很大。::"
#: ../../library/doctest.rst:814
msgid ""
"Numbers of the form ``I/2.**J`` are safe across all platforms, and I often "
"contrive doctest examples to produce numbers of that form::"
msgstr "形式 ``I/2.**J`` 的数字在所有的平台上都是安全的,我经常设计一些测试的用例来产生该形式的数::"
#: ../../library/doctest.rst:820
msgid ""
"Simple fractions are also easier for people to understand, and that makes "
"for better documentation."
msgstr "简单的分数也更容易让人理解,这也使得文件更加完善。"
#: ../../library/doctest.rst:827
msgid "Basic API"
msgstr "基本API"
#: ../../library/doctest.rst:829
msgid ""
"The functions :func:`testmod` and :func:`testfile` provide a simple "
"interface to doctest that should be sufficient for most basic uses. For a "
"less formal introduction to these two functions, see sections :ref:`doctest-"
"simple-testmod` and :ref:`doctest-simple-testfile`."
msgstr ""
"函数 :func:`testmod` 和 :func:`testfile` 为 doctest "
"提供了一个简单的接口,应该足以满足大多数基本用途。关于这两个函数的不太正式的介绍,请参见 :ref:`doctest-simple-testmod` 和"
" :ref:`doctest-simple-testfile` 部分。"
#: ../../library/doctest.rst:837
msgid ""
"All arguments except *filename* are optional, and should be specified in "
"keyword form."
msgstr "除了*filename*,所有的参数都是可选的,而且应该以关键字的形式指定。"
#: ../../library/doctest.rst:840
msgid ""
"Test examples in the file named *filename*. Return ``(failure_count, "
"test_count)``."
msgstr "测试名为 *filename* 的文件中的用例。 返回 ``(failure_count, test_count)``。"
#: ../../library/doctest.rst:843
msgid ""
"Optional argument *module_relative* specifies how the filename should be "
"interpreted:"
msgstr "可选参数 *module_relative* 指定了文件名的解释方式。"
#: ../../library/doctest.rst:846
msgid ""
"If *module_relative* is ``True`` (the default), then *filename* specifies an"
" OS-independent module-relative path. By default, this path is relative to "
"the calling module's directory; but if the *package* argument is specified, "
"then it is relative to that package. To ensure OS-independence, *filename* "
"should use ``/`` characters to separate path segments, and may not be an "
"absolute path (i.e., it may not begin with ``/``)."
msgstr ""
"如果 *module_relative* 是 ``True`` (默认),那么 *filename* 指定一个独立于操作系统的模块相对路径。 "
"默认情况下,这个路径是相对于调用模块的目录的;但是如果指定了 *package* 参数,那么它就是相对于该包的。 为了保证操作系统的独立性, "
"*filename* 应该使用字符来分隔路径段,并且不能是一个绝对路径 (即不能以 ``/`` 开始)。"
#: ../../library/doctest.rst:853
msgid ""
"If *module_relative* is ``False``, then *filename* specifies an OS-specific "
"path. The path may be absolute or relative; relative paths are resolved "
"with respect to the current working directory."
msgstr ""
"如果 *module_relative* 是 ``False``,那么 *filename* "
"指定了一个操作系统特定的路径。路径可以是绝对的,也可以是相对的;相对路径是相对于当前工作目录而言的。"
#: ../../library/doctest.rst:857
msgid ""
"Optional argument *name* gives the name of the test; by default, or if "
"``None``, ``os.path.basename(filename)`` is used."
msgstr ""
"可选参数 *name* 给出了测试的名称;默认情况下,或者如果是 ``None``,那么使用 "
"``os.path.basename(filename)``。"
#: ../../library/doctest.rst:860
msgid ""
"Optional argument *package* is a Python package or the name of a Python "
"package whose directory should be used as the base directory for a module-"
"relative filename. If no package is specified, then the calling module's "
"directory is used as the base directory for module-relative filenames. It "
"is an error to specify *package* if *module_relative* is ``False``."
msgstr ""
"可选参数 *package* 是一个 Python 包或一个 Python 包的名字,其目录应被用作模块相关文件名的基础目录。 "
"如果没有指定包,那么调用模块的目录将作为模块相关文件名的基础目录。如果 *module_relative* 是 ``False``,那么指定 "
"*package* 是错误的。"
#: ../../library/doctest.rst:866
msgid ""
"Optional argument *globs* gives a dict to be used as the globals when "
"executing examples. A new shallow copy of this dict is created for the "
"doctest, so its examples start with a clean slate. By default, or if "
"``None``, a new empty dict is used."
msgstr ""
"可选参数 *globs* 给出了一个在执行示例时用作全局变量的dict。 "
"这个dict的一个新的浅层副本将为doctest创建,因此它的用例将从一个干净的地方开始。默认情况下,或者如果为 "
"``None``,使用一个新的空dict。"
#: ../../library/doctest.rst:871
msgid ""
"Optional argument *extraglobs* gives a dict merged into the globals used to "
"execute examples. This works like :meth:`dict.update`: if *globs* and "
"*extraglobs* have a common key, the associated value in *extraglobs* appears"
" in the combined dict. By default, or if ``None``, no extra globals are "
"used. This is an advanced feature that allows parameterization of doctests."
" For example, a doctest can be written for a base class, using a generic "
"name for the class, then reused to test any number of subclasses by passing "
"an *extraglobs* dict mapping the generic name to the subclass to be tested."
msgstr ""
"可选参数 *extraglobs* 给出了一个合并到用于执行用例全局变量中的dict。 这就像 :meth:`dict.update` 一样:如果 "
"*globs* 和 *extraglobs* 有一个共同的键,那么 *extraglobs* 中的相关值会出现在合并的dict中。 默认情况下,或者为 "
"``None`` ,则不使用额外的全局变量。这是一个高级功能,允许对 doctest "
"进行参数化。例如,可以为一个基类写一个测试,使用该类的通用名称,然后通过传递一个 *extraglobs* "
"dict,将通用名称映射到要测试的子类,从而重复用于测试任何数量的子类。"
#: ../../library/doctest.rst:880
msgid ""
"Optional argument *verbose* prints lots of stuff if true, and prints only "
"failures if false; by default, or if ``None``, it's true if and only if "
"``'-v'`` is in ``sys.argv``."
msgstr ""