Skip to content

Commit

Permalink
feat: expose data pack and resource pack snapshot formats
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Apr 6, 2022
1 parent ce38d5f commit a451ce9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
28 changes: 27 additions & 1 deletion beet/pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
from pathlib import Path
from pprint import pformat

from _pytest.assertion.util import assertrepr_compare

from beet import Namespace, NamespaceContainer, Pack
from beet import DataPack, Namespace, NamespaceContainer, Pack, ResourcePack
from beet.library.test_utils import ignore_name

try:
from pytest_insta import Fmt
except ImportError:
pass
else:

class FmtResourcePack(Fmt[ResourcePack]):
extension = ".resource_pack"

def load(self, path: Path) -> ResourcePack:
return ignore_name(ResourcePack(path=path))

def dump(self, path: Path, value: ResourcePack):
value.save(path=path, overwrite=True)

class FmtDataPack(Fmt[DataPack]):
extension = ".data_pack"

def load(self, path: Path) -> DataPack:
return ignore_name(DataPack(path=path))

def dump(self, path: Path, value: DataPack):
value.save(path=path, overwrite=True)


def pytest_assertrepr_compare(config, op, left, right):
Expand Down
23 changes: 1 addition & 22 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,8 @@

from pytest_insta import Fmt

from beet import DataPack, ProjectConfig, ResourcePack
from beet import ProjectConfig
from beet.core.utils import dump_json
from beet.library.test_utils import ignore_name


class FmtResourcePack(Fmt[ResourcePack]):
extension = ".resource_pack"

def load(self, path: Path) -> ResourcePack:
return ignore_name(ResourcePack(path=path))

def dump(self, path: Path, value: ResourcePack):
value.save(path=path, overwrite=True)


class FmtDataPack(Fmt[DataPack]):
extension = ".data_pack"

def load(self, path: Path) -> DataPack:
return ignore_name(DataPack(path=path))

def dump(self, path: Path, value: DataPack):
value.save(path=path, overwrite=True)


class FmtConfig(Fmt[ProjectConfig]):
Expand Down

0 comments on commit a451ce9

Please sign in to comment.