plugins/tools/test_planet_ore_release.py
unimatrixgit b262b5f90f
Some checks failed
Sigma Ore Palette Build / sigma-ore-palette (push) Successful in 5s
DuneRealms Resourcepack CI / resourcepack (push) Failing after 10s
DuneRealms Plugin CI / plugins (push) Successful in 2m28s
Keep Sigma mineral generation within its configured palette
2026-12-02 07:25:29 +01:00

88 lines
4.4 KiB
Python

import importlib.util
import json
from pathlib import Path
from shutil import copyfile
from tempfile import TemporaryDirectory
import unittest
from unittest.mock import patch
from zipfile import ZipFile
from planet_ore_release import GENERATOR, PLANETS, SAMPLER, sha, 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)
spec = importlib.util.spec_from_file_location('reset_sigma_ore_pack', Path(__file__).with_name('reset-sigma-ore-pack.py'))
sigma = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sigma)
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()))
def test_sigma_pack_adds_only_three_biomes_and_retains_sulfur_features(self):
source = Path(__file__).resolve().parents[1] / 'DuneTerrain/planet-datapacks/sigma_draconis_iv'
with TemporaryDirectory() as temp:
folder = Path(temp)
previous, candidate = folder / 'previous.zip', folder / 'candidate.zip'
with ZipFile(previous, 'w') as archive:
archive.writestr('existing.json', b'unchanged bytes')
for name, internal in sigma.PATHS.items():
copyfile(source / internal, folder / name)
with patch.object(sigma, 'PACK', sha(previous)):
sigma.build_pack(previous, folder, candidate)
with ZipFile(candidate) as archive:
self.assertEqual(set(archive.namelist()), {'existing.json', *sigma.PATHS.values()})
self.assertEqual(archive.read('existing.json'), b'unchanged bytes')
sulfur = json.loads(archive.read(sigma.PATHS['sulfur_caves.json']))
features = {feature for layer in sulfur['features'] for feature in layer}
self.assertTrue({'minecraft:rooted_sulfur_spring', 'minecraft:sulfur_spike', 'minecraft:sulfur_pool'} <= features)
if __name__ == '__main__':
unittest.main()