Example #1
0
    def test_protected_attribute_setting(self):
        '''
        Protected attribute setting.

        - Protected attributes should stay protected.
        - Protection should work for attr setting or key setting.
        '''
        sd = Superdict()
        v = 1234
        # Setting via attribute.
        sd.update = v
        aEq(sd['update'], v)
        self.assertNotEqual(sd['update'], sd.update)
        self.assertIsInstance(sd.update, types.MethodType)
        # Setting via key.
        sd['pop'] = v
        aEq(sd['pop'], v)
        self.assertNotEqual(sd['pop'], sd.pop)
        self.assertIsInstance(sd.pop, types.MethodType)
Example #2
0
    def test_update(self):
        '''
        update().

        - Since the constructor relies on update(), this behavior is well covered.
        '''
        sd = Superdict(a=11, b=22)
        # Basic attributes.
        sd.update(c = 33, d = 44)
        aEq(sd.c, 33)
        aEq(sd.d, 44)
        aEq(sd['c'], 33)
        # Protected attributes.
        sd.update([('pop', 99), ('setdefault', 88)])
        aEq(sd['pop'], 99)
        self.assertIsInstance(sd.pop, types.MethodType)
        # Wrong N args.
        with aRaz(TERR): sd.update([1,2,3], [4,5])