test a simple use scenario initialize an int delegator trying to access a nonattribute of int fails add real int attribute bitlength by accessing it add attribute numerator delete numerator the current implementation leaves it in the name cache self assertin numerator mydel delegatorcache however this is not required and not part of the specification change delegate to float first resetting the attributes test a simple use scenario initialize an int delegator trying to access a non attribute of int fails add real int attribute bit_length by accessing it add attribute numerator delete numerator the current implementation leaves it in the name cache self assertin numerator mydel _delegator__cache however this is not required and not part of the specification change delegate to float first resetting the attributes calls resetcache
"Test delegator, coverage 100%."

from idlelib.delegator import Delegator
import unittest


class DelegatorTest(unittest.TestCase):

    def test_mydel(self):
        

        
        mydel = Delegator(int)
        self.assertIs(mydel.delegate, int)
        self.assertEqual(mydel._Delegator__cache, set())
        
        self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')

        
        bl = mydel.bit_length
        self.assertIs(bl, int.bit_length)
        self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
        self.assertEqual(mydel._Delegator__cache, {'bit_length'})

        
        mydel.numerator
        self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})

        
        del mydel.numerator
        self.assertNotIn('numerator', mydel.__dict__)
        
        
        

        
        mydel.setdelegate(float)  
        self.assertNotIn('bit_length', mydel.__dict__)
        self.assertEqual(mydel._Delegator__cache, set())
        self.assertIs(mydel.delegate, float)


if __name__ == '__main__':
    unittest.main(verbosity=2, exit=2)