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_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_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_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_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)])))
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_resolves_to_object_returned_by_db(self): o = UnresolvedObject(7, None) db = Mock(spec=interfaces.ObjectDB) expected_obj = MockObject() db.retrieve_object = Mock(return_value=expected_obj) r = o.resolve(db) self.assertEqual(r, expected_obj)
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_requests_right_object_with_non_null_type_from_db(self): o = UnresolvedObject(7, 'some_type') db = Mock(spec=interfaces.ObjectDB) expected_obj = MockObject() db.retrieve_object = Mock(return_value=expected_obj) o.resolve(db) db.retrieve_object.assert_called_once_with(7, -1, 'some_type')
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_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_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_convert_to_str(self): o = MockObject() self.assertTrue(str(o))
def test_obj_type_matches_for_new_obj(self): m = parse('wl_pointer') self.assertFalse( m.matches( MockMessage( args=[Arg.Object(MockObject(type='wl_pointer'), True)])))
def test_message_name(self): m = parse('.axis') self.assertTrue(m.matches(MockMessage(name='axis'))) self.assertFalse(m.matches(MockMessage())) self.assertFalse(m.matches(MockMessage(obj=MockObject(type='axis'))))
def test_obj_type_with_at(self): m = parse('wl_pointer@') self.assertTrue( m.matches(MockMessage(obj=MockObject(type='wl_pointer')))) self.assertFalse(m.matches(MockMessage(name='wl_pointer')))
def test_is_object(self): o = MockObject() self.assertIsInstance(o, ObjectBase)