/
test_alien_invasion.py
36 lines (26 loc) · 997 Bytes
/
test_alien_invasion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Test the Alien Invasion game."""
from pathlib import Path
import os
import importlib
import sys
import pytest
import utils
@pytest.fixture(scope="module", autouse=True)
def check_pygame_version(request, python_cmd):
"""Check if the correct version of Pygame is installed."""
utils.check_library_version(request, python_cmd, "pygame")
def test_ai_game():
"""Test basic functionality of the game."""
# Add source path to sys.path, so we can import AlienInvasion.
ai_path = Path(__file__).parents[1] / 'chapter_14' / 'scoring'
sys.path.insert(0, str(ai_path))
from alien_invasion import AlienInvasion
from ai_tester import AITester
# Create a game instance, and an AITester instance, and run game.
os.chdir(ai_path)
ai_game = AlienInvasion()
ai_tester = AITester(ai_game)
ai_tester.run_game()
# Make assertions to ensure first level was played through.
assert ai_game.stats.score == 3375
assert ai_game.stats.level == 2