[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

“.bad” filename extension in Outputs (saving this normally in the Outputs subdirectory
would trigger a failure when the test is later fixed!). Here’s a first run:


C:\...\PP4E\System\Tester> python tester.py. 1
Start tester: Mon Feb 22 22:13:38 2010
in C:\Users\mark\Stuff\Books\4E\PP4E\dev\Examples\PP4E\System\Tester
generating: .\Outputs\test-basic-args.out
generating: .\Outputs\test-basic-stdout.out
generating: .\Outputs\test-basic-streams.out
generating: .\Outputs\test-basic-this.out
ERROR status: test-errors-runtime.py 1
ERROR stream: test-errors-runtime.py .\Errors\test-errors-runtime.err
ERROR status: test-errors-syntax.py 1
ERROR stream: test-errors-syntax.py .\Errors\test-errors-syntax.err
ERROR status: test-status-bad.py 42
generating: .\Outputs\test-status-good.out
Finished: Mon Feb 22 22:13:41 2010
8 tests were run, 3 tests failed.

To run each script, the tester configures any preset command-line arguments provided,
pipes in fetched canned input (if any), and captures the script’s standard output and
error streams, along with its exit status code. When I ran this example, there were 8
test scripts, along with a variety of inputs and outputs. Since the directory and file
naming structures are the key to this example, here is a listing of the test directory I
used—the Scripts directory is primary, because that’s where tests to be run are
collected:


C:\...\PP4E\System\Tester> dir /B
Args
Errors
Inputs
Outputs
Scripts
tester.py
xxold

C:\...\PP4E\System\Tester> dir /B Scripts
test-basic-args.py
test-basic-stdout.py
test-basic-streams.py
test-basic-this.py
test-errors-runtime.py
test-errors-syntax.py
test-status-bad.py
test-status-good.py

The other subdirectories contain any required inputs and any generated outputs asso-
ciated with scripts to be tested:


C:\...\PP4E\System\Tester> dir /B Args
test-basic-args.args
test-status-good.args

300 | Chapter 6: Complete System Programs

Free download pdf