Skip to content

Commit

Permalink
feat: add test for server.online_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Oct 7, 2024
1 parent 21f641f commit 23de337
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/endstone_test/tests/on_load/test_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from pathlib import Path

import pytest
from endstone import Server, Translatable, __minecraft_version__
Expand Down Expand Up @@ -32,3 +33,15 @@ def test_max_players(server: Server) -> None:
# set max players
server.max_players = 100
assert server.max_players == 100


def test_online_mode(plugin: Plugin, server: Server) -> None:
properties_file = Path(plugin.data_folder, "..", "..", "server.properties")
with properties_file.open(mode='r') as file:
for line in file:
if line.startswith('online-mode='):
value = line.split('=', 1)[1].strip()
assert (value.lower() == 'true') == server.online_mode
return

assert False
9 changes: 7 additions & 2 deletions src/endstone_test/tests/on_player_join/test_scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ def scoreboard(server: 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")
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
server.dispatch_command(server.command_sender, "scoreboard objectives remove test_objective")
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

Expand Down

0 comments on commit 23de337

Please sign in to comment.