Esempio n. 1
0
    def test_dict_access(self):
        obj = DictObject(foo='bar')
        self.assertEqual(obj['foo'], 'bar')

        with self.assertRaises(KeyError):
            obj['missing']

        self.assertEqual(obj.get('missing', 'baz'), 'baz')
Esempio n. 2
0
    def test_data_key(self):
        # data is used internally, so we need to explictly test it
        obj = DictObject(data=1)
        self.assertEqual(obj, {'data': 1})

        obj.data = 2
        self.assertEqual(obj, {'data': 2})

        obj.update(dict(data=3))
        self.assertEqual(obj, {'data': 3})
Esempio n. 3
0
    def test_updating(self):
        obj = DictObject(foo='bar')
        self.assertEqual(obj, {'foo': 'bar'})

        obj['foo'] = 1
        self.assertEqual(obj, {'foo': 1})

        obj['bar'] = 2
        self.assertEqual(obj, {'foo': 1, 'bar': 2})

        obj.foo = 3
        self.assertEqual(obj, {'foo': 3, 'bar': 2})

        obj.baz = 1
        self.assertEqual(obj, {'foo': 3, 'bar': 2, 'baz': 1})

        setattr(obj, 'baz', 3)
        self.assertEqual(obj, {'foo': 3, 'bar': 2, 'baz': 3})
Esempio n. 4
0
 def test_update(self):
     obj = DictObject(foo=1)
     obj.update(dict(bar=2))
     self.assertEqual(obj, {'foo': 1, 'bar': 2})
Esempio n. 5
0
 def test_iteration(self):
     obj = DictObject(foo=1, bar=2, baz=3)
     self.assertEqual(set(obj), set(obj.keys()))
Esempio n. 6
0
 def test_length(self):
     obj = DictObject(foo='bar')
     self.assertEqual(len(obj), 1)
     obj.baz = 1
     self.assertEqual(len(obj), 2)