mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	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!
This commit is contained in:
		
							parent
							
								
									f95423e265
								
							
						
					
					
						commit
						58b6f5b53e
					
				
					 1 changed files with 10 additions and 4 deletions
				
			
		| 
						 | 
					@ -39,7 +39,7 @@
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
####
 | 
					####
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					r"""
 | 
				
			||||||
Here's a sample session to show how to use this module.
 | 
					Here's a sample session to show how to use this module.
 | 
				
			||||||
At the moment, this is the only documentation.
 | 
					At the moment, this is the only documentation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,7 +113,7 @@
 | 
				
			||||||
   >>> C["oreo"] = "doublestuff"
 | 
					   >>> C["oreo"] = "doublestuff"
 | 
				
			||||||
   >>> C["oreo"]["path"] = "/"
 | 
					   >>> C["oreo"]["path"] = "/"
 | 
				
			||||||
   >>> print C
 | 
					   >>> print C
 | 
				
			||||||
   Set-Cookie: oreo="doublestuff"; Path=/;
 | 
					   Set-Cookie: oreo=doublestuff; Path=/;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Each dictionary element has a 'value' attribute, which gives you
 | 
					Each dictionary element has a 'value' attribute, which gives you
 | 
				
			||||||
back the value associated with the key.
 | 
					back the value associated with the key.
 | 
				
			||||||
| 
						 | 
					@ -203,8 +203,8 @@
 | 
				
			||||||
fact, this simply returns a SmartCookie.
 | 
					fact, this simply returns a SmartCookie.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   >>> C = Cookie.Cookie()
 | 
					   >>> C = Cookie.Cookie()
 | 
				
			||||||
   >>> C.__class__
 | 
					   >>> print C.__class__.__name__
 | 
				
			||||||
   <class Cookie.SmartCookie at 99f88>
 | 
					   SmartCookie
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Finis.
 | 
					Finis.
 | 
				
			||||||
| 
						 | 
					@ -721,6 +721,12 @@ def value_encode(self, val):
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
###########################################################
 | 
					###########################################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _test():
 | 
				
			||||||
 | 
					    import doctest, Cookie
 | 
				
			||||||
 | 
					    return doctest.testmod(Cookie)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    _test()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Local Variables:
 | 
					#Local Variables:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue