コード例 #1
0
ファイル: test_structures.py プロジェクト: chomechome/pygvent
 def setUp(self):
     self.test_scene = Scene()
     self.test_layers = [Layer('TestLayer{}'.format(i),
                               [MockGameObject() for _ in range(i)])
                         for i in range(10)]
     self.test_layer = self.test_layers[-1]
コード例 #2
0
ファイル: test_structures.py プロジェクト: chomechome/pygvent
class SceneTest(TestCaseWithPatch):
    def setUp(self):
        self.test_scene = Scene()
        self.test_layers = [Layer('TestLayer{}'.format(i),
                                  [MockGameObject() for _ in range(i)])
                            for i in range(10)]
        self.test_layer = self.test_layers[-1]

    def test_add_layer(self):
        self.test_scene.add(self.test_layer)
        self.assertIn(self.test_layer, self.test_scene)

    def test_remove_layer(self):
        self.test_scene.add(self.test_layer)
        self.test_scene.remove(self.test_layer)
        self.assertNotIn(self.test_layer, self.test_scene)

    def test_remove_layer_by_name(self):
        self.test_scene.add(self.test_layer)
        self.test_scene.remove(self.test_layer.name)
        self.assertNotIn(self.test_layer, self.test_scene)

    def test_get_layer(self):
        self.test_scene.add(self.test_layer)

        name = self.test_layer.name
        self.assertIs(self.test_layer, self.test_scene[name])
        self.assertIs(self.test_layer, getattr(self.test_scene, name))

        self.assertRaises(AttributeError, getattr, self.test_scene,
                          'definitely not a layer in test scene')

    def test_extend(self):
        self.test_scene.extend(self.test_layers)

        self.assertEqual(len(self.test_layers), len(self.test_scene))
        for layer in self.test_layers:
            self.assertIn(layer, self.test_scene)
            self.assertIs(layer, self.test_scene[layer.name])
            self.assertIs(layer, getattr(self.test_scene, layer.name))

    def test_clear(self):
        test_layers_objects = [layer.objects for layer in self.test_layers]

        self.test_scene.extend(self.test_layers)
        self.test_scene.clear()

        self.assertEqual(0, len(self.test_scene))
        for layer, objects in zip(self.test_layers, test_layers_objects):
            self.assertNotIn(layer, self.test_scene)
            self.assertEqual(0, len(layer))
            for obj in objects:
                self.assertNotIn(obj, layer)
                self.assertNotIn(layer, obj.layers)

    def test_update(self):
        self.patch('pygvent.structures.Layer.update')

        self.test_scene.extend(self.test_layers)
        self.test_scene.update()

        self.assertEqual(len(self.test_layers), Layer.update.call_count)

    def test_draw(self):
        self.patch('pygvent.structures.Layer.draw')

        self.test_scene.extend(self.test_layers)

        test_screen = 'apple'
        self.test_scene.draw(test_screen)

        Layer.draw.assert_called_with(test_screen)
        self.assertEqual(len(self.test_layers), Layer.draw.call_count)