CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Thu, 24 Jul 2025 22:15:52 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.591515, exclusion.robots;dur=0.022590, exclusion.robots.policy;dur=0.011507, esindex;dur=0.014320, cdx.remote;dur=21.271147, LoadShardBlock;dur=269.661874, PetaboxLoader3.datanode;dur=79.601372, PetaboxLoader3.resolve;dur=80.780711
x-app-server: wwwb-app214
x-ts: 302
x-tr: 317
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
set-cookie: SERVER=wwwb-app214; 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, 24 Jul 2025 22:15:53 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.865713, exclusion.robots;dur=0.035083, exclusion.robots.policy;dur=0.016240, esindex;dur=0.019850, cdx.remote;dur=157.778155, LoadShardBlock;dur=121.092178, PetaboxLoader3.datanode;dur=152.668016, load_resource;dur=320.065795, PetaboxLoader3.resolve;dur=235.997686
x-app-server: wwwb-app214
x-ts: 200
x-tr: 655
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