mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-11 02:05:24 -06:00
new sprite testing functions including regex based schema tests and sprite loading
This commit is contained in:
@@ -26,14 +26,56 @@ class TestGame:
|
|||||||
game = Game()
|
game = Game()
|
||||||
game.setup()
|
game.setup()
|
||||||
# test for 100 frames
|
# test for 100 frames
|
||||||
game.test(100)
|
game.test(50)
|
||||||
|
|
||||||
|
|
||||||
class TestSprites:
|
class TestSprites:
|
||||||
"""
|
"""
|
||||||
Tests the Sprite classes as well as the available sprites.
|
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:
|
class TestLevels:
|
||||||
|
|||||||
Reference in New Issue
Block a user