def test_Event(self):
# __doc__ (as of 2008-08-02) for pygame.event.Event:
# pygame.event.Event(type, dict): return Event
# pygame.event.Event(type, **attributes): return Event
# create a new event object
#
# Creates a new event with the given type. The event is created with
# the given attributes and values. The attributes can come from a
# dictionary argument, or as string keys from a dictionary.
#
# The given attributes will be readonly attributes on the new event
# object itself. These are the only attributes on the Event object,
# there are no methods attached to Event objects.
e = pygame.event.Event(pygame.USEREVENT, some_attr=1, other_attr='1')
self.assertEquals(e.some_attr, 1)
self.assertEquals(e.other_attr, "1")
# Event now uses tp_dictoffset and tp_members: request 62
# on Motherhamster Bugzilla.
self.assertEquals(e.type, pygame.USEREVENT)
self.assert_(e.dict is e.__dict__)
e.some_attr = 12
self.assertEquals(e.some_attr, 12)
e.new_attr = 15
self.assertEquals(e.new_attr, 15)
# For Python 2.x a TypeError is raised for a readonly member;
# for Python 3.x it is an AttributeError.
self.assertRaises((TypeError, AttributeError), setattr, e, 'type', 0)
self.assertRaises((TypeError, AttributeError), setattr, e, 'dict', None)
# Ensure attributes are visible to dir(), part of the original
# posted request.
d = dir(e)
self.assert_('type' in d)
self.assert_('dict' in d)
self.assert_('__dict__' in d)
self.assert_('some_attr' in d)
self.assert_('other_attr' in d)
self.assert_('new_attr' in d)
评论列表
文章目录