CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Thu, 17 Jul 2025 16:32:59 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20090205192822
location: https://web.archive.org/web/20090205192822/https://wiki.python.org/moin/doctest
server-timing: captures_list;dur=0.541879, exclusion.robots;dur=0.021303, exclusion.robots.policy;dur=0.010576, esindex;dur=0.011982, cdx.remote;dur=39.546175, LoadShardBlock;dur=251.986355, PetaboxLoader3.datanode;dur=111.103619, PetaboxLoader3.resolve;dur=87.300027
x-app-server: wwwb-app224
x-ts: 302
x-tr: 320
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app224; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Thu, 17 Jul 2025 16:33:00 GMT
content-type: text/html; charset=utf-8
x-archive-orig-date: Thu, 05 Feb 2009 19:28:22 GMT
x-archive-orig-server: Apache/2.2.9 (Debian) mod_fastcgi/2.4.6 mod_python/3.3.1 Python/2.5.2 mod_wsgi/2.3
x-archive-orig-vary: Cookie,User-Agent,Accept-Language
x-archive-orig-content-length: 14287
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Thu, 05 Feb 2009 19:28:22 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Mon, 11 Sep 2006 05:26:06 GMT", ; rel="prev memento"; datetime="Tue, 17 Jun 2008 15:18:41 GMT", ; rel="memento"; datetime="Thu, 05 Feb 2009 19:28:22 GMT", ; rel="next memento"; datetime="Fri, 03 Jun 2011 05:50:53 GMT", ; rel="last memento"; datetime="Fri, 18 Apr 2025 16:20:48 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_8_20090205180151_crawl101-c/52_8_20090205192641_crawl103.arc.gz
server-timing: captures_list;dur=0.556709, exclusion.robots;dur=0.023546, exclusion.robots.policy;dur=0.010749, esindex;dur=0.010053, cdx.remote;dur=38.305730, LoadShardBlock;dur=113.210602, PetaboxLoader3.datanode;dur=150.704000, load_resource;dur=196.099417, PetaboxLoader3.resolve;dur=95.769523
x-app-server: wwwb-app224
x-ts: 200
x-tr: 403
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
doctest - PythonInfo Wiki
r""" halt-at-nth-failure.py See here a concise way to harness doctest to HALT_AT_NTH_FAILURE, even though that's not yet a doc'ed option like REPORT_ONLY_FIRST_FAILURE. See also: https://docs.python.org/lib/module-doctest.html Sorry you'll have to work harder if you need to doctest code that uses more than the write method of sys.stdout. An example of an illuminating result: $ python ./halt-at-nth-failure.py 1 ********************************************************************** File "./halt-at-nth-failure.py", line 47, in __main__ Failed example: 0 + 1 Expected: 111 Got: 1 2 3 ********************************************************************** File "./halt-at-nth-failure.py", line 57, in __main__ Failed example: 2 + 1 Expected: 333 Got: 3 ********************************************************************** 1 item interrupted ***Test Failed*** $ appears when this source file contains such input as: >>> import sys >>> print 'Hello, doctest world.' Hello, doctest world. >>> >>> print >>sys.stderr, 1 >>> 0 + 1 111 >>> >>> print >>sys.stderr, 2 >>> 1 + 1 2 >>> >>> print >>sys.stderr, 3 >>> 2 + 1 333 >>> >>> print >>sys.stderr, 4 >>> 3 + 1 444 >>> """ import sys class DocTestExit(KeyboardInterrupt): """ Write out the bytes passed to self.write. Raise self after self.write called to write the trigger the nth time. Derive self from KeyboardInterrupt to exit doctest when raised. Count each call containing the trigger, not all exact matches. """ def __init__(self, out, nth = 1, trigger = '\nFailed example:\n' ): self.triggerings = nth # -1 == don't halt self.out = out self.trigger = trigger self.write = self.writeOut def writeOut(self, bytes): self.out.write(bytes) if 0 <= bytes.find(self.trigger): self.triggerings -= 1 if self.triggerings == 0: raise self if __name__ == '__main__': import doctest (failings, testings) = (1, None) try: sys.stdout = DocTestExit(sys.stdout, 2) (failings, testings) = doctest.testmod( optionflags = doctest.ELLIPSIS) except DocTestExit: print '*' * 70 print '1 item interrupted' print '***Test Failed***' finally: sys.stdout = sys.stdout.out
EditText (last edited 2008-11-15 14:00:37 by localhost)