Ejemplo n.º 1
0
 def test_event_object_methods_exist(self):
     '''Event object methods exist'''
     evt = events.create('round_start')
     for name in ['cancel', 'fire', 'is_empty']:
         self.assertTrue(hasattr(evt, name),
                         'events.Event.%s does not exist' % name)
     evt.cancel()
Ejemplo n.º 2
0
 def test_event_name(self):
     '''Event.name matches creation'''
     name = 'round_start'
     evt = events.create(name)
     self.assertEqual(
         evt.name, name, 'name created with and name attribute differ'
         ' (expected "%s", found "%s")' % (name, evt.name))
Ejemplo n.º 3
0
 def test_event_object_attributes_exist(self):
     '''Event object attributes exist'''
     evt = events.create('round_start')
     for name in ['name', 'dont_broadcast']:
         self.assertTrue(hasattr(evt, name),
                         'events.Event.%s does not exist' % name)
     evt.cancel()
Ejemplo n.º 4
0
 def test_event_create(self):
     '''Event creation'''
     evt = events.create('round_start')
     self.assertTrue(
         evt, 'Event creation unsuccessful (maybe the mod doesn\'t '
         'support "round_start"?)')
     evt.cancel()
Ejemplo n.º 5
0
    def test_event_fire(self):
        '''Event field values exist and match'''
        self.values = False

        event = self.game_events.get(sm.halflife.get_game_folder_name(), None)
        if event is None:
            print 'Unable to locate a game event for your mod, using cstrike...'
            event = self.game_events['cstrike']

        evt_name = event[0]
        fields = event[1]

        def callback(evt, evt_name):
            self.values = True

            for field in fields.iterkeys():
                # Check each field has a value
                self.assertTrue(
                    not evt.is_empty(field), '"%s" event field "%s" has a'
                    ' blank value.' % (evt_name, field))
                if evt.is_empty(field):
                    continue

                # Now check that the fields match what was written to them
                self.assertEqual(
                    evt[field], fields[field][0], 'Field "%s" set and '
                    'field %s retrieved differ (expected "%s", found "%s")' %
                    (field, field, fields[field][0], evt[field]))

                # Now check that the field types match modevents.res
                self.assertEqual(
                    type(evt[field]), fields[field][1], 'Field "%s" is of'
                    ' incorrect type "%s" (expected "%s", found "%s")' %
                    (field, str(type(evt[field])), str(
                        fields[field][1]), str(type(evt[field]))))

            return Plugin_Continue

        events.hook(evt_name, callback)

        evt = events.create(evt_name)
        for field, value in fields.iteritems():
            evt[field] = value[0]
        evt.fire()

        self.assertTrue(
            self.values, 'event callback never called. This is '
            'probably due to events being handled on the next gameframe, and '
            'thus isn\'t an issue.')
Ejemplo n.º 6
0
 def test_event_get_fields(self):
   '''Event get_fields() returns all event fields.'''
   event = self.game_events.get(sm.halflife.get_game_folder_name(), None)
   if event is None:
     print 'Unable to locate a game event for your mod, using cstrike...'
     event = self.game_events['cstrike']
   
   evt_name = event[0]
   fields = event[1]
   
   evt = events.create(evt_name)
   
   # The set() is important -- we don't care about ordering.
   self.assertEqual(set(evt.get_fields().keys()), set(fields.keys()),
       'get_fields() returns a wrong or incomplete set of fields.')
   
   evt.cancel()
Ejemplo n.º 7
0
 def test_event_fire(self):
   '''Event field values exist and match'''
   self.values = False
   
   event = self.game_events.get(sm.halflife.get_game_folder_name(), None)
   if event is None:
     print 'Unable to locate a game event for your mod, using cstrike...'
     event = self.game_events['cstrike']
   
   evt_name = event[0]
   fields = event[1]
   
   def callback(evt, evt_name):
     self.values = True
     
     for field in fields.iterkeys():
       # Check each field has a value
       self.assertTrue(not evt.is_empty(field), '"%s" event field "%s" has a'
           ' blank value.' % (evt_name, field))
       if evt.is_empty(field):
         continue
       
       # Now check that the fields match what was written to them
       self.assertEqual(evt[field], fields[field][0], 'Field "%s" set and '
           'field %s retrieved differ (expected "%s", found "%s")' %
           (field, field, fields[field][0], evt[field]))
       
       # Now check that the field types match modevents.res
       self.assertEqual(type(evt[field]), fields[field][1], 'Field "%s" is of'
           ' incorrect type "%s" (expected "%s", found "%s")' %
           (field, str(type(evt[field])), str(fields[field][1]),
           str(type(evt[field]))))
     
     return Plugin_Continue
   
   events.hook(evt_name, callback)
   
   evt = events.create(evt_name)
   for field,value in fields.iteritems():
     evt[field] = value[0]
   evt.fire()
   
   self.assertTrue(self.values, 'event callback never called. This is '
       'probably due to events being handled on the next gameframe, and '
       'thus isn\'t an issue.')
