From d063327de378b9d4305e8562a886c32d094ce863 Mon Sep 17 00:00:00 2001 From: u8slvn Date: Tue, 20 Aug 2024 13:00:27 +0200 Subject: [PATCH] test: landscape module --- tests/conftest.py | 7 +++++++ tests/test_landscape.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/test_landscape.py diff --git a/tests/conftest.py b/tests/conftest.py index 5011940..19b6112 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,3 +14,10 @@ def pygame(): yield pg.quit() + + +@pytest.fixture +def pg_screen_mock(mocker): + """Mock the pygame screen surface.""" + + return mocker.Mock(spec=pg.Surface, instance=True) diff --git a/tests/test_landscape.py b/tests/test_landscape.py new file mode 100644 index 0000000..f34581f --- /dev/null +++ b/tests/test_landscape.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from doggo.landscape import Biome +from doggo.landscape import LandscapeLayer + + +def test_get_random_biome(): + biome = Biome.random() + + assert isinstance(biome, Biome) + assert biome in list(Biome) + + +def test_landscape_layer_draw_on_screen(pg_screen_mock): + image = f"{Biome.MOUNTAIN:02d}_bg.png" + landscape_layer = LandscapeLayer(image=image) + + landscape_layer.draw(pg_screen_mock) + + pg_screen_mock.blit.assert_called_once_with( + landscape_layer.image, landscape_layer.rect + )