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

(yzsuai) #1

And here are two files related to one of the detected errors—the first is its captured
stderr, and the second is its stdout generated up to the point where the error occurred;
these are for human (or other tools) inspection, and are automatically removed the next
time the tester script runs:


C:\...\PP4E\System\Tester> type Errors\test-errors-runtime.err
Traceback (most recent call last):
File ".\Scripts\test-errors-runtime.py", line 3, in <module>
print(1 / 0)
ZeroDivisionError: int division or modulo by zero

C:\...\PP4E\System\Tester> type Outputs\test-errors-runtime.out.bad
starting

Now, when run again without making any changes to the tests, the test driver script
compares saved prior outputs to new ones and detects no regressions; failures desig-
nated by exit status and stderr messages are still reported as before, but there are no
deviations from other tests’ saved expected output:


C:\...\PP4E\System\Tester> python tester.py
Start tester: Mon Feb 22 22:26:41 2010
in C:\Users\mark\Stuff\Books\4E\PP4E\dev\Examples\PP4E\System\Tester
passed: test-basic-args.py
passed: test-basic-stdout.py
passed: test-basic-streams.py
passed: test-basic-this.py
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
passed: test-status-good.py
Finished: Mon Feb 22 22:26:43 2010
8 tests were run, 3 tests failed.

But when I make a change in one of the test scripts that will produce different output
(I changed a loop counter to print fewer lines), the regression is caught and reported;
the new and different output of the script is reported as a failure, and saved in
Outputs as a “.bad” for later viewing:


C:\...\PP4E\System\Tester> python tester.py
Start tester: Mon Feb 22 22:28:35 2010
in C:\Users\mark\Stuff\Books\4E\PP4E\dev\Examples\PP4E\System\Tester
passed: test-basic-args.py
FAILED output: test-basic-stdout.py .\Outputs\test-basic-stdout.out.bad
passed: test-basic-streams.py
passed: test-basic-this.py
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
passed: test-status-good.py
Finished: Mon Feb 22 22:28:38 2010

302 | Chapter 6: Complete System Programs

Free download pdf