Skip to content

Commit

Permalink
feat: add test for player scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Sep 4, 2024
1 parent a9a7749 commit 7943b0e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/endstone_test/tests/on_player_join/test_scoreboard.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7943b0e

Please sign in to comment.