From 7943b0e7bd6ffceb217b45bbbbb6aa5102fde9c5 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 4 Sep 2024 21:44:22 +0100 Subject: [PATCH] feat: add test for player scoreboard --- .../tests/on_player_join/test_scoreboard.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/endstone_test/tests/on_player_join/test_scoreboard.py diff --git a/src/endstone_test/tests/on_player_join/test_scoreboard.py b/src/endstone_test/tests/on_player_join/test_scoreboard.py new file mode 100644 index 0000000..da98737 --- /dev/null +++ b/src/endstone_test/tests/on_player_join/test_scoreboard.py @@ -0,0 +1,39 @@ +import pytest +from endstone import Player, Server +from endstone.scoreboard import Scoreboard + + +@pytest.fixture +def server(player: Player) -> Server: + return player.server + + +@pytest.fixture +def scoreboard(server: Server) -> Scoreboard: + return server.scoreboard + + +@pytest.fixture(scope="function", autouse=True) +def before_each_after_each(server: Server, scoreboard: Scoreboard): + # Before each test run + server.dispatch_command(server.command_sender, "scoreboard objectives remove test_objective") + objective = scoreboard.get_objective("test_objective") + assert objective is None + + yield + + # After each test run + server.dispatch_command(server.command_sender, "scoreboard objectives remove test_objective") + objective = scoreboard.get_objective("test_objective") + assert objective is None + + +def test_scoreboard_value(player: Player, server: Server, scoreboard: Scoreboard) -> None: + server.dispatch_command(server.command_sender, "scoreboard objectives add test_objective dummy") + objective = scoreboard.get_objective("test_objective") + assert objective is not None + + server.dispatch_command(server.command_sender, f"scoreboard players set {player.name} test_objective 3") + score = objective.get_score(player) + assert score.is_score_set + assert score.value == 3