def test_merge_nuke(): def nuke(*args: Any) -> bool: raise Drop() p1 = DataPack( description="hello", merge_policy=MergePolicy(extra={"pack.mcmeta": [nuke]}), ) p1.merge_policy.extend(MergePolicy(namespace={Function: [nuke]})) p1.merge_policy.extend_namespace_extra("foo.json", nuke) p1["demo:foo"] = Function() p1["demo"].extra["foo.json"] = JsonFile() p1["thing"].extra["foo.json"] = JsonFile() p2 = DataPack(description="world") p2["demo:foo"] = Function() p2["demo:bar"] = Function() p2["demo"].extra["foo.json"] = JsonFile() p1.merge(p2) assert p1.description == "" assert list(p1.functions) == ["demo:bar"] assert list(p1["demo"].extra) == [] assert p1["thing"].extra["foo.json"] == JsonFile()
def beet_default(ctx: Context): for lib in sorted(ctx.directory.glob("lib_*")): config = { "data_pack": { "load": [lib.name], }, "pipeline": ["demo.export_mcmeta"], } ctx.require(subproject(config)) with ctx.worker(bridge) as channel: # Request mcmeta files from the worker channel.send(None) final_mcmeta = JsonFile({ "pack": { "pack_format": 7, "description": "This is the root", }, "custom_data": 0, "libs": [], }) for mcmeta in channel: final_mcmeta.data["custom_data"] += mcmeta.data["custom_data"] final_mcmeta.data["libs"].append(mcmeta.data) ctx.data.mcmeta = final_mcmeta
def test_equality(): assert DataPack() == DataPack() assert DataPack("hello") == DataPack("hello") assert DataPack("hello") != DataPack("world") p1 = DataPack("foo", mcmeta=JsonFile({"pack": {"description": "bar"}})) p2 = DataPack("foo", mcmeta=JsonFile({"pack": {"description": "bar"}})) assert p1 == p2 p1 = DataPack("foo", mcmeta=JsonFile( {"pack": { "description": "bar", "pack_format": 6 }})) p2 = DataPack("foo", mcmeta=JsonFile( {"pack": { "description": "bar", "pack_format": 5 }})) assert p1 != p2
import pytest from PIL import Image, ImageDraw from beet import JsonFile, PngFile, ResourcePack, Texture def test_default(): assert ResourcePack() == ResourcePack() assert not ResourcePack() @pytest.mark.parametrize( # type: ignore "pack", [ ResourcePack("p1"), ResourcePack("p2", mcmeta=JsonFile({"pack": {"description": "world"}})), ResourcePack( "p3", mcmeta=JsonFile({"pack": {"description": "world", "pack_format": 42}}) ), ], ) def test_empty(snapshot: Any, pack: ResourcePack): assert snapshot("resource_pack") == pack assert not pack assert dict(pack) == {} def test_empty_with_image(): pack = ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue"))) assert pack assert pack == ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue")))