Ejemplo n.º 1
0
 def setUp(self):
     self.foo = User_dict()
     self.messages = []
     self.foo.connect('changed', self.callback)
Ejemplo n.º 2
0
class TestSignals(unittest.TestCase):

    def setUp(self):
        self.foo = User_dict()
        self.messages = []
        self.foo.connect('changed', self.callback)

    def callback(self, *args):
        self.messages.append(args)

    def test_update_with_additions(self):
        bar = {'foobar': 7}
        self.foo.update({'foobar': 7})
        self.assertEqual(self.messages[0][1], ('foobar',))
        self.foo.update({'fooey': 2})
        self.assertEqual(self.messages[1][1], ('fooey',))
        self.assertEqual(len(self.messages), 2)

    def test_update_with_changes(self):
        bar = {'foobar': 7}
        self.foo.update({'foobar': 7})
        self.assertEqual(self.messages[0][1], ('foobar',))
        self.foo.update({'foobar': 8})
        self.assertEqual(self.messages[1][1], ('foobar',))
        self.assertEqual(len(self.messages), 2)

    def test_update_without_changes(self):
        bar = {'foobar': 7}
        self.foo.update({'foobar': 7})
        self.assertEqual(self.messages[0][1], ('foobar',))
        self.foo.update({'foobar': 7})
        self.assertEqual(len(self.messages), 1)

    def test_update_with_several_items(self):
        data = {'pluto': 7, 'mickey': 8, 'minnie': 9}
        self.foo.update(data)
        self.assertEqual(self.messages[0][1], ('mickey', 'minnie', 'pluto'))
        self.assertEqual(len(self.messages), 1)
        data = {'mickey': 1, 'minnie': 2}
        self.foo.update(data)
        self.assertEqual(self.messages[1][1], ('mickey', 'minnie'))
        self.assertEqual(len(self.messages), 2)

    def test__setitem__with_additions(self):
        self.foo['too'] = 3
        self.assertEqual(self.messages[0][1], ('too',))

    def test__setitem__with_changes(self):
        self.foo['too'] = 3
        self.assertEqual(self.messages[0][1], ('too',))
        self.assertEqual(len(self.messages), 1)
        self.foo['too'] = 4
        self.assertEqual(len(self.messages), 2)

    def test__setitem__without_changes(self):
        self.foo['too'] = 3
        self.assertEqual(self.messages[0][1], ('too',))
        self.assertEqual(len(self.messages), 1)
        self.foo['too'] = 3
        self.assertEqual(len(self.messages), 1)
Ejemplo n.º 3
0
 def test__setitem__(self):
     foo = User_dict()
     foo[2] = 3
     self.assertEqual(foo.get(2), 3)
Ejemplo n.º 4
0
 def test__delitem__(self):
     foo = User_dict()
     foo[2] = 3
     self.assertEqual(foo.get(2), 3)
     del foo[2]
     self.assertEqual(foo.get(2, 'default'), 'default')
Ejemplo n.º 5
0
 def test_update_from_dict(self):
     foo = User_dict()
     bar = {'pluto':2}
     foo.update(bar)
     self.assertEqual(foo.get('pluto'), 2)