| 
									
										
										
										
											2000-04-03 03:51:50 +00:00
										 |  |  | #!/usr/bin/env python | 
					
						
							| 
									
										
										
										
											2001-02-09 12:00:47 +00:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2002-07-23 19:04:11 +00:00
										 |  |  | from test.test_support import verbose | 
					
						
							|  |  |  | from test import string_tests | 
					
						
							| 
									
										
										
										
											2000-04-03 03:51:50 +00:00
										 |  |  | # UserString is a wrapper around the native builtin string type. | 
					
						
							|  |  |  | # UserString instances should behave similar to builtin string objects. | 
					
						
							|  |  |  | # The test cases were in part derived from 'test_string.py'. | 
					
						
							|  |  |  | from UserString import UserString | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							| 
									
										
										
										
											2002-04-12 16:25:39 +00:00
										 |  |  |     verbose = '-v' in sys.argv | 
					
						
							| 
									
										
										
										
											2000-04-03 03:51:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | tested_methods = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-12 16:25:39 +00:00
										 |  |  | def test(methodname, input, output, *args): | 
					
						
							| 
									
										
										
										
											2000-04-03 03:51:50 +00:00
										 |  |  |     global tested_methods | 
					
						
							|  |  |  |     tested_methods[methodname] = 1 | 
					
						
							|  |  |  |     if verbose: | 
					
						
							| 
									
										
										
										
											2002-04-12 16:25:39 +00:00
										 |  |  |         print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))), | 
					
						
							| 
									
										
										
										
											2000-04-03 03:51:50 +00:00
										 |  |  |     u = UserString(input) | 
					
						
							|  |  |  |     objects = [input, u, UserString(u)] | 
					
						
							|  |  |  |     res = [""] * 3 | 
					
						
							|  |  |  |     for i in range(3): | 
					
						
							|  |  |  |         object = objects[i] | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             f = getattr(object, methodname) | 
					
						
							| 
									
										
										
										
											2002-04-12 16:25:39 +00:00
										 |  |  |         except AttributeError: | 
					
						
							|  |  |  |             f = None | 
					
						
							|  |  |  |             res[i] = AttributeError | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 res[i] = apply(f, args) | 
					
						
							|  |  |  |             except: | 
					
						
							|  |  |  |                 res[i] = sys.exc_type | 
					
						
							|  |  |  |     if res[0] == res[1] == res[2] == output: | 
					
						
							| 
									
										
										
										
											2000-04-03 03:51:50 +00:00
										 |  |  |         if verbose: | 
					
						
							|  |  |  |             print 'yes' | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         if verbose: | 
					
						
							| 
									
										
										
										
											2002-04-12 16:25:39 +00:00
										 |  |  |             print 'no' | 
					
						
							|  |  |  |         print (methodname, input, output, args, res[0], res[1], res[2]) | 
					
						
							| 
									
										
										
										
											2000-04-03 03:51:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-10 17:08:42 +00:00
										 |  |  | string_tests.run_method_tests(test) | 
					
						
							| 
									
										
										
										
											2002-08-06 16:58:21 +00:00
										 |  |  | string_tests.run_contains_tests(test) | 
					
						
							| 
									
										
										
										
											2002-08-09 01:37:06 +00:00
										 |  |  | string_tests.run_inplace_tests(UserString) |