<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 16.1.?概覽 在 [第?13?章 _單元測試_](../unit_testing/index.html "第?13?章?單元測試") 中,你學會了單元測試的哲學。在 [第?14?章 _測試優先編程_](../unit_testing/stage_1.html "第?14?章?測試優先編程") 中你步入了 Python 基本的單元測試操作,在 [第?15?章 _重構_](../refactoring/index.html "第?15?章?重構") 部分,你看到單元測試如何令大規模重構變得容易。本章將在這些程序樣例的基礎上,集中關注于超越單元測試本身的更高級的 Python 特有技術。 下面是一個作為簡單回歸測試 (regression test) 框架運行的完整 Python 程序。它將你前面編寫的單獨單元測試模塊組織在一起成為一個測試套件并一次性運行。實際上這是本書的構建代碼的一部分;我為幾個樣例程序都編寫了單元測試 (不是只有 [第?13?章 _單元測試_](../unit_testing/index.html "第?13?章?單元測試") 中的 `roman.py` 模塊),我的自動構建代碼的第一個工作便是確保我所有的例子可以正常工作。如果回歸測試程序失敗,構建過程當即終止。我可不想因為發布了不能工作的樣例程序而讓你在下載他們后坐在顯示器前抓耳撓腮地為程序不能運轉而煩惱。 ## 例?16.1.?`regression.py` 如果您還沒有下載本書附帶的樣例程序, 可以 [下載本程序和其他樣例程序](http://www.woodpecker.org.cn/diveintopython/download/diveintopython-exampleszh-cn-5.4b.zip "Download example scripts")。 ``` """Regression testing framework This module will search for scripts in the same directory named XYZtest.py. Each such script should be a test suite that tests a module through PyUnit. (As of Python 2.1, PyUnit is included in the standard library as "unittest".) This script will aggregate all found test suites into one big test suite and run them all at once. """ import sys, os, re, unittest def regressionTest(): path = os.path.abspath(os.path.dirname(sys.argv[0])) files = os.listdir(path) test = re.compile("test\.py$", re.IGNORECASE) files = filter(test.search, files) filenameToModuleName = lambda f: os.path.splitext(f)[0] moduleNames = map(filenameToModuleName, files) modules = map(__import__, moduleNames) load = unittest.defaultTestLoader.loadTestsFromModule return unittest.TestSuite(map(load, modules)) if __name__ == "__main__": unittest.main(defaultTest="regressionTest") ``` 把這段代碼放在本書其他樣例代碼相同的目錄下運行之,`_`module`_test.py` 中的所有單元測試將被找到并一起被運行。 ## 例?16.2.?`regression.py` 的樣例輸出 ``` [you@localhost py]$ python regression.py -v help should fail with no object ... ok help should return known result for apihelper ... ok help should honor collapse argument ... ok help should honor spacing argument ... ok buildConnectionString should fail with list input ... ok buildConnectionString should fail with string input ... ok buildConnectionString should fail with tuple input ... ok buildConnectionString handles empty dictionary ... ok buildConnectionString returns known result with known input ... ok fromRoman should only accept uppercase input ... ok toRoman should always return uppercase ... ok fromRoman should fail with blank string ... ok fromRoman should fail with malformed antecedents ... ok fromRoman should fail with repeated pairs of numerals ... ok fromRoman should fail with too many repeated numerals ... ok fromRoman should give known result with known input ... ok toRoman should give known result with known input ... ok fromRoman(toRoman(n))==n for all n ... ok toRoman should fail with non-integer input ... ok toRoman should fail with negative input ... ok toRoman should fail with large input ... ok toRoman should fail with 0 input ... ok kgp a ref test ... ok kgp b ref test ... ok kgp c ref test ... ok kgp d ref test ... ok kgp e ref test ... ok kgp f ref test ... ok kgp g ref test ... ok ---------------------------------------------------------------------- Ran 29 tests in 2.799s OK ``` | | | | --- | --- | | \[1\] | 前五個測試來自于 `apihelpertest.py`,用以測試 [第?4?章 _自省的威力_](../power_of_introspection/index.html "第?4?章?自省的威力") 中的樣例代碼。 | | \[2\] | 接下來的五個測試來自于 `odbchelpertest.py`,用以測試 [第?2?章 _第一個 Python 程序_](../getting_to_know_python/index.html "第?2?章?第一個 Python 程序") 中的樣例代碼。 | | \[3\] | 其他的測試來自于 `romantest.py`,你在 [第?13?章 _單元測試_](../unit_testing/index.html "第?13?章?單元測試") 中深入學習過。 |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看