Example #1
0
    def test_basic_attribute_access(self):
        '''
        Basic attribute access.

        - Can set values via attr or key.
        - Set values are store in both the attr and the key.
        '''
        sd = Superdict(a = 1, b = 2)
        # Basics.
        sd.b = 22
        sd['c'] = 33
        aEq(sd.a, 1)
        aEq(sd.c, 33)
        aEq(sd['a'], 1)
        aEq(sd['c'], 33)
        aEq(sd, dict(a = 1, b = 22, c = 33))
        # Set attributes are stored both as attributes on the Superdict and as
        # keys in the underlying dict.
        ks = set('abc')
        for k in ks:
            self.assertIn(k, sd.__dict__)
        dict_ks = super(Superdict, sd).keys()
        aEq(set(dict_ks), ks)