def test_obj_id_with_at(self): m = parse('@7') self.assertTrue(m.matches(MockMessage(obj=MockObject(id=7)))) self.assertTrue( m.matches(MockMessage(obj=MockObject(id=7, generation=3)))) self.assertFalse(m.matches(MockMessage(obj=MockObject(id=8)))) self.assertFalse(m.matches(MockMessage(obj=MockObject(type='7'))))
def test_obj_type_with_wildcard(self): m = parse('wl_*') self.assertTrue( m.matches(MockMessage(obj=MockObject(type='wl_pointer')))) self.assertTrue(m.matches( MockMessage(obj=MockObject(type='wl_touch')))) self.assertFalse( m.matches(MockMessage(obj=MockObject(type='xdg_shell'))))
def test_multiple_object_types(self): m = parse('[wl_pointer, wl_touch]') self.assertTrue( m.matches(MockMessage(obj=MockObject(type='wl_pointer')))) self.assertTrue(m.matches( MockMessage(obj=MockObject(type='wl_touch')))) self.assertFalse( m.matches(MockMessage(obj=MockObject(type='wl_keyboard'))))
def test_exclude_obje_types(self): m = parse('wl_* ! wl_keyboard') self.assertTrue( m.matches(MockMessage(obj=MockObject(type='wl_pointer')))) self.assertFalse( m.matches(MockMessage(obj=MockObject(type='wl_keyboard')))) self.assertFalse( m.matches(MockMessage(obj=MockObject(type='xdg_shell'))))
def test_not_message(self): m = parse('!.get_popup') self.assertTrue( m.matches( MockMessage(obj=MockObject(type='xdg_surface'), name='commit'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='xdg_surface'), name='get_popup')))
def test_title_does_not_overrite_app_id(self): last_part = 'last_part' app_id = 'some.app.id.' + last_part m0 = MockMessage(name='set_app_id', args=[Arg.String(app_id)]) self.c.message(m0) title = 'some_app_title' m1 = MockMessage(name='set_title', args=[Arg.String(title)]) self.c.message(m1) self.assertNotIn(title, str(self.c)) self.assertIn(last_part, str(self.c))
def test_obj_type_and_message_name(self): m = parse('wl_pointer.motion') self.assertTrue( m.matches( MockMessage(obj=MockObject(type='wl_pointer'), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_touch'), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_pointer'), name='axis')))
def test_obj_id_and_generation(self): m = parse('5d') self.assertTrue( m.matches(MockMessage(obj=MockObject(id=5, generation=3)))) self.assertFalse( m.matches(MockMessage(obj=MockObject(id=5, generation=None)))) self.assertFalse( m.matches(MockMessage(obj=MockObject(id=5, generation=12)))) self.assertFalse( m.matches(MockMessage(obj=MockObject(id=12, generation=3)))) self.assertFalse(m.matches(MockMessage(obj=MockObject(type='5'))))
def test_obj_type(self): m = parse('wl_pointer') self.assertTrue( m.matches(MockMessage(obj=MockObject(type='wl_pointer')))) self.assertFalse(m.matches(MockMessage())) self.assertFalse( m.matches(MockMessage(obj=MockObject(type='wl_touch')))) self.assertFalse(m.matches(MockMessage(name='wl_pointer'))) self.assertFalse( m.matches( MockMessage( args=[Arg.Object(MockObject(type='wl_pointer'), False)])))
class TestMockMessage(TestCase): def setUp(self): self.m = MockMessage() def test_convert_to_str(self): self.assertTrue(str(self.m)) def test_resolve(self): db = mock.Mock(spec=interfaces.ObjectDB) self.m.resolve(db) def test_used_objects(self): self.assertEqual(self.m.used_objects(), ())
def test_obj_type_with_multiple_message_names(self): m = parse('wl_pointer.[motion, axis]') self.assertTrue( m.matches( MockMessage(obj=MockObject(type='wl_pointer'), name='motion'))) self.assertTrue( m.matches( MockMessage(obj=MockObject(type='wl_pointer'), name='axis'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_pointer'), name='frame'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_touch'), name='motion')))
def test_object_wildcard_not_type_or_message_name(self): m = parse('xdg_* ! xdg_popup, .get_popup') self.assertTrue( m.matches( MockMessage(obj=MockObject(type='xdg_surface'), name='commit'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='xdg_surface'), name='get_popup'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='xdg_popup'), name='commit'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_surface'), name='commit')))
def test_delete_id_can_be_matched(self): m = parse('wl_surface.destroyed') self.assertTrue( m.matches( MockMessage(obj=MockObject(type='wl_display', id=1), name='delete_id', destroyed_obj=MockObject(type='wl_surface')))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_display', id=1), name='delete_id', destroyed_obj=MockObject(type='wl_touch')))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_display', id=1), name='delete_id')))
def test_obj_id_generation_and_message_name(self): m = parse('@5d.motion') self.assertTrue( m.matches( MockMessage(obj=MockObject(id=5, generation=3), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(id=12, generation=3), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(id=5, generation=12), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(id=5, generation=3), name='axis'))) self.assertFalse(m.matches(MockMessage(name='3.motion')))
def test_object_id_with_multiple_messages(self): m = parse('55a.[motion, axis]') self.assertTrue( m.matches( MockMessage(obj=MockObject(id=55, generation=0), name='motion'))) self.assertTrue( m.matches( MockMessage(obj=MockObject(id=55, generation=0), name='axis'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(id=55, generation=0), name='frame'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(id=55, generation=9), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(id=54, generation=0), name='axis')))
def test_description_includes_layer_namespace_from_message(self): title = 'some_app_title' m = MockMessage(name='get_layer_surface', args=[ Arg.Null(), Arg.Null(), Arg.Null(), Arg.Null(), Arg.String(title) ]) self.c.message(m) self.assertIn(title, str(self.c))
def test_object_type_and_id_with_message(self): m = parse('[wl_pointer, 12].motion') self.assertTrue( m.matches( MockMessage(obj=MockObject(type='wl_pointer', id=6), name='motion'))) self.assertTrue( m.matches( MockMessage(obj=MockObject(type='wl_touch', id=12), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_touch', id=6), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_pointer', id=6), name='frame'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_touch', id=12), name='frame')))
def test_object_name_but_not_ids_with_messages(self): m = parse('[wl_pointer ! 55, 62].motion') self.assertTrue( m.matches( MockMessage(obj=MockObject(type='wl_pointer', id=12), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_pointer', id=12), name='axis'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_pointer', id=55), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_pointer', id=62), name='motion'))) self.assertFalse( m.matches( MockMessage(obj=MockObject(type='wl_touch', id=12), name='motion')))
def test_detects_app_id(self): app_id = 'some.app.id' m = MockMessage(name='set_app_id', args=[Arg.String(app_id)]) self.c.message(m) self.assertEqual(self.c.app_id(), app_id)
def test_messages_are_stored(self): m0 = MockMessage() m1 = MockMessage() self.c.message(m0) self.c.message(m1) self.assertEqual(self.c.messages(), (m0, m1))
def test_warning_on_message_after_close(self): self.c.close(0.0) m = MockMessage() self.c.message(m)
def test_remove_listener(self): self.c.add_connection_listener(self.l) self.c.remove_connection_listener(self.l) m = MockMessage() self.c.message(m) self.l.connection_got_new_message.assert_not_called()
def test_messages_returns_tuple(self): self.c.message(MockMessage()) self.c.message(MockMessage()) self.assertIsInstance(self.c.messages(), tuple)
def test_listener_notified_of_message(self): self.c.add_connection_listener(self.l) m = MockMessage() self.c.message(m) self.l.connection_got_new_message.assert_called_once_with(self.c, m)
def test_listener_not_notified_on_no_description_change(self): m = MockMessage() self.c.add_connection_listener(self.l) self.c.message(m) self.l.connection_str_changed.assert_not_called()
def test_description_includes_app_id_from_message(self): last_part = 'last_part' app_id = 'some.app.id.' + last_part m = MockMessage(name='set_app_id', args=[Arg.String(app_id)]) self.c.message(m) self.assertIn(last_part, str(self.c))
def test_listener_notified_of_app_id_change(self): app_id = 'some.app.id' m = MockMessage(name='set_app_id', args=[Arg.String(app_id)]) self.c.add_connection_listener(self.l) self.c.message(m) self.l.connection_app_id_set.assert_called_once_with(self.c, app_id)
def test_description_only_includes_last_part_of_app_id(self): last_part = 'last_part' app_id = 'some.app.id.' + last_part m = MockMessage(name='set_app_id', args=[Arg.String(app_id)]) self.c.message(m) self.assertNotIn(app_id, str(self.c))
def test_description_includes_title_from_message(self): title = 'some_app_title' m = MockMessage(name='set_title', args=[Arg.String(title)]) self.c.message(m) self.assertIn(title, str(self.c))
def test_listener_notified_of_title_description_change(self): title = 'some_app_title' m = MockMessage(name='set_title', args=[Arg.String(title)]) self.c.add_connection_listener(self.l) self.c.message(m) self.l.connection_str_changed.assert_called_once_with(self.c)