mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	test_dir(): Add tests for dir(i) where i is a module subclass.
This commit is contained in:
		
							parent
							
								
									7b0494635b
								
							
						
					
					
						commit
						caaff8d95d
					
				
					 1 changed files with 23 additions and 0 deletions
				
			
		| 
						 | 
					@ -241,6 +241,29 @@ def test_dir():
 | 
				
			||||||
    a.amethod = lambda self: 3
 | 
					    a.amethod = lambda self: 3
 | 
				
			||||||
    verify(interesting(dir(a)) == astuff + ['adata', 'amethod'])
 | 
					    verify(interesting(dir(a)) == astuff + ['adata', 'amethod'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Try a module subclass.
 | 
				
			||||||
 | 
					    import sys
 | 
				
			||||||
 | 
					    class M(type(sys)):
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					    minstance = M()
 | 
				
			||||||
 | 
					    minstance.b = 2
 | 
				
			||||||
 | 
					    minstance.a = 1
 | 
				
			||||||
 | 
					    verify(dir(minstance) == ['a', 'b'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class M2(M):
 | 
				
			||||||
 | 
					        def getdict(self):
 | 
				
			||||||
 | 
					            return "Not a dict!"
 | 
				
			||||||
 | 
					        __dict__ = property(getdict)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m2instance = M2()
 | 
				
			||||||
 | 
					    m2instance.b = 2
 | 
				
			||||||
 | 
					    m2instance.a = 1
 | 
				
			||||||
 | 
					    verify(m2instance.__dict__ == "Not a dict!")
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        dir(m2instance)
 | 
				
			||||||
 | 
					    except TypeError:
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
binops = {
 | 
					binops = {
 | 
				
			||||||
    'add': '+',
 | 
					    'add': '+',
 | 
				
			||||||
    'sub': '-',
 | 
					    'sub': '-',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue