Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58b6f5b

Browse files
committed
Since this module already uses doctest-style examples, I figured I'd
add a self-test using doctest. Results: - The docstring needs to be a raw string because it uses \"...\". - The oreo example was broken: the Set-Cookie output doesn't add quotes around "doublestuff". - I had to change the example that prints the class of a Cookie.Cookie instance to avoid incorporating an arbitrary object address in the test output. Pretty good score for both doctest and the doc string, I'd say!
1 parent f95423e commit 58b6f5b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/Cookie.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#
4040
####
4141

42-
"""
42+
r"""
4343
Here's a sample session to show how to use this module.
4444
At the moment, this is the only documentation.
4545
@@ -113,7 +113,7 @@
113113
>>> C["oreo"] = "doublestuff"
114114
>>> C["oreo"]["path"] = "/"
115115
>>> print C
116-
Set-Cookie: oreo="doublestuff"; Path=/;
116+
Set-Cookie: oreo=doublestuff; Path=/;
117117
118118
Each dictionary element has a 'value' attribute, which gives you
119119
back the value associated with the key.
@@ -203,8 +203,8 @@
203203
fact, this simply returns a SmartCookie.
204204
205205
>>> C = Cookie.Cookie()
206-
>>> C.__class__
207-
<class Cookie.SmartCookie at 99f88>
206+
>>> print C.__class__.__name__
207+
SmartCookie
208208
209209
210210
Finis.
@@ -721,6 +721,12 @@ def value_encode(self, val):
721721
#
722722
###########################################################
723723

724+
def _test():
725+
import doctest, Cookie
726+
return doctest.testmod(Cookie)
727+
728+
if __name__ == "__main__":
729+
_test()
724730

725731

726732
#Local Variables:

0 commit comments

Comments
 (0)