plugins/tools/test_planet_ore_release.py
unimatrixgit b54c277568
Some checks failed
Planet Ore Profiles Build / planet-ore-profiles (push) Successful in 42s
DuneRealms Resourcepack CI / resourcepack (push) Failing after 11s
DuneRealms Plugin CI / plugins (push) Successful in 2m59s
Use vanilla height profiles for existing planet ores
2026-12-02 07:08:09 +01:00

64 lines
2.9 KiB
Python

import importlib.util
from pathlib import Path
from tempfile import TemporaryDirectory
import unittest
from zipfile import ZipFile
from planet_ore_release import GENERATOR, PLANETS, SAMPLER, verify_terrain
spec = importlib.util.spec_from_file_location('reset_planet_ores', Path(__file__).with_name('reset-planet-ores.py'))
reset = importlib.util.module_from_spec(spec)
spec.loader.exec_module(reset)
class PlanetOreReleaseTest(unittest.TestCase):
def test_world_scope_preserves_other_dimensions_and_all_player_files(self):
with TemporaryDirectory() as temp:
world = Path(temp).resolve()
overworld = world / reset.DIMENSION
names = [
overworld / 'region/r.0.0.mca', overworld / 'entities/r.0.0.mca',
overworld / 'data/paper/metadata.dat', world / 'players/data/test.dat',
world / 'dimensions/minecraft/the_nether/region/r.0.0.mca',
]
for name in names:
name.parent.mkdir(parents=True, exist_ok=True)
name.write_text('retained fixture')
self.assertEqual(set(reset.chunk_files(overworld)), set(names[:2]))
self.assertEqual(set(reset.world_snapshot(world, set())),
{p.relative_to(world).as_posix() for p in names[2:]})
unexpected = overworld / 'region/unreviewed.txt'
unexpected.touch()
with self.assertRaises(ValueError):
reset.chunk_files(overworld)
def test_candidate_cannot_change_other_terrain_entries(self):
with TemporaryDirectory() as temp:
folder = Path(temp)
with ZipFile(folder / 'baseline.jar', 'w') as archive:
archive.writestr(GENERATOR, b'previous')
archive.writestr('config.yml', b'unchanged')
with ZipFile(folder / 'ore-heights.zip', 'w') as archive:
for name in SAMPLER:
archive.writestr(name, b'canonical')
for title, config in [('valid', b'unchanged'), ('modified', b'changed')]:
path = folder / f'{title}.jar'
with ZipFile(path, 'w') as archive:
archive.writestr(GENERATOR, b'reviewed transformation')
archive.writestr('config.yml', config)
for name in SAMPLER:
archive.writestr(name, b'canonical')
if title == 'valid':
verify_terrain(folder / 'baseline.jar', path, folder)
else:
with self.assertRaises(ValueError):
verify_terrain(folder / 'baseline.jar', path, folder)
def test_five_world_scope_excludes_lobby(self):
self.assertEqual(set(PLANETS), {'arrakis', 'caladan', 'giedi_prime', 'kaitain', 'sigma_draconis_iv'})
self.assertTrue(all(len(pin) == 64 for pin in PLANETS.values()))
if __name__ == '__main__':
unittest.main()