Ejemplo n.º 8
0
 def test_event_len(self):
   '''Event len(evt) produces correct result.'''
   event = self.game_events.get(sm.halflife.get_game_folder_name(), None)
   if event is None:
     print 'Unable to locate a game event for your mod, using cstrike...'
     event = self.game_events['cstrike']
   
   evt_name = event[0]
   fields = event[1]
   
   evt = events.create(evt_name)
   for field,value in fields.iteritems():
     evt[field] = value[0]
   
   self.assertEqual(len(evt), len(fields), 'modevents.res fields length (%d)'
       ' and passed fields length (%d) do not match.' % (len(evt), len(fields)))
   
   evt.cancel()
Ejemplo n.º 9
0
    def test_event_get_fields(self):
        '''Event get_fields() returns all event fields.'''
        event = self.game_events.get(sm.halflife.get_game_folder_name(), None)
        if event is None:
            print 'Unable to locate a game event for your mod, using cstrike...'
            event = self.game_events['cstrike']

        evt_name = event[0]
        fields = event[1]

        evt = events.create(evt_name)

        # The set() is important -- we don't care about ordering.
        self.assertEqual(
            set(evt.get_fields().keys()), set(fields.keys()),
            'get_fields() returns a wrong or incomplete set of fields.')

        evt.cancel()
Ejemplo n.º 10
0
    def test_event_len(self):
        '''Event len(evt) produces correct result.'''
        event = self.game_events.get(sm.halflife.get_game_folder_name(), None)
        if event is None:
            print 'Unable to locate a game event for your mod, using cstrike...'
            event = self.game_events['cstrike']

        evt_name = event[0]
        fields = event[1]

        evt = events.create(evt_name)
        for field, value in fields.iteritems():
            evt[field] = value[0]

        self.assertEqual(
            len(evt), len(fields), 'modevents.res fields length (%d)'
            ' and passed fields length (%d) do not match.' %
            (len(evt), len(fields)))

        evt.cancel()
Ejemplo n.º 11
0
 def test_event_name_change(self):
   '''Event.name is read-only'''
   name = 'round_start'
   evt = events.create(name)
   self.assertRaises(AttributeError, setattr, evt, 'name', 'fuzzbuggler')
   evt.cancel()
Ejemplo n.º 12
0
 def test_event_name(self):
   '''Event.name matches creation'''
   name = 'round_start'
   evt = events.create(name)
   self.assertEqual(evt.name, name, 'name created with and name attribute differ'
       ' (expected "%s", found "%s")' % (name, evt.name))
Ejemplo n.º 13
0
 def test_event_object_methods_exist(self):
   '''Event object methods exist'''
   evt = events.create('round_start')
   for name in ['cancel', 'fire', 'is_empty']:
     self.assertTrue(hasattr(evt, name), 'events.Event.%s does not exist' % name)
   evt.cancel()
Ejemplo n.º 14
0
 def test_event_object_attributes_exist(self):
   '''Event object attributes exist'''
   evt = events.create('round_start')
   for name in ['name', 'dont_broadcast']:
     self.assertTrue(hasattr(evt, name), 'events.Event.%s does not exist' % name)
   evt.cancel()
Ejemplo n.º 15
0
 def test_event_create(self):
   '''Invalid Event creation not allowed'''
   evt = events.create('a non-existent event name')
   self.assertFalse(evt, 'Event creation successful, but it shouldn\'t be')
Ejemplo n.º 16
0
 def test_event_create(self):
   '''Event creation'''
   evt = events.create('round_start')
   self.assertTrue(evt, 'Event creation unsuccessful (maybe the mod doesn\'t '
       'support "round_start"?)')
   evt.cancel()
Ejemplo n.º 17
0
 def test_event_create(self):
     '''Invalid Event creation not allowed'''
     evt = events.create('a non-existent event name')
     self.assertFalse(evt,
                      'Event creation successful, but it shouldn\'t be')
Ejemplo n.º 18
0
 def test_event_name_change(self):
     '''Event.name is read-only'''
     name = 'round_start'
     evt = events.create(name)
     self.assertRaises(AttributeError, setattr, evt, 'name', 'fuzzbuggler')
     evt.cancel()