| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | """Test module for the custom examples
 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | Custom 1: | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> import custom | 
					
						
							|  |  |  | >>> c1 = custom.Custom() | 
					
						
							|  |  |  | >>> c2 = custom.Custom() | 
					
						
							|  |  |  | >>> del c1 | 
					
						
							|  |  |  | >>> del c2 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | Custom 2 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> import custom2 | 
					
						
							|  |  |  | >>> c1 = custom2.Custom('jim', 'fulton', 42) | 
					
						
							|  |  |  | >>> c1.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'jim' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.last | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 42 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'jim fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first = 'will' | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'will fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.last = 'tell' | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'will tell' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> del c1.first | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | AttributeError: first | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | AttributeError: first | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first = 'drew' | 
					
						
							|  |  |  | >>> c1.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'drew' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> del c1.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | TypeError: can't delete numeric/char attribute | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.number=2 | 
					
						
							|  |  |  | >>> c1.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 2 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first = 42 | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | '42 tell' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2 = custom2.Custom() | 
					
						
							|  |  |  | >>> c2.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | ' ' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | '' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.last | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | '' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> del c2.first | 
					
						
							|  |  |  | >>> c2.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | AttributeError: first | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | AttributeError: first | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  |   File "<stdin>", line 1, in ? | 
					
						
							|  |  |  | AttributeError: first | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 0 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> n3 = custom2.Custom('jim', 'fulton', 'waaa') | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  |   File "<stdin>", line 1, in ? | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | TypeError: an integer is required (got type str) | 
					
						
							|  |  |  | >>> del c1 | 
					
						
							|  |  |  | >>> del c2 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | Custom 3 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> import custom3 | 
					
						
							|  |  |  | >>> c1 = custom3.Custom('jim', 'fulton', 42) | 
					
						
							|  |  |  | >>> c1 = custom3.Custom('jim', 'fulton', 42) | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'jim fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> del c1.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  |   File "<stdin>", line 1, in ? | 
					
						
							|  |  |  | TypeError: Cannot delete the first attribute | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first = 42 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  |   File "<stdin>", line 1, in ? | 
					
						
							|  |  |  | TypeError: The first attribute value must be a string | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first = 'will' | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'will fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2 = custom3.Custom() | 
					
						
							|  |  |  | >>> c2 = custom3.Custom() | 
					
						
							|  |  |  | >>> c2 = custom3.Custom() | 
					
						
							|  |  |  | >>> n3 = custom3.Custom('jim', 'fulton', 'waaa') | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  |   File "<stdin>", line 1, in ? | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | TypeError: an integer is required (got type str) | 
					
						
							|  |  |  | >>> del c1 | 
					
						
							|  |  |  | >>> del c2 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | Custom 4 | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> import custom4 | 
					
						
							|  |  |  | >>> c1 = custom4.Custom('jim', 'fulton', 42) | 
					
						
							|  |  |  | >>> c1.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'jim' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.last | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 42 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'jim fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first = 'will' | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'will fulton' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.last = 'tell' | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'will tell' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> del c1.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | TypeError: Cannot delete the first attribute | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							|  |  |  | 'will tell' | 
					
						
							|  |  |  | >>> c1.first = 'drew' | 
					
						
							|  |  |  | >>> c1.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 'drew' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> del c1.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | TypeError: can't delete numeric/char attribute | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.number=2 | 
					
						
							|  |  |  | >>> c1.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 2 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c1.first = 42 | 
					
						
							|  |  |  | Traceback (most recent call last): | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | TypeError: The first attribute value must be a string | 
					
						
							|  |  |  | >>> c1.name() | 
					
						
							|  |  |  | 'drew tell' | 
					
						
							|  |  |  | >>> c2 = custom4.Custom() | 
					
						
							|  |  |  | >>> c2 = custom4.Custom() | 
					
						
							|  |  |  | >>> c2 = custom4.Custom() | 
					
						
							|  |  |  | >>> c2 = custom4.Custom() | 
					
						
							|  |  |  | >>> c2.name() | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | ' ' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.first | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | '' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.last | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | '' | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> c2.number | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 0 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> n3 = custom4.Custom('jim', 'fulton', 'waaa') | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | Traceback (most recent call last): | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | ... | 
					
						
							|  |  |  | TypeError: an integer is required (got type str) | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Test cyclic gc(?) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | >>> import gc | 
					
						
							|  |  |  | >>> gc.disable() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | >>> class Subclass(custom4.Custom): pass | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | >>> s = Subclass() | 
					
						
							|  |  |  | >>> s.cycle = [s] | 
					
						
							|  |  |  | >>> s.cycle.append(s.cycle) | 
					
						
							|  |  |  | >>> x = object() | 
					
						
							|  |  |  | >>> s.x = x | 
					
						
							|  |  |  | >>> del s | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | >>> sys.getrefcount(x) | 
					
						
							|  |  |  | 3 | 
					
						
							|  |  |  | >>> ignore = gc.collect() | 
					
						
							|  |  |  | >>> sys.getrefcount(x) | 
					
						
							|  |  |  | 2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | >>> gc.enable() | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | from distutils.util import get_platform | 
					
						
							| 
									
										
										
										
											2016-02-11 13:10:36 +02:00
										 |  |  | PLAT_SPEC = "%s-%d.%d" % (get_platform(), *sys.version_info[:2]) | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | src = os.path.join("build", "lib.%s" % PLAT_SPEC) | 
					
						
							|  |  |  | sys.path.append(src) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     import doctest, __main__ | 
					
						
							|  |  |  |     doctest.testmod(__main__) |