From 23de337f03991239da11ed272d364c6b568c8761 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 7 Oct 2024 22:59:12 +0100 Subject: [PATCH] feat: add test for server.online_mode --- src/endstone_test/tests/on_load/test_server.py | 13 +++++++++++++ .../tests/on_player_join/test_scoreboard.py | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/endstone_test/tests/on_load/test_server.py b/src/endstone_test/tests/on_load/test_server.py index 65f0ab4..4fbcc28 100644 --- a/src/endstone_test/tests/on_load/test_server.py +++ b/src/endstone_test/tests/on_load/test_server.py @@ -1,4 +1,5 @@ import time +from pathlib import Path import pytest from endstone import Server, Translatable, __minecraft_version__ @@ -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 diff --git a/src/endstone_test/tests/on_player_join/test_scoreboard.py b/src/endstone_test/tests/on_player_join/test_scoreboard.py index da98737..8b66476 100644 --- a/src/endstone_test/tests/on_player_join/test_scoreboard.py +++ b/src/endstone_test/tests/on_player_join/test_scoreboard.py @@ -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