Skip to content

Commit

Permalink
test: add more tests for the inventory api
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Oct 29, 2024
1 parent e9d40c2 commit 918b82f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/endstone_test/tests/on_load/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def test_max_players(server: Server) -> None:


def test_online_mode(plugin: Plugin, server: Server) -> None:
properties_file = Path(plugin.data_folder, "..", "..", "server.properties").resolve()
properties_file = Path(
plugin.data_folder, "..", "..", "server.properties"
).resolve()
with properties_file.open(mode="r") as file:
for line in file:
if line.startswith("online-mode="):
Expand Down
36 changes: 36 additions & 0 deletions src/endstone_test/tests/on_player_join/test_inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from endstone import Player, Server
from endstone.inventory import ItemStack


@pytest.fixture
def server(player: Player) -> Server:
return player.server


def test_inventory_sizes(player: Player):
assert player.inventory.size == 36
assert player.inventory.max_stack_size == 254


def test_set_invalid_item(player: Player):
player.inventory.set_item(35, ItemStack("item_that_does_not_exist", 1))
assert player.inventory.get_item(35) is None


def test_set_empty_item(player: Player):
player.inventory.set_item(35, None)
assert player.inventory.get_item(35) is None


def test_set_item(player: Player):
player.inventory.set_item(35, ItemStack("minecraft:clock", 7))

item = player.inventory.get_item(35)
assert item.type == "minecraft:clock"
assert item.amount == 7

player.inventory.set_item(35, item)
item = player.inventory.get_item(35)
assert item.type == "minecraft:clock"
assert item.amount == 7
20 changes: 0 additions & 20 deletions src/endstone_test/tests/on_player_join/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ def test_player_in_online_players(player: Player, server: Server):
assert server.get_player(player.unique_id) is player


def test_player_inventory(player: Player):
assert player.inventory.size == 36
assert player.inventory.max_stack_size == 254

player.inventory.set_item(35, ItemStack("minecraft:clock", 1))
assert player.inventory.get_item(35).type == "minecraft:clock"


def test_player_permissions(player: Player, plugin: Plugin):
assert player.has_permission("minecraft.command.me") is True
player.add_attachment(plugin, "minecraft.command.me", False)
Expand Down Expand Up @@ -88,18 +80,6 @@ def test_player_game_mode(player: Player):
assert player.game_mode == current_game_mode


def test_player_scoreboard(player: Player, server: Server):
assert player.scoreboard is server.scoreboard

new_scoreboard = server.create_scoreboard()
player.scoreboard = new_scoreboard
assert player.scoreboard is new_scoreboard
assert player.scoreboard is not server.scoreboard

player.scoreboard = server.scoreboard
assert player.scoreboard is server.scoreboard


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
Expand Down
14 changes: 13 additions & 1 deletion src/endstone_test/tests/on_player_join/test_scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ def scoreboard(server: Server) -> Scoreboard:
return server.scoreboard


def test_set_scoreboard(player: Player, server: Server):
assert player.scoreboard is server.scoreboard

new_scoreboard = server.create_scoreboard()
player.scoreboard = new_scoreboard
assert player.scoreboard is new_scoreboard
assert player.scoreboard is not server.scoreboard

player.scoreboard = server.scoreboard
assert player.scoreboard is server.scoreboard


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 Down

0 comments on commit 918b82f

Please sign in to comment.