Skip to content

Commit

Permalink
Merge pull request #14 from steven-murray/yaml-error
Browse files Browse the repository at this point in the history
fix: the yaml loader
  • Loading branch information
steven-murray committed Jul 12, 2023
2 parents 36cad70 + 0d6d74f commit c393346
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/hickleable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ def _load_path(h_node, base_type, py_obj_type):

if yaml is not None:
# Register a YAML loader for hickle-dumped files.
def _hickle_yaml_loader(path):
return hickle.load(path)
def _hickle_yaml_loader(loader: yaml.SafeLoader, node):
return hickle.load(node.value)

yaml.add_constructor("!hickle", _hickle_yaml_loader, Loader=yaml.FullLoader)
yaml.add_constructor("!hickle", _hickle_yaml_loader, Loader=yaml.Loader)
25 changes: 25 additions & 0 deletions tests/test_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import hickle
import yaml

from hickleable import hickleable


@hickleable()
class A:
def __init__(self, a):
self.a = a

def __eq__(self, other):
return self.a == other.a


def test_load_yaml(tmpdir):
fl = tmpdir / "test_load_yaml.h5"
a = A("more stuff")

hickle.dump(a, str(fl))

txt = f"""!hickle {fl}"""

b = yaml.load(txt, Loader=yaml.FullLoader)
assert a == b

0 comments on commit c393346

Please sign in to comment.