コード例 #1
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})
コード例 #2
0
 def test_length(self):
     obj = DictObject(foo='bar')
     self.assertEqual(len(obj), 1)
     obj.baz = 1
     self.assertEqual(len(obj), 2)