new sprite testing functions including regex based schema tests and sprite loading

This commit is contained in:
Xevion
2020-04-20 23:33:36 -05:00
parent 8bac3a50d2
commit f53c977432

View File

@@ -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: