Skip to content

Commit

Permalink
update tests for recent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed May 10, 2024
1 parent 8294883 commit 620c9c5
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions asdf/_tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from asdf.testing.helpers import yaml_to_asdf


def _roundtrip(obj):
def _roundtrip(obj, init_kwargs=None):
"""
Parameters
----------
Expand All @@ -31,8 +31,12 @@ def _roundtrip(obj):
read_tree : object
object read back from ASDF file
"""

init_kwargs = init_kwargs or {}
buff = io.BytesIO()
asdf.AsdfFile({"obj": obj}).write_to(buff)
af = asdf.AsdfFile(**init_kwargs)
af["obj"] = obj
af.write_to(buff)
buff.seek(0)

open_kwargs = {
Expand Down Expand Up @@ -104,11 +108,12 @@ class Foo:
ff.write_to(buff)


def run_tuple_test(input_tree):
content, tree = _roundtrip(input_tree)
def run_tuple_test(input_tree, **kwargs):
content, tree = _roundtrip(input_tree, **kwargs)

assert b"tuple" not in content
assert isinstance(tree["val"], list)
return content, tree


def test_python_tuple():
Expand All @@ -120,8 +125,7 @@ def test_python_tuple():

input_tree = {"val": (1, 2, 3)}

with pytest.warns(AsdfDeprecationWarning, match="ignore_implicit_conversion"):
run_tuple_test(input_tree)
run_tuple_test(input_tree)


@contextlib.contextmanager
Expand Down Expand Up @@ -149,7 +153,7 @@ def test_named_tuple_collections():
input_tree = {"val": nt(1, 2, 3)}

with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
run_tuple_test(input_tree)
run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})


def test_named_tuple_typing():
Expand All @@ -162,20 +166,19 @@ class NT(NamedTuple):
two: int
three: int

tree = {"val": NT(1, 2, 3)}
input_tree = {"val": NT(1, 2, 3)}

with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
run_tuple_test(tree)
run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})


def test_named_tuple_collections_recursive():
nt = namedtuple("TestNamedTuple3", ("one", "two", "three"))

input_tree = {"val": nt(1, 2, np.ones(3))}

#init_options = {"ignore_implicit_conversion": True}
with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
_, tree = _roundtrip(input_tree)
_, tree = run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})
assert (tree["val"][2] == np.ones(3)).all()


Expand All @@ -187,9 +190,8 @@ class NT(NamedTuple):

input_tree = {"val": NT(1, 2, np.ones(3))}

init_options = {"ignore_implicit_conversion": True}
with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
_, tree = _roundtrip(input_tree)
_, tree = run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})
assert (tree["val"][2] == np.ones(3)).all()


Expand Down

0 comments on commit 620c9c5

Please sign in to comment.