GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python-docs-ja/library/doctest.po at 3.12 · python/python-docs-ja Expand file tree/ Copy pathdoctest.poMore file actions 3386 lines (3009 loc) · 154 KB / Copy pathdoctest.poFile metadata and controls3386 lines (3009 loc) · 154 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 Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # # Translators: # tomo, 2021 # Yusuke Miyazaki <[email protected]>, 2021 # Takanori Suzuki <[email protected]>, 2023 # Arihiro TAKASE, 2023 # Osamu NAKAMURA, 2023 # TENMYO Masakazu, 2023 # Takeshi Nakazato, 2024 # 石井明久, 2024 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2025-05-08 02:53-0300\n" "PO-Revision-Date: 2021-06-28 01:04+0000\n" "Last-Translator: 石井明久, 2024\n" "Language-Team: Japanese (https://app.transifex.com/python-doc/teams/5390/" "ja/)\n" "Language: ja\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\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 セッションのように見えるテキストを" "探し出し、セッションの内容を実行して、そこに書かれている通りに振舞うかを調べ" "ます。 :mod:`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 "" "モジュールの docstring (ドキュメンテーション文字列) 中にある対話実行例のすべ" "てが書かれている通りに動作するか検証することで、docstring の内容が最新かどう" "かチェックする。" #: ../../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:33 msgid "" "\"\"\"\n" "This is the \"example\" module.\n" "\n" "The example module supplies one function, factorial(). For example,\n" "\n" ">>> factorial(5)\n" "120\n" "\"\"\"\n" "\n" "def factorial(n):\n" " \"\"\"Return the factorial of n, an exact integer >= 0.\n" "\n" " >>> [factorial(n) for n in range(6)]\n" " [1, 1, 2, 6, 24, 120]\n" " >>> factorial(30)\n" " 265252859812191058636308480000000\n" " >>> factorial(-1)\n" " Traceback (most recent call last):\n" " ...\n" " ValueError: n must be >= 0\n" "\n" " Factorials of floats are OK, but the float must be an exact integer:\n" " >>> factorial(30.1)\n" " Traceback (most recent call last):\n" " ...\n" " ValueError: n must be exact integer\n" " >>> factorial(30.0)\n" " 265252859812191058636308480000000\n" "\n" " It must also not be ridiculously large:\n" " >>> factorial(1e100)\n" " Traceback (most recent call last):\n" " ...\n" " OverflowError: n too large\n" " \"\"\"\n" "\n" " import math\n" " if not n >= 0:\n" " raise ValueError(\"n must be >= 0\")\n" " if math.floor(n) != n:\n" " raise ValueError(\"n must be exact integer\")\n" " if n+1 == n: # catch a value like 1e300\n" " raise OverflowError(\"n too large\")\n" " result = 1\n" " factor = 2\n" " while factor <= n:\n" " result *= factor\n" " factor += 1\n" " return result\n" "\n" "\n" "if __name__ == \"__main__\":\n" " import doctest\n" " doctest.testmod()" 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:91 msgid "" "$ python example.py\n" "$" msgstr "" "$ python example.py\n" "$" #: ../../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:100 msgid "" "$ python example.py -v\n" "Trying:\n" " factorial(5)\n" "Expecting:\n" " 120\n" "ok\n" "Trying:\n" " [factorial(n) for n in range(6)]\n" "Expecting:\n" " [1, 1, 2, 6, 24, 120]\n" "ok" msgstr "" #: ../../library/doctest.rst:114 msgid "And so on, eventually ending with:" msgstr "といった具合で、最後には:" #: ../../library/doctest.rst:116 msgid "" "Trying:\n" " factorial(1e100)\n" "Expecting:\n" " Traceback (most recent call last):\n" " ...\n" " OverflowError: n too large\n" "ok\n" "2 items passed all tests:\n" " 1 test in __main__\n" " 6 tests in __main__.factorial\n" "7 tests in 2 items.\n" "7 passed.\n" "Test passed.\n" "$" 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/test_doctest.py`." msgstr "" #: ../../library/doctest.rst:139 msgid "" "Output is colorized by default and can be :ref:`controlled using environment " "variables <using-on-controlling-color>`." msgstr "" #: ../../library/doctest.rst:147 msgid "Simple Usage: Checking Examples in Docstrings" msgstr "簡単な利用法: docstring 中の実行例をチェックする" #: ../../library/doctest.rst:149 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 "" "if __name__ == \"__main__\":\n" " import doctest\n" " doctest.testmod()" msgstr "" #: ../../library/doctest.rst:156 msgid ":mod:`!doctest` then examines docstrings in module :mod:`!M`." msgstr "" "こうすると、 :mod:`!doctest` は :mod:`!M` 中の docstring を検査します。" #: ../../library/doctest.rst:158 msgid "" "Running the module as a script causes the examples in the docstrings to get " "executed and verified::" msgstr "" "モジュールをスクリプトとして実行すると、docstring 中の実行例が実行され、検証" "されます::" #: ../../library/doctest.rst:161 msgid "python M.py" msgstr "python M.py" #: ../../library/doctest.rst:163 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 "" "docstring に書かれた実行例の実行が失敗しない限り、何も表示されません。失敗す" "ると、失敗した実行例と、その原因が (場合によっては複数) 標準出力に印字され、" "最後に ``***Test Failed*** N failures.`` という行を出力します。ここで、*N* は" "失敗した実行例の数です。" #: ../../library/doctest.rst:168 msgid "Run it with the ``-v`` switch instead::" msgstr "一方、``-v`` スイッチをつけて走らせると::" #: ../../library/doctest.rst:170 msgid "python M.py -v" msgstr "python M.py -v" #: ../../library/doctest.rst:172 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:175 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 "" "``verbose=True`` を :func:`testmod` に渡せば、詳細報告 (verbose) モードを強制" "できます。また、 ``verbose=False`` にすれば禁止できます。どちらの場合にも、 :" "func:`testmod` は ``sys.argv`` 上のスイッチを調べません。(したがって、 ``-" "v`` をつけても効果はありません)。" #: ../../library/doctest.rst:180 msgid "" "There is also a command line shortcut for running :func:`testmod`, see " "section :ref:`doctest-cli`." msgstr "" #: ../../library/doctest.rst:183 msgid "" "For more information on :func:`testmod`, see section :ref:`doctest-basic-" "api`." msgstr "" ":func:`testmod` の詳しい情報は :ref:`doctest-basic-api` 節を参照してくださ" "い。" #: ../../library/doctest.rst:189 msgid "Simple Usage: Checking Examples in a Text File" msgstr "簡単な利用法: テキストファイル中の実行例をチェックする" #: ../../library/doctest.rst:191 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:194 msgid "" "import doctest\n" "doctest.testfile(\"example.txt\")" msgstr "" "import doctest\n" "doctest.testfile(\"example.txt\")" #: ../../library/doctest.rst:197 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 操作例すべてを実行して、その内容を検証します。ファイルの内容" "は一つの巨大な docstring であるかのように扱われます; ファイルが Python プログ" "ラムである必要はありません!例えば、 :file:`example.txt` には以下のような内容" "が入っているとします:" #: ../../library/doctest.rst:202 msgid "" "The ``example`` module\n" "======================\n" "\n" "Using ``factorial``\n" "-------------------\n" "\n" "This is an example text file in reStructuredText format. First import\n" "``factorial`` from the ``example`` module:\n" "\n" " >>> from example import factorial\n" "\n" "Now use it:\n" "\n" " >>> factorial(6)\n" " 120" msgstr "" #: ../../library/doctest.rst:220 msgid "" "Running ``doctest.testfile(\"example.txt\")`` then finds the error in this " "documentation::" msgstr "" "``doctest.testfile(\"example.txt\")`` を実行すると、このドキュメント内のエ" "ラーを見つけ出します::" #: ../../library/doctest.rst:223 msgid "" "File \"./example.txt\", line 14, in example.txt\n" "Failed example:\n" " factorial(6)\n" "Expected:\n" " 120\n" "Got:\n" " 720" msgstr "" #: ../../library/doctest.rst:231 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` は実行例が失敗しない限り何も表示" "しません。実行例が失敗すると、失敗した実行例とその原因が (場合によっては複" "数) :func:`testmod` と同じ書式で標準出力に書き出されます。" #: ../../library/doctest.rst:236 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` は自分自身を呼び出したモジュールのあるディ" "レクトリを探します。その他の場所にあるファイルを見に行くように :func:" "`testfile` に指示するためのオプション引数についての説明は :ref:`doctest-" "basic-api` 節を参照してください。" #: ../../library/doctest.rst:240 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` の冗長性 (verbosity) はコマンドライ" "ンスイッチ ``-v`` またはオプションのキーワード引数 *verbose* によって指定でき" "ます。" #: ../../library/doctest.rst:244 msgid "" "There is also a command line shortcut for running :func:`testfile`, see " "section :ref:`doctest-cli`." msgstr "" #: ../../library/doctest.rst:247 msgid "" "For more information on :func:`testfile`, see section :ref:`doctest-basic-" "api`." msgstr "" ":func:`testfile` の詳細は :ref:`doctest-basic-api` 節を参照してください。" #: ../../library/doctest.rst:253 msgid "Command-line Usage" msgstr "コマンドラインでの使用" #: ../../library/doctest.rst:255 msgid "" "The :mod:`doctest` module can be invoked as a script from the command line:" msgstr "" #: ../../library/doctest.rst:257 msgid "python -m doctest [-v] [-o OPTION] [-f] file [file ...]" msgstr "python -m doctest [-v] [-o OPTION] [-f] file [file ...]" #: ../../library/doctest.rst:265 msgid "" "Detailed report of all examples tried is printed to standard output, along " "with assorted summaries at the end::" msgstr "" #: ../../library/doctest.rst:268 msgid "python -m doctest -v example.py" msgstr "python -m doctest -v example.py" #: ../../library/doctest.rst:270 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:274 msgid "" "If the file name does not end with :file:`.py`, :mod:`!doctest` infers that " "it must be run with :func:`testfile` instead::" msgstr "" #: ../../library/doctest.rst:277 msgid "python -m doctest -v example.txt" msgstr "python -m doctest -v example.txt" #: ../../library/doctest.rst:281 msgid "" "Option flags control various aspects of doctest's behavior, see section :ref:" "`doctest-options`." msgstr "" #: ../../library/doctest.rst:288 msgid "This is shorthand for ``-o FAIL_FAST``." msgstr "" #: ../../library/doctest.rst:296 msgid "How It Works" msgstr "doctest のからくり" #: ../../library/doctest.rst:298 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 のからくり: どの docstring を見に行くのか、どのように対話" "実行例を見つけ出すのか、どんな実行コンテキストを使うのか、例外をどう扱うか、" "上記の振る舞いを制御するためにどのようなオプションフラグを使うか、について詳" "しく吟味します。こうした情報は、doctest に対応した実行例を書くために必要な知" "識です; 書いた実行例に対して実際に doctest を実行する上で必要な情報については" "後続の節を参照してください。" #: ../../library/doctest.rst:309 msgid "Which Docstrings Are Examined?" msgstr "どの docstring が検証されるのか?" #: ../../library/doctest.rst:311 msgid "" "The module docstring, and all function, class and method docstrings are " "searched. Objects imported into the module are not searched." msgstr "" "モジュールの docstring と、すべての関数、クラスおよびメソッドの docstring が" "検索されます。モジュールに import されたオブジェクトは検索されません。" #: ../../library/doctest.rst:314 msgid "" "In addition, there are cases when you want tests to be part of a module but " "not part of the help text, which requires that the tests not be included in " "the docstring. Doctest looks for a module-level variable called ``__test__`` " "and uses it to locate other tests. If ``M.__test__`` exists, 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 ``M." "__test__.K``." msgstr "" #: ../../library/doctest.rst:323 msgid "For example, place this block of code at the top of :file:`example.py`:" msgstr "" #: ../../library/doctest.rst:325 msgid "" "__test__ = {\n" " 'numbers': \"\"\"\n" ">>> factorial(6)\n" "720\n" "\n" ">>> [factorial(n) for n in range(6)]\n" "[1, 1, 2, 6, 24, 120]\n" "\"\"\"\n" "}" msgstr "" #: ../../library/doctest.rst:337 msgid "" "The value of ``example.__test__[\"numbers\"]`` will be treated as a " "docstring and all the tests inside it will be run. It is important to note " "that the value can be mapped to a function, class object, or module; if so, :" "mod:`!doctest` searches them recursively for docstrings, which are then " "scanned for tests." msgstr "" #: ../../library/doctest.rst:343 msgid "" "Any classes found are recursively searched similarly, to test docstrings in " "their contained methods and nested classes." msgstr "" "検索中に見つかったクラスも同様に再帰的に検索が行われ、クラスに含まれているメ" "ソッドおよびネストされたクラスについて docstring のテストが行われます。" #: ../../library/doctest.rst:350 msgid "How are Docstring Examples Recognized?" msgstr "docstring 内の実行例をどのように認識するのか?" #: ../../library/doctest.rst:352 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 "" "ほとんどの場合、対話コンソールセッション上でのコピー/ペーストはうまく動作し" "ます。とはいえ、:mod:`doctest` は特定の Python シェルの振る舞いを正確にエミュ" "レーションしようとするわけではありません。" #: ../../library/doctest.rst:357 msgid "" ">>> # comments are ignored\n" ">>> x = 12\n" ">>> x\n" "12\n" ">>> if x == 13:\n" "... print(\"yes\")\n" "... else:\n" "... print(\"no\")\n" "... print(\"NO\")\n" "... print(\"NO!!!\")\n" "...\n" "no\n" "NO\n" "NO!!!\n" ">>>" msgstr "" #: ../../library/doctest.rst:377 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:381 msgid "The fine print:" msgstr "詳細事項:" #: ../../library/doctest.rst:383 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:388 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 カラムのタブ位置でスペースに展開されます。テスト対象のコー" "ドが作成した出力にあるタブは変更されません。出力例にあるどんなタブも展開 *さ" "れる* ので、コードの出力がハードタブを含んでいた場合、 doctest が通るには :" "const:`NORMALIZE_WHITESPACE` オプションか :ref:`directive <doctest-" "directives>` を有効にするしかありません。そうする代わりに、テストが出力を読み" "取りテストの一部として期待される値と正しく比較するように、テストを書き直すこ" "ともできます。このソース中のタブの扱いは試行錯誤の結果であり、タブの扱いの中" "で最も問題の起きにくいものだということが分かっています。タブの扱いについて" "は、独自の :class:`DocTestParser` クラスを実装して、別のアルゴリズムを使うこ" "ともできます。" #: ../../library/doctest.rst:400 msgid "" "Output to stdout is captured, but not output to stderr (exception tracebacks " "are captured via a different means)." msgstr "" "標準出力への出力は取り込まれますが、標準エラーは取り込まれません (例外発生時" "のトレースバックは別の方法で取り込まれます)。" #: ../../library/doctest.rst:403 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 "" "対話セッションにおいて、バックスラッシュを用いて次の行に続ける場合や、その他" "の理由でバックスラッシュを用いる場合、raw docstring を使ってバックスラッシュ" "を入力どおりに扱わせるようにしなければなりません::" #: ../../library/doctest.rst:407 msgid "" ">>> def f(x):\n" "... r'''Backslashes in a raw docstring: m\\n'''\n" "...\n" ">>> print(f.__doc__)\n" "Backslashes in a raw docstring: m\\n" msgstr "" #: ../../library/doctest.rst:413 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 にあるバックスラッシュを二重にする (そして raw string を使わない) と" "いう方法もあります::" #: ../../library/doctest.rst:417 msgid "" ">>> def f(x):\n" "... '''Backslashes in a raw docstring: m\\\\n'''\n" "...\n" ">>> print(f.__doc__)\n" "Backslashes in a raw docstring: m\\n" msgstr "" #: ../../library/doctest.rst:423 msgid "The starting column doesn't matter::" msgstr "開始カラムはどこでもかまいません::" #: ../../library/doctest.rst:425 msgid "" ">>> assert \"Easy!\"\n" " >>> import math\n" " >>> math.floor(1.9)\n" " 1" msgstr "" #: ../../library/doctest.rst:430 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:437 msgid "What's the Execution Context?" msgstr "実行コンテキストとは何か?" #: ../../library/doctest.rst:439 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` はテストを行うべき docstring を見つけるたび" "に :mod:`!M` のグローバル名前空間の *浅いコピー* を使い、テストの実行によって" "モジュールの実際のグローバル名前空間を変更しないようにし、かつ :mod:`!M` 内で" "行ったテストが痕跡を残して偶発的に別のテストを誤って動作させないようにしてい" "ます。したがって、実行例中では :mod:`!M` 内のトップレベルで定義されたすべての" "名前と、 docstring が動作する以前に定義された名前を自由に使えます。個々の実行" "例は他の docstring 中で定義された名前を参照できません。" #: ../../library/doctest.rst:447 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 "" ":func:`testmod` や :func:`testfile` に ``globs=your_dict`` を渡し、自前の辞書" "を実行コンテキストとして使うこともできます。" #: ../../library/doctest.rst:454 msgid "What About Exceptions?" msgstr "例外はどう扱えばよいか?" #: ../../library/doctest.rst:456 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:462 msgid "Simple example::" msgstr "簡単な例を示しましょう::" #: ../../library/doctest.rst:464 msgid "" ">>> [1, 2, 3].remove(42)\n" "Traceback (most recent call last):\n" " File \"<stdin>\", line 1, in <module>\n" "ValueError: list.remove(x): x not in list" msgstr "" #: ../../library/doctest.rst:469 msgid "" "That doctest succeeds if :exc:`ValueError` is raised, with the ``list." "remove(x): x not in list`` detail as shown." msgstr "" "この doctest は、 :exc:`ValueError` が送出され、その詳細情報が ``list." "remove(x): x not in list`` である場合に成功します。" #: ../../library/doctest.rst:472 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:476 msgid "" "Traceback (most recent call last):\n" "Traceback (innermost last):" msgstr "" #: ../../library/doctest.rst:479 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:483 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:488 msgid "" ">>> raise ValueError('multi\\n line\\ndetail')\n" "Traceback (most recent call last):\n" " File \"<stdin>\", line 1, in <module>\n" "ValueError: multi\n" " line\n" "detail" msgstr "" #: ../../library/doctest.rst:495 msgid "" "The last three lines (starting with :exc:`ValueError`) are compared against " "the exception's type and detail, and the rest are ignored." msgstr "" "上の例では、最後の 3 行 (:exc:`ValueError` から始まる行) における例外の型と詳" "細情報だけが比較され、それ以外の部分は無視されます。" #: ../../library/doctest.rst:498 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:501 msgid "" ">>> raise ValueError('multi\\n line\\ndetail')\n" "Traceback (most recent call last):\n" " ...\n" "ValueError: multi\n" " line\n" "detail" msgstr "" #: ../../library/doctest.rst:508 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` オプションとは独立" "しています。この例での省略記号は何かの省略を表しているかもしれませんし、コン" "マや数字が 3 個 (または 300 個) かもしれませんし、 Monty Python のスキットを" "インデントして書き写したものかもしれません。" #: ../../library/doctest.rst:514 msgid "Some details you should read once, but won't need to remember:" msgstr "" "以下の詳細はずっと覚えておく必要はないのですが、一度目を通しておいてください:" #: ../../library/doctest.rst:516 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 は期待する出力の出所が print 文なのか例外なのかを推測できません。した" "がって、例えば期待する出力が ``ValueError: 42 is prime`` であるような実行例" "は、 :exc:`ValueError` が実際に送出された場合と、万が一期待する出力と同じ文字" "列を print した場合の両方で成功してしまいます。現実的には、通常の出力がトレー" "スバックヘッダから始まることはないので、実際に問題になることはないでしょう。" #: ../../library/doctest.rst:523 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:529 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 "" "doctest のオプション :const:`IGNORE_EXCEPTION_DETAIL` を指定した場合、最も左" "端のコロン以後の全ての内容と、例外名の中の全てのモジュール情報が無視されま" "す。" #: ../../library/doctest.rst:533 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 "" "対話シェルでは、 :exc:`SyntaxError` の場合にトレースバックヘッダが省略される" "ことがあります。しかし doctest にとっては、例外を例外でないものと区別するため" "にトレースバックヘッダが必要です。そこで、トレースバックヘッダを省略するよう" "な :exc:`SyntaxError` をテストする必要があるというごく稀なケースでは、実行例" "にトレースバックヘッダを手作業で追加する必要があるでしょう。" #: ../../library/doctest.rst:541 msgid "" "For some exceptions, Python displays the position of the error using ``^`` " "markers and tildes::" msgstr "" #: ../../library/doctest.rst:544 msgid "" ">>> 1 + None\n" " File \"<stdin>\", line 1\n" " 1 + None\n" " ~~^~~~~~\n" "TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'" msgstr "" #: ../../library/doctest.rst:550 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:554 msgid "" ">>> 1 + None\n" " File \"<stdin>\", line 1\n" " 1 + None\n" " ^~~~~~~~\n" "TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'" msgstr "" #: ../../library/doctest.rst:565 msgid "Option Flags" msgstr "オプションフラグ" #: ../../library/doctest.rst:567 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>` でつないで様々な関数に渡すことができます。シンボル名は :" "ref:`doctest directives <doctest-directives>` でも使用でき、doctest コマンド" "ラインインターフェースに ``-o`` を通して与えることができます。" #: ../../library/doctest.rst:573 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:579 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` を指定すると、こうした値の読み替えを行いません。デ" |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |