def test_immutable(self): d = frozendict() with self.assertRaises(Exception): d['hello'] = 'world' d = frozendict({'hello': 'world'}) with self.assertRaises(Exception): d['hello'] = 'world'
def test_immutable(self): d = frozendict() with self.assertRaises(Exception): d['hello'] = 'world' d = frozendict({'hello':'world'}) with self.assertRaises(Exception): d['hello'] = 'world'
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()
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()
def test_construction(self): d = frozendict() self.assertIsNone(d.get('hello')) d = frozendict({'hello': 'world'}) self.assertEqual(d['hello'], 'world')
def test_construction(self): d = frozendict() self.assertIsNone(d.get('hello')) d = frozendict({'hello':'world'}) self.assertEqual(d['hello'], 'world')