generated from EndstoneMC/python-example-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test for player scoreboard
- Loading branch information
1 parent
a9a7749
commit 7943b0e
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |