Example #1
0
    def test_immutable(self):
        d = frozendict()

        with self.assertRaises(Exception):
            d['hello'] = 'world'

        d = frozendict({'hello': 'world'})

        with self.assertRaises(Exception):
            d['hello'] = 'world'
Example #2
0
    def test_immutable(self):
        d = frozendict()

        with self.assertRaises(Exception):
            d['hello'] = 'world'

        d = frozendict({'hello':'world'})

        with self.assertRaises(Exception):
            d['hello'] = 'world'
Example #3
0
 def freeze(self):
     if self.frozen:
         return
     if isinstance(self.value, Reference):
         raise ASTError('setting %s.%s is a reference with no resolved '
             'value' % (self.instance, self.attribute), self)
     if self.attribute in C_KEYWORDS:
         raise ASTError('setting name \'%s\' clashes with a C keyword' %
             self.attribute, self)
     if isinstance(self.value, list):
         self.value = tuple(self.value)
     elif isinstance(self.value, dict):
         self.value = frozendict(self.value)
     super(Setting, self).freeze()
Example #4
0
 def freeze(self):
     if self.frozen:
         return
     if isinstance(self.value, Reference):
         raise ASTError('setting %s.%s is a reference with no resolved '
             'value' % (self.instance, self.attribute), self)
     if self.attribute in C_KEYWORDS:
         raise ASTError('setting name \'%s\' clashes with a C keyword' %
             self.attribute, self)
     if isinstance(self.value, list):
         self.value = tuple(self.value)
     elif isinstance(self.value, dict):
         self.value = frozendict(self.value)
     super(Setting, self).freeze()
Example #5
0
    def test_construction(self):
        d = frozendict()
        self.assertIsNone(d.get('hello'))

        d = frozendict({'hello': 'world'})
        self.assertEqual(d['hello'], 'world')
Example #6
0
    def test_construction(self):
        d = frozendict()
        self.assertIsNone(d.get('hello'))

        d = frozendict({'hello':'world'})
        self.assertEqual(d['hello'], 'world')