CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sat, 19 Jul 2025 07:30:19 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20071208112909
location: https://web.archive.org/web/20071208112909/https://wiki.python.org/moin/MultiLineStringsInDocTest
server-timing: captures_list;dur=0.825981, exclusion.robots;dur=0.022646, exclusion.robots.policy;dur=0.010874, esindex;dur=0.009656, cdx.remote;dur=10.539308, LoadShardBlock;dur=152.667774, PetaboxLoader3.datanode;dur=48.790215, PetaboxLoader3.resolve;dur=67.231812
x-app-server: wwwb-app210
x-ts: 302
x-tr: 194
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app210; 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: Sat, 19 Jul 2025 07:30:20 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Sat, 08 Dec 2007 11:29:08 GMT
x-archive-orig-server: Apache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 08 Dec 2007 11:29:09 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sun, 14 May 2006 07:15:11 GMT", ; rel="prev memento"; datetime="Thu, 20 Sep 2007 01:37:11 GMT", ; rel="memento"; datetime="Sat, 08 Dec 2007 11:29:09 GMT", ; rel="next memento"; datetime="Fri, 12 Aug 2011 00:12:28 GMT", ; rel="last memento"; datetime="Thu, 07 Jul 2022 06:25:29 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_1_20071208104348_crawl102-c/52_1_20071208112235_crawl107.arc.gz
server-timing: captures_list;dur=0.433082, exclusion.robots;dur=0.019135, exclusion.robots.policy;dur=0.009758, esindex;dur=0.010964, cdx.remote;dur=7.191373, LoadShardBlock;dur=197.404291, PetaboxLoader3.resolve;dur=186.182519, PetaboxLoader3.datanode;dur=108.630035, load_resource;dur=138.882088
x-app-server: wwwb-app210
x-ts: 200
x-tr: 399
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
MultiLineStringsInDocTest - PythonInfo Wiki
MultiLineStringsInDocTest
The DocTest module requires special actions / processing for multi-line strings.
Multi-Line Strings in commands
Consider a function get_html_title designed to extract the title from an HTML page. Here is some python code to test the function:
1 >>> html = '''
2 <html>
3 <head>
4 <title>This is the page title</title>
5 </head>
6 <body>
7 This is the body
8 </body>
9 </html>
10 '''
11 >>> title = get_html_title(html)
12 >>> assert(title == "This is the page title")
Putting this directly into a doctest results in an exception, such as:
Failed example: html = ''' Exception raised: Traceback (most recent call last): File "C:\Python24\lib\doctest.py", line 1243, in __run compileflags, 1) in test.globs File "<doctest sample.tests[1]>", line 1 html = ''' ^ SyntaxError: EOF while scanning triple-quoted string
The solution is to add the command continuation characters:
1 >>> html = '''
2 ... <html>
3 ... <head>
4 ... <title>This is the page title</title>
5 ... </head>
6 ... <body>
7 ... This is the body
8 ... </body>
9 ... </html>
10 ... '''
11 >>> title = get_html_title(html)
12 >>> assert(title == "This is the page title")
Multi-Line Strings in output
Blank lines in the output need to be specially handled. For example, the following doctest will fail:
1 >>> test = "Here is a blank line\n\nBlank line is above"
2 >>> print test
3 Here is a blank line
4
5 Blank line is above
This is because the blank line is used to seperate commands and comments. With Python 2.4, a <BLANKLINE> keyword was added, so the proper doctest is now:
1 >>> test = "Here is a blank line\n\nBlank line is above"
2 >>> print test
3 Here is a blank line
4 <BLANKLINE>
5 Blank line is above
EditText (last edited 2005-12-20 19:21:51 by 192)
DeleteCache (cached 2007-11-18 03:45:37)- Login
- Navigation
- Actions
- Your recent pages