Пример #1
0
        item.add_to_batch = Mock()
        render.on_add_item(item)
        self.assertEquals(
            item.add_to_batch.call_args,
            ((render.batch, render.groups), {})
        )


    def test_on_remove_item(self):
        game = Mock()
        game.item_added = Event()
        game.item_removed = Event()
        render = Render(game)
        item = GameItem()

        render.on_remove_item(item)
        # item.remove_from_batch doesn't exist and is not called

        item.remove_from_batch = Mock()
        render.on_remove_item(item)
        self.assertEquals(
            item.remove_from_batch.call_args,
            ((render.batch, ), {})
        )


if __name__ == '__main__':
    run(RenderTest)

Пример #2
0
        self.assertRaises(
            lambda: remove(event, nonlistener),
            KeyError, expected_msg)


    def test_RemovingListenersMultipleTimesRaises(self):
        mock = Mock()
        event = Event()
        event += mock

        def remove(event, mock):
            event -= mock

        remove(event, mock)
        expected_msg = 'listener not subscribed to this event:\n  %s\n  %s' \
            % (mock, event)
        self.assertRaises(lambda: remove(event, mock), KeyError, expected_msg)


    def test_str(self):
        self.assertEquals(str(Event()), 'Event')

        class MyEvent(Event): pass
        self.assertEquals(str(MyEvent()), 'MyEvent')



if __name__ == '__main__':
    run(EventTest)

Пример #3
0
    def test_normalized(self):
        v = Vec2(3, 4)
        self.assertEquals(v.normalized(), Vec2(3 / 5, 4 / 5))
        self.assertEquals(v, Vec2(3, 4))

    def test_normalized_zero(self):
        v = Vec2(0, 0)
        self.assertEquals(v.normalized(), Vec2(1, 0))
        self.assertEquals(v, Vec2(0, 0))

    def test_normalize_zero_raises(self):
        v = Vec2(0, 0)
        self.assertRaises(
            lambda: v.normalize(raise_on_zero=True), ZeroDivisionError)

    def test_normalized_zero_raises(self):
        v = Vec2(0, 0)
        self.assertRaises(
            lambda: v.normalized(raise_on_zero=True), ZeroDivisionError)

    def test_dot(self):
        a = Vec2(3, 4)
        self.assertEquals(a.dot(a), 25)
        self.assertEquals(a.dot(Vec2(4, -3)), 0)


if __name__ == '__main__':
    run(Vec2Test)

Пример #4
0
        for item in bag:
            expected.remove(item)
        self.assertEquals(expected, [])


    def test_simultaneous_iterations_by_type(self):
        bag, (o1, o2, o3) = self.create_populated_bag()

        expected1 = [o1, o2]
        for item1 in bag[int]:
            expected1.remove(item1)
            expected2 = [o1, o2]
            for item2 in bag[int]:
                expected2.remove(item2)
        self.assertEquals(expected1, [])
        self.assertEquals(expected2, [])


    def test_index_by_type(self):
        bag, (o1, o2, o3) = self.create_populated_bag()

        expected = [o1, o2]
        for item in bag[int]:
            expected.remove(item)
        self.assertEquals(expected, [])


if __name__ == '__main__':
    run(TypeBagTest)