plugins/tools/test_giedi_nether_pearl.py
unimatrixgit 426c6729c3
All checks were successful
Giedi Nether Ender Pearl Operations Build / giedi-nether-pearl (push) Successful in 5s
DuneRealms Plugin CI / plugins (push) Successful in 2m59s
Pin the actual installed Towny filename
2026-12-02 11:59:30 +01:00

63 lines
3.1 KiB
Python

import importlib.util
from pathlib import Path
from tempfile import TemporaryDirectory
import unittest
from unittest.mock import patch
spec = importlib.util.spec_from_file_location('pearl', Path(__file__).with_name('allow-giedi-nether-pearl.py'))
pearl = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pearl)
BEFORE = 'usingTowny=true\nunclaimedZoneItemUse=false\nunclaimedZoneIgnoreIds=TORCH,CHORUS_FRUIT\nclaimable=false\n'
class GiediNetherPearlTests(unittest.TestCase):
def test_native_command_targets_the_nether_and_replays_the_entire_list(self):
self.assertEqual(pearl.command(pearl.fields(BEFORE)),
'townyworld giedi_prime_nether set wildignore TORCH CHORUS_FRUIT ENDER_PEARL')
with self.assertRaises(ValueError):
pearl.command(pearl.fields(BEFORE.replace('TORCH,', 'TORCH;op,')))
def test_towny_may_sort_materials_but_no_other_setting_may_change(self):
before = pearl.fields(BEFORE)
after = pearl.fields(BEFORE.replace('TORCH,CHORUS_FRUIT', 'CHORUS_FRUIT,ENDER_PEARL,TORCH'))
pearl.verify(before, after)
for field, value in [(pearl.IGNORE, 'ENDER_PEARL,TORCH'), ('unclaimedZoneItemUse', 'true')]:
with self.subTest(field=field), self.assertRaises(ValueError):
pearl.verify(before, {**after, field: value})
def test_plan_and_apply_use_only_the_reviewed_world_file(self):
with TemporaryDirectory() as temp:
root = Path(temp).resolve()
towny = root / 'plugins/Towny-0.103.2.0.jar'
config = root / 'plugins/Towny/settings/config.yml'
world = root / 'plugins/Towny/data/worlds/giedi_prime_nether.txt'
sibling = world.with_name('giedi_prime.txt')
for path, content in [(towny, 'jar'), (config, 'config'), (world, BEFORE), (sibling, 'untouched')]:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content)
native_calls = []
def console(fifo, line):
native_calls.append((fifo, line))
world.write_text(BEFORE.replace('TORCH,CHORUS_FRUIT', 'TORCH,CHORUS_FRUIT,ENDER_PEARL'))
with patch.multiple(pearl, ROOT=root, WORLD_SHA=pearl.sha(world), CONFIG_SHA=pearl.sha(config),
TOWNY_SHA=pearl.sha(towny), send=console), patch.object(
pearl, 'service', side_effect=lambda *args: 'active' if args[0] == 'is-active' else str(root)), \
patch.object(pearl.time, 'sleep'):
self.assertEqual(pearl.run(False)['status'], 'planned')
self.assertEqual(native_calls, [])
self.assertEqual(pearl.run(True)['status'], 'persisted')
self.assertEqual(len(native_calls), 1)
self.assertEqual(native_calls[0][0], root / 'console.fifo')
self.assertEqual(sibling.read_text(), 'untouched')
with self.assertRaises(ValueError):
pearl.run(True)
self.assertEqual(len(native_calls), 1)
if __name__ == '__main__':
unittest.main()