Skip to content

Commit

Permalink
test: add tests for actor tags
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Oct 22, 2024
1 parent 7dceab7 commit 2747647
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
20 changes: 19 additions & 1 deletion src/endstone_test/tests/on_player_join/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,28 @@ def test_player_scoreboard(player: Player, server: Server):
assert player.scoreboard is server.scoreboard


def test_player_tags(player: Player, server: Server):
def test_player_get_tags(player: Player, server: Server):
server.dispatch_command(server.command_sender, f'tag "{player.name}" add test_tag')
assert "test_tag" in player.scoreboard_tags
server.dispatch_command(
server.command_sender, f'tag "{player.name}" remove test_tag'
)
assert "test_tag" not in player.scoreboard_tags


def test_player_add_tag(player: Player, server: Server):
assert player.add_scoreboard_tag("test_tag")
assert "test_tag" in player.scoreboard_tags

assert not player.add_scoreboard_tag("test_tag")
server.dispatch_command(server.command_sender, f'tag "{player.name}" remove test_tag')


def test_player_remove_tag(player: Player, server: Server):
server.dispatch_command(server.command_sender, f'tag "{player.name}" add test_tag')
assert "test_tag" in player.scoreboard_tags

assert player.remove_scoreboard_tag("test_tag")
assert "test_tag" not in player.scoreboard_tags

assert not player.remove_scoreboard_tag("test_tag")
30 changes: 5 additions & 25 deletions src/endstone_test/tests/on_player_join/test_scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,8 @@ 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
objective = scoreboard.get_objective("test_objective")
if objective is not None:
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
objective = scoreboard.get_objective("test_objective")
if objective is not None:
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
player: Player, server: Server, scoreboard: Scoreboard
) -> None:
server.dispatch_command(
server.command_sender, "scoreboard objectives add test_objective dummy"
Expand All @@ -52,3 +28,7 @@ def test_scoreboard_value(
score = objective.get_score(player)
assert score.is_score_set
assert score.value == 3

server.dispatch_command(
server.command_sender, "scoreboard objectives remove test_objective"
)

0 comments on commit 2747647

Please sign in to comment.