From f53c97743279095d1785914fd08b624c7f2865ba Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 20 Apr 2020 23:33:36 -0500 Subject: [PATCH] new sprite testing functions including regex based schema tests and sprite loading --- triple-dungeon/tests.py | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/triple-dungeon/tests.py b/triple-dungeon/tests.py index 657f373..2640e64 100644 --- a/triple-dungeon/tests.py +++ b/triple-dungeon/tests.py @@ -26,14 +26,56 @@ class TestGame: game = Game() game.setup() # test for 100 frames - game.test(100) + game.test(50) class TestSprites: """ Tests the Sprite classes as well as the available sprites. """ - pass + + @pytest.fixture + def sprites(self) -> list: + """ + Returns a list of absolute paths to sprites found in the images folder. + + :return: List of absolute paths to sprites + """ + + import os + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + IMAGE_DIR = os.path.join(BASE_DIR, 'resources', 'images') + + return [[ + os.path.join(IMAGE_DIR, file) for file in os.listdir(os.path.join(IMAGE_DIR, folder)) + ] for folder in os.listdir(IMAGE_DIR)] + + @pytest.fixture + def patterns(self) -> list: + import re + return list(map(re.compile, + [r'\w+_(?:\w+_)?\d+\.(?:jp(?:eg|e|g)|png)' + r'\w+\d+\.(?:jp(?:eg|e|g)|png)', + r'\w+_tile\.(?:jp(?:eg|e|g)|png)'] + )) + + def test_sprite_schema(self, sprites, patterns) -> None: + """ + Tests that all sprites follow the naming conventions. + """ + import os + + for sprite in map(os.path.basename, sprites): + assert any(pattern.match(pattern, sprite) for pattern in patterns) + + def test_sprite_loads(self, sprites) -> None: + """ + Tests that all sprites can be loaded by the arcade framework. + """ + import arcade + + for sprite in sprites: + _sprite = arcade.Sprite(sprite) class TestLevels: